How to Install LAMP stack on Arch Linux


LAMP is the most common configuration used in web server and it stands for Linux, Apache, MySQL, and PHP. This tutorial describes how to install LAMP stack on to your Arch Linux system. Pacman, a package manager designed specifically for Arch Linux will be used to install and update all required software packages.

Installing Apache

Apache is a free software that is distributed by Apache Software Foundation and is supposed to be the most popular open source software that runs over 50% of web servers in the world.

Before getting to installation of any LAMP software, just make sure of these two things:

  • User should have root privileges
  • Package manager should be updated

sudo pacman -Syu

After updating the package manager, you can run the command to install Apache.

sudo pacman -S apache

Once the installation of Apache is completed, there are some changes to be made to the apache configuration file.

You can open the configuration file to edit by giving:

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

Now, search and comment the unique_id_module as given below:

#LoadModule unique_id_module modules/

Then, restart Apache.

sudo systemctl restart httpd

Sometimes, while restarting apache, you may get an alert as shown below:

httpd: apr_sockaddr_info_get() failed for droplet1
httpd: Could not reliably determine the server's fully qualified domain name, using for ServerName

You can neglect this alert as it doesn’t cause any problem with your Apache launch. But if you wish to eliminate this, you can do that by adding the hostname to configuration.

Open the hosts file and add hostname to end of line starting with “”

sudo nano /etc/hosts       localhost.localdomain   localhost droplet1


This will eliminate the alert display with subsequent restarts.

Now that Apache is installed on your server, you can quickly try out few things. Get your server’s IP address by running the following command.

curl -s

Now, direct your browser to your server IP address to get the display of auto-index directory. Add a sample index.html file to the Arch’s document root directory located in srv/http.

sudo nano /srv/http/index.html

<h2>Hello, Welcome to Arch</h2>

You can see the placeholder page by directing your browser to your server’s IP address. If the page is fine, we can continue with our MySQL installation.

Installing MySQL

MariaDB is the default implementation for MySQL, which is almost a drop in replacement. It means, installation of MySQL will automatically drop MariaDB as a replacement in Arch repositories.

Let’s start with MySQL installation process.

Open your terminal and enter the following command.

sudo pacman -S mysql

In case if the system displays any messages, press enter. Once mysql is installed, you can proceed with the command for running it.

sudo systemctl start mysqld

Next step is to run the secure install script to clean up.

sudo mysql_secure_installation

While the secure install scrip is running, the system will ask for your MySQL root password. In that case, just hit enter as MySQL root password has not been set.

When system prompts for setting the root password, type ‘Y’ and enter your new MySQL root password. Below you can see a snapshot of the output screen, while the script is running.

Enter current password for root (enter for none):
OK, successfully used password, moving on...
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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, MySQL 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...

Now you will have MariaDB set up as your database. Make sure you enable and restart MySQL as given below:

sudo systemctl enable mysqld && sudo systemctl restart mysqld

Installing PHP

Here, in this tutorial, we are considering only the basics needed for installation of PHP. If you need other modules to be installed, you may have to update the php.ini file accordingly.

To begin with, open up the terminal and enter the following command.

sudo pacman -S php php-apache

Now, open the apache configuration file and update it to let Apache know about PHP.

sudo  nano /etc/httpd/conf/httpd.conf
# Use for PHP 5.x:
LoadModule php5_module       modules/
AddHandler php5-script php
Include conf/extra/php5_module.conf

Now that the LAMP stack is completely installed on your system, you may have to verify it by creating a simple php info page.

For that, you need to create a new blank file and paste the following code.

sudo nano /srv/http/phpinfo.php


After saving the file, go ahead and restart apache in order to bring in all your changes.

sudo systemctl restart httpd

Visit your php info page by going to your web address.


Now you are just one step behind finishing up your LAMP installation.

Open the configuration file of Arch’s innitscripts and make necessary changes to include apache server and MySQL daemons in the list of startup programs to be run during the server startup.

sudo systemctl enable mysqld httpd

Now you are officially done with the installation of LAMP stack on  Arch Linux.

support2 has written 111 articles

Leave a Reply