How to Install LAMP Stack with PhpMyAdmin in Arch Linux

Technically, the LAMP stack consists of Linux, Apache, MySQL, and PHP modules. A LAMP stack environment is ideal for web software developers that want to experience how their web application(s) is likely to behave on a server-hosted/production environment.

It is the perfect testing/debugging platform for your web app until you are confident enough to decouple it and host it on a dedicated server.

[ You might also like: How to Sync Two Web Servers in Linux Automatically ]

In this article, you will learn how to install and configure the LAMP environment along with the PhpMyAdmin database management tool in Arch Linux.

Afterward, you should be able to comfortably develop and test your first web application before making it production-ready and taking it online.

Step 1: Update Arch Linux System

An up-to-date Linux system is a performant system and will not break down easily.

$ sudo pacman -Syu
Update Arch Linux
Update Arch Linux

Step 2: Install Apache in Arch Linux

The following command installs the latest version of the Apache webserver.

$ sudo pacman -Syu apache
Install Apache in Arch Linux
Install Apache in Arch Linux

Once Apache is installed, next, you need to start, enable and check the status of the Apache server daemon.

$ sudo systemctl start httpd 
$ sudo systemctl enable httpd
$ sudo systemctl status httpd
Check Apache Status in Arch Linux
Check Apache Status in Arch Linux

Step 3: Install PHP in Arch Linux

The following command installs PHP and its Apache module.

$ sudo pacman -S php php-apache
Install PHP in Arch Linux
Install PHP in Arch Linux

Step 4: Install MySQL in Arch Linux

MariaDB is a community-supported MySQL fork and therefore a good idea to go with it.

$ sudo pacman -S mysql

Choose the option 1) to install MariaDB.

Install MySQL in Arch Linux
Install MySQL in Arch Linux

We also need to start, enable and check the MySQL daemon to make sure it is running.

$ sudo systemctl start mysqld 
$ sudo systemctl enable mysqld
$ sudo systemctl status mysqld
Check MySQL Status in Arch Linux
Check MySQL Status in Arch Linux

If you run into unnecessary errors while trying to execute the above command, for example.

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

Switch to the root user of the Arch Linux system:

$ su

Navigate to the directory path /var/lib/mysql and delete everything inside it.

# cd /var/lib/mysql
# rm -r *

Run the command:

# mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Fix Can't open and lock privilege tables Error
Fix Can’t open and lock privilege tables Error

Switch back to your sudoer user and finally, rerun the following command to make sure the mysqld daemon is active:

$ sudo systemctl start mysqld 
$ sudo systemctl enable mysqld
$ sudo systemctl status mysqld

Step 5: Secure MySQL in Arch Linux

Next, you need to secure your MySQL installation by running the following security script.

$ sudo mysql_secure_installation

You will be asked some questions which you can answer as per your preference.

Secure MariaDB Installation
Secure MariaDB Installation

Finally, connect to your MySQL database as the root user.

$ mysql -u root -p
Connect MySQL Database
Connect MySQL Database

Step 6: Configure Apache in Arch Linux

Open the apache configuration file.

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

Search for the lines starting with LoadModule mpm_prefork_ and uncomment it.

Configure Apache in Arch Linux
Configure Apache in Arch Linux

Also, at the bottom of this file, add the following lines:

LoadModule php_module modules/libphp.so
AddHandler php-script php
Include conf/extra/php_module.conf
Enable Modules in Apache
Enable Modules in Apache

Restart Apache webserver to apply configuration changes.

$ sudo systemctl restart httpd 

Step 7: Testing Apache in Arch Linux

To test Apache, we will create a custom home page (index.html) file.

$ sudo nano /srv/http/index.html

Add the following HTML code.

<!DOCTYPE html>
<html>

<head>
  <title>Welcome</title>
</head>

<body>

  <h1>Welcome to LinuxShellTips</h1>
   <p>Linux Command Line Tips, Tricks, Hacks, Tutorials, and Ideas in Blog</p>

</body>
</html>

Save the file and go to the following URL on your browser to access the page.

http://localhost
Or
http://IP-Address
Check Apache in Arch Linux
Check Apache in Arch Linux

To test if Apache serves PHP scripts, create and edit the following file:

$ sudo nano /srv/http/test.php

Add the following PHP code.

<?php
phpinfo()
?>

Save the file and go to the following URL on your browser to access the page.

http://localhost/test.php
Or
http://IP-Address/test.php
Check PHP in Arch Linux
Check PHP in Arch Linux

Step 8: Install PhpMyAdmin in Arch Linux

PhpMyAdmin is an open-source web-based database management tool for MySQL/MariaDB.

$ sudo pacman -S phpmyadmin
Install PhpMyAdmin in Arch Linux
Install PhpMyAdmin in Arch Linux

Open the file /etc/php/php.ini and uncomment the lines extension=mysqli, extension=pdo_mysql and extension=iconv by removing the semicolon (;) preceding them.

$ sudo nano /etc/php/php.ini
Enable PHP Modules in Apache
Enable PHP Modules in Apache

Now set up Apache to work with phpmyadmin by creating phpmyadmin’s main configuration file.

$ sudo nano /etc/httpd/conf/extra/phpmyadmin.conf

Populate this file with content similar to the following screen capture:

Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin"
<Directory "/usr/share/webapps/phpMyAdmin">
	DirectoryIndex  index.php
    AllowOverride All
    Options FollowSymlinks
    Require all granted
</Directory>

Next, include the path to this configuration file on Apache’s main configuration file.

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

Add the following line at the bottom.

Include conf/extra/phpmyadmin.conf

Finally, restart the Apache web service.

$ sudo systemctl restart httpd

Now access the PhpMyAdmin from the browser.

http://localhost/phpmyadmin
Or
http://IP-Address/phpmyadmin
PhpMyAdmin Login
PhpMyAdmin Login
PhpMyAdmin Dashboard
PhpMyAdmin Dashboard

With this article guide, you can comfortably start testing the behavior of your web app in a production-like environment. You are now familiar with the needed extensions and configurations required to keep your server environment running.

1 thought on “How to Install LAMP Stack with PhpMyAdmin in Arch Linux”

  1. If you having issues with installing MySQL this should help.

    $ cd /var/lib/mysql
    $ rm -r *
    $ mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
    
    Reply

Got something to say? Join the discussion.