How To Install LAMP on Manjaro 20

Install LAMP on Manjaro 20

In this tutorial, we will show you how to install LAMP on Manjaro 20. For those of you who didn’t know, LAMP stands for Linux, Apache, MySQL/MariaDB, and PHP or Perl or Python. All components are free and open-source software, and the combination is suitable for building dynamic web pages. The LAMP stack is one of the most popular server configurations in the world.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step by step installation of LAMP Stack on a Manjaro 20 (Nibia).

Install LAMP on Manjaro 20 Nibia

Step 1. Before running the tutorial below, make sure that our system is up to date:

sudo pacman -Syu

Step 2. Installing Apache.

Let’s install the Apache webserver using the following command:

sudo pacman -S apache

Once the installation has completed, open the Apache configuration file that exists on /etc/httpd/conf/httpd.conf, search and comment on the following line:
# LoadModule unique_id_module modules/mod_unique_id.so

We can now enable and start the apache server by using the following command:

sudo systemctl enable httpd
sudo systemctl restart httpd

Step 3. Install MySQL.

Run the following command to install MySQL Server on Manjaro:

sudo pacman -S mysql

Once completed, begin by initializing the MySQL data directory using the following command:

sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Next, enable and start it by using the following commands:

sudo systemctl enable mysqld
sudo systemctl restart mysqld

By default, MySQL is not hardened. You can secure MySQL using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MySQL:

$ sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
 ... Success!

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Step 4. Installing PHP.

To install PHP and PHP Apache module in Manjaro, simply use pacman the command:

sudo pacman -S php php-apache

After installation, we need to configure out PHP. Edit file: /etc/httpd/conf/httpd.conf:

sudo nano /etc/httpd/conf/httpd.conf

Find the following line and comment on it:

#LoadModule mpm_event_module modules/mod_mpm_event.so

Also, uncomment or add the line:

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

Then, add the following lines at the bottom of the configuration file:

LoadModule php7_module modules/libphp7.so
AddHandler php7-script php
Include conf/extra/php7_module.conf

Now save the file and exit. Restart the apache server to make sure all the configurations are loaded properly:

sudo systemctl restart httpd

To test the PHP installation, create a file at /srv/http/phpinfo.php and write the following PHP code:

<?php
phpinfo();
?>

Now open this file in the browser by visiting the localhost/phptest.php and check that the Apache server with the latest PHP version installed on your Manjaro Linux.

Congratulations! You have successfully installed the LAMP server. Thanks for using this tutorial for installing LAMP (Apache, MariaDB, and PHP) in Manjaro 20 systems. For additional help or useful information, we recommend you to check the official Apache, MariaDB, and PHP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!