Apache, MySQL and PHP on El Capitan


After upgrading to Mac OS X 10.11/El Capitan it is time to check if the webserver is still working as it should.


The file httpd.conf inside /etc/apache2 holds the main configuration of Apache. We want to check if the PHP5 and Userdir modules are loaded correctly.

Make sure the following lines are not commented out, if there is an asterisk in front of it then remove that:

LoadModule php5_module libexec/apache2/libphp5.so
LoadModule userdir_module libexec/apache2/mod_userdir.so

Also for mod_userdir make sure the following line is not commented out as well. It is referencing to an additional confguration file containing module options:

Include /private/etc/apache2/extra/httpd-userdir.conf

Lastly edit the file /private/etc/apache2/extra/httpd-userdir.conf and uncomment the following line:

Include /private/etc/apache2/users/*.conf  

This will make sure that for every ~username/ on your server the corresponding username.conf configuration is loaded.

Restart the webserver using the following command:

sudo apachectl restart


If you have configured the userdir module you should have a file name username.conf for each user that uses the webserver inside the /etc/apache2/users directory.

Those config files usually look like this:

<Directory "/Users/username/Sites/">  
    Options Indexes MultiViews  
    AllowOverride None  
    Order allow,deny  
    Allow from all  

Unfortunately this file contains some obsolete parameters so it will not work. Change the lines:

Order allow, deny  
Allow from all  


Require all granted  

If you want to play with .htaccess options within your web projects then you should change AllowOverride None into AllowOverride All as well. So the correct file syntax should now look like this:

<Directory "/Users/username/Sites/">  
    Options Indexes MultiViews FollowSymlinks  
    AllowOverride All  
    Require all granted  

If you changed any of these options you need to restart the webserver to load in the new configuration.


Test if PHP5 works by creating a small PHP script useing the following code snippet (or use one of your own scripts of course):


Save this snippet as phpinfo.php in your ~/Sites/ directory and run it in your browser as http://localhost/~username/phpinfo.php. This should give you a nice listing of your PHP configuration.


To try something differently we are going to install MariaDB, a clone of MySQL. It can be installed through MacPorts.

sudo port install mariadb-10.0

This will install MariaDB and all of its dependencies.

sudo port select mysql mariadb-10.0

The above command will set mariadb as the default MySQL server. Now we need to setup the default database structures. If you have old databases you can skip this step. This page has more information about this step.

sudo mysql_install_db --user=mysql

The following plist file can be used to start up the server at each boot:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version='1.0'>

This article is my 30th oldest. It is 457 words long.