How to Install LAMP on Arch Linux

LAMP (Linux, Apache, MySQL, PHP) Stack

Rumaisa Niazi
4 min readOct 8, 2021

A LAMP stack is a group of open-source software used to prepare servers for hosting web content. LAMP stands for Linux (Operating System), Apache (HTTP Server), MySQL (Database Management System), and PHP (Programming Language). The Pacman installer is used to download the latest required packages for each program with one command.

The web application has to include an OS, web server, database, and programming language to work smoothly. The article provides a step-by-step guide on how to install the LAMP stack on Arch Linux.

Step 1: Apache Installation

Apache is an open-source software running over 55% of the World’s web servers. Before getting started with the installation process, update the Arch package database for updated software, as follows:

#sudo pacman -Syu

After system update, install Apache as follows:

#sudo pacman -Syu apache

Now enable the Apache service using:

#sudo systemctl enable — now httpdCreated symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

The above command starts the web server on machine boot where — now is a switch to start the service right away.

After installation, uncomment the unique_id_module by removing # in the main configuration file httpd.conf.

#sudo vim /etc/httpd/conf/httpd.conf

Save and close the file. Now restart the Apache service as follows:

#sudo systemctl restart httpd

To check whether the apache server is running, open the browser and type localhost. The browser will display the following page:

Step 2: PHP Installation

The second step is installing PHP which is an open-source programming language. It helps in creating dynamic web pages by working with Apache. As HTML does not allow dynamic processes, using PHP code in the parts of these pages helps in providing this functionality.

There are several packages in PHP that we can install by using the command:

#sudo pacman -S php php-cgi php-gd php-pgsql php-apache

When prompted “Proceed with installation?”, press “Y” and hit enter.

After installation has been completed, there is another change to be made in the configuration file which can be done by opening the configuration file using:

#sudo vim /etc/httpd/conf/httpd.conf

Now comment the mpm_event_module with # and uncomment mpm_prefork_module by removing #:

Once done, scroll to the end of the main configuration file and include the following module:

LoadModule php7_module modules/libphp7.soAddHandler php7-script phpInclude conf/extra/php7_module.conf

Add following line for php8:

LoadModule php_module modules/libphp.soAddHandler php-script phpInclude conf/extra/php_module.conf

Now uncomment gd and mysqli extensions in the php.ini file by removing “;”.

#sudo vim /etc/php7/php.ini

Test if PHP is working correctly, by creating a file on theserver:

#sudo vim /srv/http/info.php<?php phpinfo();

The above code will display a page containing PHP and other LAMP settings related information. Save the file and exit.

Now restart the server:

#sudo systemctl restart httpd

Type localhost/info.php in the web browser to verify the successful PHP setup.

Step 3: MySQL

MySQL is a database management system used for data access and management. Install MySQL as follows:

#sudo pacman -S mysql

Since MariaDB is the default installation of MySQL in Arch Linux, it will ask for MariaDB or Percona server installation, just hit enter, type y, and enter again to carry on with the default installation. Now initialize the MariaDB database before starting the MySQL service.

#sudo mysql_install_db — user=mysql — basedir=/usr — datadir=/var/lib/mysql#sudo systemctl enable mysqld#sudo systemctl start mysqld

Secure MySQL/MariaDB installation requires a set-up that includes parameters like username, password, removing anonymous users, and preventing root users from remote login, etc. For the time being, run the following script to secure the root user account by setting up its password, as follows:

#sudo mysql_secure_installation

Press the “Enter” button when MySQL asks about the root password. It will prompt the user to “Set root password?”. Type the ‘Y’ key and press enter to set the password. Remember root password is not to be confused with server password as they are both different things.

Once done, enter ‘Y’ to all the options to complete the MySQL installation. MySQL will automatically reload and load the changes.

Closing Thoughts

The article demonstrates the step-by-step process of creating a LAMP server with some troubleshooting tips to ease the process. You can create your HTML and PHP files in any of the web-enabled directories. It provides the user with a great base to develop a website and focuses on the development basics.

--

--