[[Wikipedia:LAMP (software bundle)|LAMP]] refers to a common combination of software used in many web servers: '''L'''inux, '''A'''pache, '''M'''ySQL, and '''P'''HP. This article describes how to set up the [http://httpd.apache.org Apache HTTP Server] on an Arch Linux system. It also tells you how to optionally install [[PHP]] and [[MySQL]] and integrate these in the Apache server.

[[Wikipedia:LAMP (software bundle)|LAMP]] refers to a common combination of software used in many web servers: '''L'''inux, '''A'''pache, '''M'''ySQL/'''M'''ariaDB, and '''P'''HP. This article describes how to set up the [http://httpd.apache.org Apache HTTP Server] on an Arch Linux system. It also tells you how to optionally install [[PHP]] and [[MariaDB]] and integrate these in the Apache server.

If you only need a web server for development and testing, [[Xampp]] might be a better and easier option.

If you only need a web server for development and testing, [[Xampp]] might be a better and easier option.

−

==Installation==

+

== Installation ==

−

# pacman -S apache php php-apache mysql

+

This document assumes you will install Apache, PHP and MariaDB together. If desired however, you may install Apache, PHP, and MariaDB separately and simply refer to the relevant sections below.

−

This document assumes you will install Apache, PHP and MySQL together. If desired however, you may install Apache, PHP, and MySQL separately and simply refer to the relevant sections below.

+

You can [[pacman|install]] {{Pkg|apache}}, {{Pkg|php}}, {{Pkg|php-apache}} and {{Pkg|mariadb}} from the [[official repositories]].

−

{{Note|New default user and group: Instead of group "nobody", apache now runs as user/group "http" by default. You might want to adjust your httpd.conf according to this change, though you may still run httpd as nobody.}}

+

{{Note|Even though Apache 2.4 was released over a year ago (Feb 2012), it still isn't available in the official repositories. You can however get it from the [[AUR]] as {{Pkg|apache24}}.}}

−

==Configuration==

+

== Configuration ==

−

===Apache===

+

=== Apache ===

−

For security reasons, as soon as Apache is started by the root user (directly or via startup scripts) it switches to the UID/GID specified in {{ic|/etc/httpd/conf/httpd.conf}}

+

For security reasons, as soon as Apache is started by the root user (directly or via startup scripts) it switches to the UID/GID specified in {{ic|/etc/httpd/conf/httpd.conf}}. The default is user '''http''' and it is created automatically during installation.

−

* Check for the existence of the http user by looking for ''http'' in the output of the following command:

+

Change {{ic|httpd.conf}} and optionally {{ic|extra/httpd-default.conf}} to your liking and start the {{ic|httpd}} daemon using [[systemd]].

−

# grep http /etc/passwd

+

−

* Create the system user http if it does not exist already:

+

Apache should now be running. Test by visiting http://localhost/ in a web browser. It should display a simple Apache test page.

−

# useradd -d /srv/http -r -s /bin/false -U http

+

−

:This creates the http user with home directory {{ic|/srv/http/}}, as a system account (-r), with a bogus shell (-s {{ic|/bin/false}}) and creates a group with the same name (-U).

+

−

* Change {{ic|httpd.conf}} and optionally {{ic|extra/httpd-default.conf}} to your liking. For security reasons, you might want to change '''ServerTokens Full''' to '''ServerTokens Prod''' and '''ServerSignature On''' to '''ServerSignature Off''' in {{ic|extra/httpd-default.conf}}.

+

==== User directories ====

+

* User directories are available by default through http://localhost/~user/ and show the contents of {{ic|~/public_html}} (this can be changed in {{ic|/etc/httpd/conf/extra/httpd-userdir.conf}}).

* If you do not want user directories to be available on the web, comment out the following line in {{ic|/etc/httpd/conf/httpd.conf}}:

−

+

−

:Apache should now be running. Test by visiting http://localhost/ in a web browser. It should display a simple Apache test page. If you receive a 403 Error, comment out the following line in {{ic|/etc/httpd/conf/httpd.conf}}:

+

Include conf/extra/httpd-userdir.conf

Include conf/extra/httpd-userdir.conf

−

−

* It is also possible to start '''httpd''' automatically [[Daemons#Starting on boot|at boot]].

−

−

====User dirs====

−

* If you do not want user directories to be available on the web (e.g., {{ic|~/public_html}} on the machine is accessed as http://localhost/~user/ -Note that you can change what this points to in {{ic|/etc/httpd/conf/extra/httpd-userdir.conf}}), comment the following line in {{ic|/etc/httpd/conf/httpd.conf}} since they are activated by default:

−

Include conf/extra/httpd-userdir.conf

* You must make sure that your home directory permissions are set properly so that Apache can get there. Your home directory and {{ic|~/public_html/}} must be executable for others ("rest of the world"). This seems to be enough:

* You must make sure that your home directory permissions are set properly so that Apache can get there. Your home directory and {{ic|~/public_html/}} must be executable for others ("rest of the world"). This seems to be enough:

−

$ chmod o+x ~

+

$ chmod o+x ~

−

$ chmod o+x ~/public_html

+

$ chmod o+x ~/public_html

−

* More secure way to share your home folder with apache is to add '''http user''' in group that your home folder belongs. For example, if your home folder and other sub-folders in your home folder belong to group '''piter''', all you have to do is following:

+

* A more secure way to share your home folder with Apache is to add the '''http''' user to the group that owns your home folder. For example, if your home folder and other sub-folders in your home folder belong to group '''piter''', all you have to do is following:

+

# usermod -aG piter http

−

$ usermod -aG piter http

+

* Of course, you have to give ''read'' and ''execute'' permissions on {{ic|~/}}, {{ic|~/public_html}}, and all other sub-folders in {{ic|~/public_html}} to the group members (group '''piter''' in our case). Do something like the following ('''modify the commands for your specific case'''):

+

$ chmod g+xr-w /home/''yourusername''

+

$ chmod -R g+xr-w /home/''yourusername''/public_html

−

* Of course, you have to give ''read'' and ''execute'' permissions on {{ic|~/}}, {{ic|~/public_html}}, and all other sub-folders in {{ic|~/public_html}} to the group members (group '''piter''' in our case). Do something like following ('''modify commands for your specific case'''):

+

{{Note|This way you do not have to give access to your folder to every single user in order to give access to '''http''' user. Only the '''http''' user and other potential users that are in the '''piter''' group will have access to your home folder.}}

−

$ chmod g+xr-w /home/''yourusername''

+

Restart {{ic|httpd}} to apply any changes.

−

$ chmod -R g+xr-w /home/''yourusername''/public_html

+

−

{{Note|This way you do not have to give access to your folder to every single user in order to give access to '''http user'''. Only '''http user''' and other potential users that are in '''piter''' group will have access to your home folder.}}

+

==== SSL ====

+

* Create a self-signed certificate (you can change the key size and the number of days of validity):

Add your virtual host names to your {{ic|/etc/hosts}} file (NOT necessary if bind is serving these domains already, but will not hurt):

+

* Add your virtual host names to your {{ic|/etc/hosts}} file (not necessary if a DNS server is serving these domains already, but will not hurt to do it anyway):

−

{{bc|127.0.0.1 domainname1.dom

+

127.0.0.1 domainname1.dom

−

127.0.0.1 domainname2.dom}}

+

127.0.0.1 domainname2.dom

−

and restart '''httpd'''.

+

Restart {{ic|httpd}} to apply any changes.

−

If you setup your virtual hosts to be in your user directory, sometimes it interferes with Apache's 'Userdir' settings. To avoid problems disable 'Userdir' by commenting it out:

+

* If you setup your virtual hosts to be in your user directory, sometimes it interferes with Apache's {{ic|Userdir}} settings. To avoid problems disable {{ic|Userdir}} by comment the following line in:

−

{{bc|

+

#Include conf/extra/httpd-userdir.conf

−

# User home directories

+

−

#Include conf/extra/httpd-userdir.conf}}

+

−

As said above, ensure that you have the proper permissions:

+

* As said above, ensure that you have the proper permissions:

−

# chmod 0775 /home/yourusername/

+

# chmod 0775 /home/''yourusername''/

−

If you have a huge amount of virtual hosts you easily want to dis- and enable, it's recommended to create one config file per virtualhost and store them all in one folder, eg: {{ic|/etc/httpd/conf/vhosts}}.

+

* If you have a huge amount of virtual hosts, you may want to easily disable and enable them. It is recommended to create one configuration file per virtual host and store them all in one folder, eg: {{ic|/etc/httpd/conf/vhosts}}.

−

First create the folder:

+

* First create the folder:

# mkdir /etc/httpd/conf/vhosts

# mkdir /etc/httpd/conf/vhosts

−

Then place the single config files in them:

+

* Then place the single configuration files in it:

# nano /etc/httpd/conf/vhosts/domainname1.dom

# nano /etc/httpd/conf/vhosts/domainname1.dom

# nano /etc/httpd/conf/vhosts/domainname2.dom

# nano /etc/httpd/conf/vhosts/domainname2.dom

...

...

−

In the last step, "Include" the single configs in your {{ic|/etc/httpd/conf/httpd.conf}}:

+

* In the last step, {{ic|Include}} the single configurations in your {{ic|/etc/httpd/conf/httpd.conf}}:

−

{{bc|#Enabled Vhosts:

+

#Enabled Vhosts:

−

Include conf/vhosts/domainname1.dom

+

Include conf/vhosts/domainname1.dom

−

#Include conf/vhosts/domainname1.dom}}

+

Include conf/vhosts/domainname2.dom

−

You can enable and disable single virtual hosts by commenting them out or uncommenting them.

+

* You can enable and disable single virtual hosts by commenting or uncommenting them.

−

====Advanced Options====

+

==== Advanced Options ====

−

These options in {{ic|/etc/httpd/conf/httpd.conf}} might be interesting for you:

+

These options in {{ic|/etc/httpd/conf/httpd.conf}} might be interesting for you.

# Listen 80

# Listen 80

−

This is the port Apache will listen to. For Internet-access with router, you have to forward the port.

+

* This is the port Apache will listen to. For Internet-access with router, you have to forward the port.

If you setup Apache for local development you may want it to be only accessible from your computer. Then change this line to:

If you setup Apache for local development you may want it to be only accessible from your computer. Then change this line to:

# Listen 127.0.0.1:80

# Listen 127.0.0.1:80

−

This is the admin's email-address which can be found on e.g. error-pages:

+

* This is the admin's email address which can be found on e.g. error pages:

−

# ServerAdmin sample@sample.com

+

# ServerAdmin you@example.com

−

This is the directory where you should put your web pages:

+

* This is the directory where you should put your web pages:

# DocumentRoot "/srv/http"

# DocumentRoot "/srv/http"

−

Change it, if you want to, but do not forget to also change the

+

Change it, if you want to, but do not forget to also change

<Directory "/srv/http">

<Directory "/srv/http">

−

to whatever you changed your DocumentRoot to, or you will likely get a 403 error (lack of privileges) when you try to access the new document root. Do not forget to change the Deny from all line, otherwise you will get 403 error too.

+

to whatever you changed your {{ic|DocumentRoot}} too, or you will likely get a '''403 Error''' (lack of privileges) when you try to access the new document root. Do not forget to change the {{ic|Deny from all}} line, otherwise you will get a '''403 Error'''.

# AllowOverride None

# AllowOverride None

−

This directive in {{ic|<Directory>}} sections causes apache to completely ignore .htaccess files. If you intend to use rewrite mod or other settings in .htaccess files, you can allow which directives declared in that file can override server configuration. For more info refer to http://httpd.apache.org/docs/current/mod/core.html#allowoverride

+

* This directive in {{ic|<Directory>}} sections causes Apache to completely ignore {{ic|.htaccess}} files. If you intend to use {{ic|mod_rewrite}} or other settings in {{ic|.htaccess}} files, you can allow which directives declared in that file can override server configuration. For more info refer to the [http://httpd.apache.org/docs/current/mod/core.html#allowoverride Apache documentation].

−

{{Note|If you have issues with your configuration you can have apache check the configuration with:

+

{{Note|If you have issues with your configuration you can have Apache check the configuration with: {{ic|apachectl configtest}}}}

* To test whether PHP was correctly configured: create a file called {{ic|test.php}} in your Apache {{ic|DocumentRoot}} directory (e.g. {{ic|/srv/http/}} or {{ic|~/public_html}}) and inside it put:

<?php phpinfo(); ?>

<?php phpinfo(); ?>

−

:See if it works: http://localhost/test.php or http://localhost/~myname/test.php

+

:To see if it works go to: http://localhost/test.php or http://localhost/~myname/test.php

−

:If the PHP code is is not executed (you see : <html>...</html>), check that you have added "Includes" to the "Options" line for your root directory in {{ic|/etc/httpd/conf/httpd.conf}}. Moreover, check that {{ic|TypesConfig conf/mime.types}} is uncommented in the <IfModule mime_module> section, you may also try adding the following to the <IfModule mime_module> in httpd.conf:

+

:If the PHP code is not executed (you see plain text in {{ic|test.php}}), check that you have added {{ic|Includes}} to the {{ic|Options}} line for your root directory in {{ic|/etc/httpd/conf/httpd.conf}}. Moreover, check that {{ic|TypesConfig conf/mime.types}} is uncommented in the <IfModule mime_module> section, you may also try adding the following to the {{ic|<IfModule mime_module>}} in {{ic|httpd.conf}}:

AddHandler application/x-httpd-php .php

AddHandler application/x-httpd-php .php

−

====Advanced options====

+

==== Advanced options ====

−

* It is recommended to set your timezone in {{ic|/etc/php/php.ini}} like so: ([http://www.php.net/manual/en/timezones.php list of timezones])

+

* It is recommended to set your timezone ([http://www.php.net/manual/en/timezones.php list of timezones]) in {{ic|/etc/php/php.ini}} like so:

{{bc|1=date.timezone = Europe/Berlin}}

{{bc|1=date.timezone = Europe/Berlin}}

−

* If you want to display errors to debug your php code, change {{ic|display_errors}} to {{ic|On}} in {{ic|/etc/php/php.ini}}:

+

* If you want to display errors to debug your PHP code, change {{ic|display_errors}} to {{ic|On}} in {{ic|/etc/php/php.ini}}:

display_errors=On

display_errors=On

−

* If you want the libGD module, install {{Pkg|php-gd}} and uncomment {{ic|1=extension=gd.so}} in {{ic|/etc/php/php.ini}}:

+

* If you want the {{ic|libGD}} module, install {{Pkg|php-gd}} and uncomment {{ic|1=extension=gd.so}} in {{ic|/etc/php/php.ini}}:

{{Note|Pay attention to which extension you uncomment, as this extension is sometimes mentioned in an explanatory comment before the actual line you want to uncomment.}}

{{Note|Pay attention to which extension you uncomment, as this extension is sometimes mentioned in an explanatory comment before the actual line you want to uncomment.}}

−

* If you want the mcrypt module, install {{Pkg|php-mcrypt}} and uncomment {{ic|1=extension=mcrypt.so}} in {{ic|/etc/php/php.ini}}:

+

* If you want the {{ic|mcrypt}} module, install {{Pkg|php-mcrypt}} and uncomment {{ic|1=extension=mcrypt.so}} in {{ic|/etc/php/php.ini}}:

extension=mcrypt.so

extension=mcrypt.so

−

* Remember to add a file handler for .phtml if you need it in {{ic|/etc/httpd/conf/extra/php5_module.conf}}:

+

* Remember to add a file handler for {{ic|.phtml}}, if you need it, in {{ic|/etc/httpd/conf/extra/php5_module.conf}}:

DirectoryIndex index.php index.phtml index.html

DirectoryIndex index.php index.phtml index.html

==== Using php5 with apache2-mpm-worker and mod_fcgid ====

==== Using php5 with apache2-mpm-worker and mod_fcgid ====

−

Uncomment following in {{ic|/etc/conf.d/apache}}:

+

* Uncomment following in {{ic|/etc/conf.d/apache}}:

HTTPD=/usr/sbin/httpd.worker

HTTPD=/usr/sbin/httpd.worker

−

Uncomment following in {{ic|/etc/httpd/conf/httpd.conf}}:

+

+

* Uncomment following in {{ic|/etc/httpd/conf/httpd.conf}}:

Include conf/extra/httpd-mpm.conf

Include conf/extra/httpd-mpm.conf

−

Install mod_fcgid and php-cgi packages:

+

−

# pacman -S mod_fcgid php-cgi

+

* [[Pacman|Install]] the {{pkg|mod_fcgid}} and {{Pkg|php-cgi}} packages from the [[official repositories]].

−

Create {{ic|/etc/httpd/conf/extra/php5_fcgid.conf}} with following content:

+

−

{{bc|1=

+

* Create {{ic|/etc/httpd/conf/extra/php5_fcgid.conf}} with following content:

+

{{hc|/etc/httpd/conf/extra/php5_fcgid.conf|<nowiki>

# Required modules: fcgid_module

# Required modules: fcgid_module

Line 282:

Line 281:

Options +ExecCGI

Options +ExecCGI

</Location>

</Location>

−

</IfModule>

+

</IfModule></nowiki>

}}

}}

−

Create needed directory and symlink for php wrapper:

+

* Create the needed directory and symlink it for the PHP wrapper:

# mkdir /srv/http/fcgid-bin

# mkdir /srv/http/fcgid-bin

# ln -s /usr/bin/php-cgi /srv/http/fcgid-bin/php-fcgid-wrapper

# ln -s /usr/bin/php-cgi /srv/http/fcgid-bin/php-fcgid-wrapper

−

Edit {{ic|/etc/httpd/conf/httpd.conf}}:

+

* Edit {{ic|/etc/httpd/conf/httpd.conf}}:

#LoadModule php5_module modules/libphp5.so

#LoadModule php5_module modules/libphp5.so

LoadModule fcgid_module modules/mod_fcgid.so

LoadModule fcgid_module modules/mod_fcgid.so

Include conf/extra/php5_fcgid.conf

Include conf/extra/php5_fcgid.conf

−

Make sure {{ic|/etc/php/php.ini}} has the directive enabled:

+

+

* Make sure {{ic|/etc/php/php.ini}} has the directive enabled:

cgi.fix_pathinfo=1

cgi.fix_pathinfo=1

−

and [[systemd#Using_units|restart]] '''httpd'''.

+

and [[Daemons|restart]] '''httpd'''.

−

{{Note|1=As of Apache 2.4 (available as [https://aur.archlinux.org/packages.php?ID=60719 AUR package]) you can now use [http://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html mod_proxy_fcgi] (part of the official distribution) with PHP-FPM (and the new event MPM). See [http://wiki.apache.org/httpd/PHP-FPM configuration example]}}

+

{{Note|1=As of Apache 2.4 (the {{AUR|apache24}} package is available in the [[AUR]]) you can now use [http://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html mod_proxy_fcgi] (part of the official distribution) with PHP-FPM (and the new event MPM). See this [http://wiki.apache.org/httpd/PHP-FPM configuration example].}}

−

===MySQL===

+

=== MariaDB ===

−

* Configure MySQL as described in [[MySQL]].

+

* Configure MySQL/MariaDB as described in [[MariaDB]].

−

* Uncomment at least one of the following lines in {{ic|/etc/php/php.ini}}:

+

* Uncomment [http://www.php.net/manual/en/mysqlinfo.api.choosing.php at least one] of the following lines in {{ic|/etc/php/php.ini}}:

extension=pdo_mysql.so

extension=pdo_mysql.so

extension=mysqli.so

extension=mysqli.so

Line 309:

Line 309:

* You can add minor privileged MySQL users for your web scripts. You might also want to edit {{ic|/etc/mysql/my.cnf}} and uncomment the {{ic|skip-networking}} line so the MySQL server is only accessible by the localhost. You have to restart MySQL for changes to take effect.

* You can add minor privileged MySQL users for your web scripts. You might also want to edit {{ic|/etc/mysql/my.cnf}} and uncomment the {{ic|skip-networking}} line so the MySQL server is only accessible by the localhost. You have to restart MySQL for changes to take effect.

−

* [[Systemd#Using units|Restart]] '''httpd'''.

+

* [[Daemons|Restart]] the '''httpd''' daemon.

{{Tip|You may want to install a tool like [[phpMyAdmin]], [[Adminer]] or {{AUR|mysql-workbench}} to work with your databases.}}

{{Tip|You may want to install a tool like [[phpMyAdmin]], [[Adminer]] or {{AUR|mysql-workbench}} to work with your databases.}}

Note: Even though Apache 2.4 was released over a year ago (Feb 2012), it still isn't available in the official repositories. You can however get it from the AUR as apache24.

Configuration

Apache

For security reasons, as soon as Apache is started by the root user (directly or via startup scripts) it switches to the UID/GID specified in /etc/httpd/conf/httpd.conf. The default is user http and it is created automatically during installation.

Change httpd.conf and optionally extra/httpd-default.conf to your liking and start the httpd daemon using systemd.

Apache should now be running. Test by visiting http://localhost/ in a web browser. It should display a simple Apache test page.

User directories

User directories are available by default through http://localhost/~user/ and show the contents of ~/public_html (this can be changed in /etc/httpd/conf/extra/httpd-userdir.conf).

If you do not want user directories to be available on the web, comment out the following line in /etc/httpd/conf/httpd.conf:

Include conf/extra/httpd-userdir.conf

You must make sure that your home directory permissions are set properly so that Apache can get there. Your home directory and ~/public_html/ must be executable for others ("rest of the world"). This seems to be enough:

$ chmod o+x ~
$ chmod o+x ~/public_html

A more secure way to share your home folder with Apache is to add the http user to the group that owns your home folder. For example, if your home folder and other sub-folders in your home folder belong to group piter, all you have to do is following:

# usermod -aG piter http

Of course, you have to give read and execute permissions on ~/, ~/public_html, and all other sub-folders in ~/public_html to the group members (group piter in our case). Do something like the following (modify the commands for your specific case):

Note: This way you do not have to give access to your folder to every single user in order to give access to http user. Only the http user and other potential users that are in the piter group will have access to your home folder.

Restart httpd to apply any changes.

SSL

Create a self-signed certificate (you can change the key size and the number of days of validity):

Add your virtual host names to your /etc/hosts file (not necessary if a DNS server is serving these domains already, but will not hurt to do it anyway):

127.0.0.1 domainname1.dom
127.0.0.1 domainname2.dom

Restart httpd to apply any changes.

If you setup your virtual hosts to be in your user directory, sometimes it interferes with Apache's Userdir settings. To avoid problems disable Userdir by comment the following line in:

#Include conf/extra/httpd-userdir.conf

As said above, ensure that you have the proper permissions:

# chmod 0775 /home/yourusername/

If you have a huge amount of virtual hosts, you may want to easily disable and enable them. It is recommended to create one configuration file per virtual host and store them all in one folder, eg: /etc/httpd/conf/vhosts.

In the last step, Include the single configurations in your /etc/httpd/conf/httpd.conf:

#Enabled Vhosts:
Include conf/vhosts/domainname1.dom
Include conf/vhosts/domainname2.dom

You can enable and disable single virtual hosts by commenting or uncommenting them.

Advanced Options

These options in /etc/httpd/conf/httpd.conf might be interesting for you.

# Listen 80

This is the port Apache will listen to. For Internet-access with router, you have to forward the port.

If you setup Apache for local development you may want it to be only accessible from your computer. Then change this line to:

# Listen 127.0.0.1:80

This is the admin's email address which can be found on e.g. error pages:

# ServerAdmin you@example.com

This is the directory where you should put your web pages:

# DocumentRoot "/srv/http"

Change it, if you want to, but do not forget to also change

<Directory "/srv/http">

to whatever you changed your DocumentRoot too, or you will likely get a 403 Error (lack of privileges) when you try to access the new document root. Do not forget to change the Deny from all line, otherwise you will get a 403 Error.

# AllowOverride None

This directive in <Directory> sections causes Apache to completely ignore .htaccess files. If you intend to use mod_rewrite or other settings in .htaccess files, you can allow which directives declared in that file can override server configuration. For more info refer to the Apache documentation.

Note: If you have issues with your configuration you can have Apache check the configuration with: apachectl configtest

More settings in /etc/httpd/conf/extra/httpd-default.conf:

To turn off your server's signature:

ServerSignature Off

To hide server information like Apache and PHP versions:

ServerTokens Prod

PHP

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

Make sure that the following line is uncommented in the <IfModule mime_module> section:

TypesConfig conf/mime.types

Uncomment the following line (optional):

MIMEMagicFile conf/magic

Add this line in /etc/httpd/conf/mime.types:

application/x-httpd-php php php5

Note: If you do not see libphp5.so in the Apache modules directory (/etc/httpd/modules), you may have forgotten to install php-apache.

If your DocumentRoot is not /srv/http, add it to open_basedir in /etc/php/php.ini as such:

If the PHP code is not executed (you see plain text in test.php), check that you have added Includes to the Options line for your root directory in /etc/httpd/conf/httpd.conf. Moreover, check that TypesConfig conf/mime.types is uncommented in the <IfModule mime_module> section, you may also try adding the following to the <IfModule mime_module> in httpd.conf:

AddHandler application/x-httpd-php .php

Advanced options

It is recommended to set your timezone (list of timezones) in /etc/php/php.ini like so:

date.timezone = Europe/Berlin

If you want to display errors to debug your PHP code, change display_errors to On in /etc/php/php.ini:

display_errors=On

If you want the libGD module, install php-gd and uncomment extension=gd.so in /etc/php/php.ini:

MariaDB

You can add minor privileged MySQL users for your web scripts. You might also want to edit /etc/mysql/my.cnf and uncomment the skip-networking line so the MySQL server is only accessible by the localhost. You have to restart MySQL for changes to take effect.