Install PHP on Arch Linux
PHP is a popular dynamic server side programming language. It’s commonly used as part of LAMP stack together with Apache web server. WordPress and many other Content Management Systems require it to run.
Install PHP & Apache PHP Module
Install from the official repository.
sudo pacman -S php
If intending to install & configure apache web server on Arch Linux also install Apache module.
sudo pacman -S php-apache
Configure Apache PHP Module
Open Apache configuration file.
sudo nano /etc/httpd/conf/httpd.conf
Find and comment out LoadModule mpm_event_module modules/mod_mpm_event.so
line. This is needed because of a bug in Arch Linux. After the commented line add line.
Add the following to the configuration file and save.
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so LoadModule php7_module modules/libphp7.so AddHandler php7-script php Include conf/extra/php7_module.conf
The first line enables an alternative module that works with the non-tread safe installation present on Arch Linux. Subsequent lines enables the Apache module. The module number may need to be modified depending on the installed version.
Test PHP
Create a new php file in the root of the server.
sudo nano /srv/http/phpinfo.php
If not using the default web root directory, change /srv/http
to whatever the root directory is configured as.
Add the php_info function and save the file.
<?php phpinfo(); ?>
Open the page in a web browser. For example localhost/phpinfo.php
If PHP version and other information is loaded then PHP is working otherwise it will just print the text in the file.
Configure MySQL Extension
Open the PHP configuration file.
sudo nano /etc/php/php.ini
Enable MySQL extension by uncommenting at least one of the lines below.
;extension=pdo_mysql.so extension=mysqli.so
In php.ini
configuration file the comment is ;
instead of the more common #
. Most commonly used MySQL extension is mysqli.so
while mysql.so
is depreciated and should be left commented out.