Tutorial to install WebServer and get Apache, MySQL, PHP and phpMyAdmin working on Mac OS X 10.11 El Capitan


#1

The following words will give you an specific instruction how to install Web-server and get Apache, MySQL, PHP and phpMyAdmin under Mac OS X El Capitan.

1. Running Commands at Root

sudo su -

2. Enable Apache on Mac OS X El Capitan

apachectl start

How to check Apache version?

httpd -v

Check if the Webserver is working on Mac by accessing http://localhost
If Apache does not work, try troubleshooting Apache to see if there are anything configured wrongly.

apachectl configtest

3. Where is the Document Root?

The default DocumentRoot for Mac OS X El Capitan is /Library/WebServer/Documents. You can verify this from your Apache configuration.

grep DocumentRoot httpd.conf

4. User Level Root

Firstly, make a folder such as “Sites” at the root level.

Add a “username.conf” filed in /etc/apache2/users/
If you don’t already have one (very likely), then create one named by the short username of the account with the suffix .conf, its location and permissions/ownership is best tackled by using the Terminal, the text editor ‘nano‘ would be the best tool to deal with this.

Swap ‘username‘ with your account’s shortname

cd /etc/apache2/users
sudo nano username.conf

add the content below swapping in your ‘username’ in the code below

Set Permissions for the file

chmod 644 username.conf

Modify the httpd.conf

nano /etc/apache2/httpd.conf

Then make sure these modules are uncommented:

LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule include_module libexec/apache2/mod_include.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so
Include /private/etc/apache2/extra/httpd-userdir.conf

Press Control + O to save the change.

Modify httpd-userdir.conf

nano /etc/apache2/extra/httpd-userdir.conf

uncomment:

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

Restart Apache

apachectl restart

Then this user level document root will be viewable at:
http://localhost/~username/

5. Enable PHP on El Capitan

PHP 5.5.29 is loaded in the build of OSX 10.11.1 El Capitan and needs to be turned on by uncommenting a line in the httpd.conf file.

nano /etc/apache2/httpd.conf

Remove the # in front of the following line.

LoadModule php5_module libexec/apache2/libphp5.so

To save the change, use Control + X keyboards.

Restart Apache

apachectl restart

To check PHP version, create a file named “phpinfo.php” in the document root with the contents below, then view it in a browser.

<?php phpinfo(); ?>

Here is the result from http://localhost/phpinfo.php

6. Install MySQL on Mac OS X El Capitan

Download MySQL from the MySQL site - use the Mac OS X 10.10 (x86, 64-bit), DMG Archive version (works on 10.11). After downloading, launch dmg file to start installing MySQL into OS X 10.11 El Capitan.

Access MySQL Preference from System Preference to start MySQL.

How to change the MySQL root password?
Please be clear that this is not the same as the root or admin password of OSX – this is a unique password for the mysql root user, use one and remember/jot down somewhere what it is.

/usr/local/mysql/bin/mysqladmin -u root -p’temppassword’ password ‘newpassword’

Use the single ‘quotes’ surrounding the password

7. Install phpMyAdmin

Before get phpMyAdmin working fine on Mac OS X, you need to Fix the 2002 MySQL Socket error, which is linking where MySQL places the socket and where OSX thinks it should be, MySQL puts it in /tmp and OSX looks for it in /var/mysql the socket is a type of file that allows mysql client/server communication.

mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Download phpMyAdmin, then unzip and move the whole folder into the document root level renaming folder to ‘phpmyadmin’.
Make the config folder

mkdir ~/Sites/phpmyadmin/config

Change the permissions

chmod o+w ~/Sites/phpmyadmin/config

Run the set up in the browser
http://localhost/~username/phpmyadmin/setup/ or http://localhost/phpmyadmin/setup/

Click on new server to create a new localhost mysql server connection

Select Authentication tab then set the local mysql root user and the password.

Click on save, then move this file to the root level of /phpmyadmin and then remove the now empty /config directory.

The http://localhost/~username/phpmyadmin/ must brings you to MySQL databases screen now.

If not you will get an error when trying to log in to the phpmyadmin, you need to run these lines in terminal to make the phpmyadmin connect to the mysql:

mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock