Install Apache, Mysql and PHP on Arch Linux

This was a really fun and quickly lab that I had one week ago and I decided to publish. So the lab it was basically install Apache and PHP on any linux, in my case I’m a fan of Arch Linux and of course Arch user so if you have another linux version based on Arch like Manjaro you can install in the same way.

In my case I had already installed the Apache and the Mysql but not the PHP, so let go to the deal. Arch is use pacman as a package manager and is really easy to use, so first to install Apache

sudo pacman -S apache

and done, to install mysql and I choose MariaDB as my engine db

sudo pacman -S mysql

done, and to install PHP we need to install this packages

sudo pacman -S php

and

sudo pacman -S php-apache

Now with the php already installed, we need to enable the php with apache, so following the arch wiki documentation, we need to add some lines in the http.conf of the apache.

By default the http.conf of the apache is in this path /etc/httpd/conf/httpd.conf, so first we have a little note of the arch wiki;

Note: libphp5.so included with php-apache does not work with mod_mpm_event (FS#39218). You’ll have to use mod_mpm_prefork instead.

To use mod_mpm_prefork, open /etc/httpd/conf/httpd.conf and replace

LoadModule mpm_event_module modules/mod_mpm_event.so

with

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

As an alternative, you can use mod_proxy_fcgi (see #Using php5 with php-fpm and mod_proxy_fcgi below).

To enable PHP, add these lines to /etc/httpd/conf/httpd.conf: Place this in the LoadModule list anywhere after LoadModule dir_module modules/mod_dir.so:

LoadModule php5_module modules/libphp5.so

Place this at the end of the Include list:

Include conf/extra/php5_module.conf

To test whether PHP was correctly configured: create a file called phpinfo.php in your Apache DocumentRoot directory (e.g. /srv/http/ or ~/public_html) in my case I created a folder “phpinfo” with the following contents:

<?php phpinfo(); ?>
phplinux

References: