Home Arch Linux How to Install LAMP Stack with PhpMyAdmin in Arch Linux

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 in 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.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

14 thoughts on “How to Install LAMP Stack with PhpMyAdmin in Arch Linux”

  1. server not started:

    sudo systemctl status httpd
    [sudo] hasło użytkownika maras:
    × httpd.service – Apache Web Server
    Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor pre>
    Active: failed (Result: exit-code) since Wed 2022-01-12 13:55:40 CET; 1min>
    Process: 2117 ExecStart=/usr/bin/httpd -k start -DFOREGROUND (code=exited, >
    Main PID: 2117 (code=exited, status=1/FAILURE)
    CPU: 43ms

    sty 12 13:55:40 maras-n73jg-arch systemd[1]: Started Apache Web Server.
    sty 12 13:55:40 maras-n73jg-arch httpd[2117]: AH00534: httpd: Configuration err>
    sty 12 13:55:40 maras-n73jg-arch systemd[1]: httpd.service: Main process exited>
    sty 12 13:55:40 maras-n73jg-arch systemd[1]: httpd.service: Failed with result >

    Reply
    • Maybe the problem is caused because “More than one MPM loaded”. Following the documentation, you enable one necessary MPM but the documentation forgot to disable one other MPM.

      Reply
    • In /etc/httpd/conf/httpd.conf, comment the line:

      #LoadModule mpm_event_module modules/mod_mpm_event.so
      

      and uncomment the line:

      LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
      
      Reply
  2. 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

Leave a Reply to Roberto Vianna Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.