بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم

Apache is a popular web server. A web server is a program that shows websites. Apache is made by the Apache Software Foundation. This tutorial shows how to set up Apache. You can also connect it to PHP if you need it.

On Arch Linux, MySQL is replaced by MariaDB. MariaDB is a replacement for MySQL that works the same way. So the commands below use MariaDB, but they work just like MySQL.

Installation

First, install the packages you need:

sudo pacman -S php apache mariadb php-apache phpmyadmin

This command installs everything at once. You do not need to install mcrypt. mcrypt was removed from PHP in version 7.2, and phpMyAdmin does not need it.

Configuration

Open the Apache config file:

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

Add a hash mark at the start of this line:

LoadModule mpm_event_module modules/mod_mpm_event.so

Then remove the hash mark at the start of this line:

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

Add these three lines at the end of the file, then save the file:

LoadModule php_module modules/libphp.so
AddHandler php-script .php
Include conf/extra/php_module.conf

Before restarting, check the configuration first:

sudo apachectl configtest

The result should be Syntax OK. If there is an error, read the message and fix the line it mentions.

Now start Apache and check its status:

sudo systemctl enable httpd
sudo systemctl restart httpd
sudo systemctl status httpd

img1

Next, set up MySQL. MySQL is a database that stores website data.

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

Start MySQL:

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

img2

Once MySQL is running, set a root password. This command must run with sudo so it can log in as root. Just press Enter if it asks any questions. See the image below for an example:

sudo mysql_secure_installation

img3

Now let’s test PHP. First, create a test file in the /srv/http/ folder:

sudo nano /srv/http/test.php

Fill the file with this:

<?php
phpinfo();
?>

img4

Open this address in your browser: http://localhost/test.php

img5

Next, set up phpMyAdmin. phpMyAdmin is a web app for managing a MySQL database in the browser.

sudo nano /etc/php/php.ini

Enable the extensions below. To do that, remove the semicolon in front of each one. If an extension is not in the list, add it yourself:

extension=pdo_mysql
extension=mysqli
extension=bz2
extension=zip
extension=iconv.so

Open the phpMyAdmin config file:

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

Fill the file with this:

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

img6

Add this line to the /etc/httpd/conf/httpd.conf file, then check the configuration and restart Apache:

Include conf/extra/phpmyadmin.conf
sudo apachectl configtest
sudo systemctl restart httpd

Open this address in your browser: http://localhost/phpmyadmin/

img7

Hope this helps.

References

  1. https://wiki.archlinux.org/title/Apache_HTTP_Server
  2. https://wiki.archlinux.org/title/PHP
  3. https://wiki.archlinux.org/title/phpMyAdmin