Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
PHP Dev on Mac OS X 10.10 (PHP, MySQL, Apache, Composer)


to start it

sudo apachectl start

to stop it

sudo apachectl stop

to restart it

sudo apachectl restart

To find the Apache version

httpd -v

It works!


troubleshooting Apache to see if there is anything wrong in its config file by running

apachectl configtest

System Level Web Root


The files are shared in the filing system at – /Library/WebServer/Documents/

User Level Root ~/Sites

Add a .conf

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

Add the content

<Directory "/Users/suvozit/Sites/">
    AllowOverride All
    Options Indexes MultiViews FollowSymLinks
    Require all granted

Set permission

sudo chmod 644 suvozit.conf

Allow some modules:

sudo nano /etc/apache2/httpd.conf

Make sure these 3 modules are uncommented (the first 2 should be on a clean install):

LoadModule authz_core_module libexec/apache2/
LoadModule authz_host_module libexec/apache2/
LoadModule userdir_module libexec/apache2/


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

Then open another Apache config file and uncomment another file:

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

And uncomment:

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

Restart Apache for the new file to be read:

sudo apachectl restart

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

Get php running

sudo nano /etc/apache2/httpd.conf


LoadModule php5_module libexec/apache2/

Restart Apache

sudo apachectl restart

Override .htaccess and allow URL Rewrites

sudo nano /etc/apache2/httpd.conf

Allow any .htaccess files used to override the default settings
Change AllowOverride None to AllowOverride All

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
AllowOverride All


LoadModule rewrite_module libexec/apache2/

Restart Apache

sudo apachectl restart

Test it!

mkdir /Users/suvozit/Sites/welcome
sudo nano /Users/suvozit/Sites/welcome/index.php

Paste it

<?php phpinfo(); ?>




To run a website with no permission issues it is best to set the web root and its contents to be writeable by all, since it’s a local development it should’nt be a security issue.

sudo chmod -R a+w ~/Sites/welcome

If you are concerned about security then instead of making it world writeable you can set the owner to be Apache _www

sudo chown -R _www ~/Sites/welcome


Download and install the Xcode Command Line Tools:
or run the command:

xcode-select --install


# ruby -e "$( replace the direccurl -fsSL"
# OS X El Capitan 10.11
ruby -e "$(curl -fsSL"

Check for any conflicts or problems

brew doctor

Update and upgrade its formulas in case you already had Homebrew installed before:

brew update && brew upgrade


brew tap homebrew/dupes
brew tap homebrew/php

Now install it with the following arguments:

brew install php56 --with-fpm --with-mysql --with-mcrypt

Setup PHP CLI binary

Check version

php -v

Update the $PATH environment variable of shell profile.

echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
. ~/.bash_profile

Now run again:

php -v

PHP info

php -i 

Setup auto start:

Create a folder for our LaunchAgents and symlink the start/stop service:

mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/

And start PHP-FPM:

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

Make sure PHP-FPM is listening on port 9000:

lsof -Pni4 | grep LISTEN | grep php

The output should look something like this:

php-fpm   69659  frdmn    6u  IPv4 0x8d8ebe505a1ae01      0t0  TCP (LISTEN)
php-fpm   69660  frdmn    0u  IPv4 0x8d8ebe505a1ae01      0t0  TCP (LISTEN)
php-fpm   69661  frdmn    0u  IPv4 0x8d8ebe505a1ae01      0t0  TCP (LISTEN)
php-fpm   69662  frdmn    0u  IPv4 0x8d8ebe505a1ae01      0t0  TCP (LISTEN)    

Configure Apache

sudo nano /etc/apache2/httpd.conf


#LoadModule php5_module libexec/apache2/

Uncomment it by removing #, and replace the directory to our new PHP version. The updated line should look like this:

LoadModule php5_module /usr/local/opt/php56/libexec/apache2/

restart Apache

sudo apachectl restart

Check version at



Next step is to install MySQL:

brew install mysql

Setup auto start

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

And start the database server:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Setup CLI

echo 'PATH="/usr/local/mysql/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

Check version

mysql -v

Use these commands to start / stop mysql server:

mysql.server stop
mysql.server start
mysql.server restart

Secure the installation

To seure our MySQL server, we'll exececute the provided secure_mysql_installation binary to change the root password, remove anonymous users and disbale remote root logins:

Securing the MySQL server deployment.

Enter password for root user: 

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:

Nopes. Not required.

> Enter current password for root (enter for none):

Press enter since you don't have one set.

> Change the root password? [Y/n]

Press enter, choose a root password, add it in your 1Password keychain and enter it here.

> Remove anonymous users? [Y/n]

Yes. They are not necessary.

> Disallow root login remotely? [Y/n]

Yes. No need to log in as root from any other IP than

> Remove test database and access to it? [Y/n]

Yes. We don't need the testing tables.

> Reload privilege tables now? [Y/n]

Reload the privilege table to ensure all changes made so far will take effect.

Test connection

mysql -uroot -p

Enter your root password and you should see the MySQL console:

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Quit the session with \q:

mysql> \q

Fix the 2002 MySQL Socket error

Fix the looming 2002 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.

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

Set Timezone

For MySQL 5.7 on Mac OS X El Capitan: /usr/local/opt/mysql/my.cnf
Copy default conf from /usr/local/opt/mysql/support-files/my-default.cnf

cp /usr/local/opt/mysql/support-files/my-default.cnf /usr/local/opt/mysql/my.cnf
sudo nano /usr/local/opt/mysql/my.cnf

insert the following line:


restart mysql server

mysql.server restart


$ mysql -uroot -p
mysql> SELECT @@global.time_zone, @@session.time_zone;
| @@global.time_zone | @@session.time_zone |
| +00:00             | +00:00              |
1 row in set (0.00 sec)


Install autoconf, which is needed for the installation of phpMyAdmin:

brew install autoconf


echo 'PHP_AUTOCONF="'$(which autoconf)'"' >> ~/.bash_profile && . ~/.bash_profile

Let's start with the installation of phpMyAdmin:

brew install phpmyadmin

Note that this formula will NOT install mysql. It is not required since you might want to get connected to a remote database server.

Webserver configuration example (add this at the end of your /etc/apache2/httpd.conf for instance) :

open the file to edit

sudo nano /etc/apache2/httpd.conf

paste the code

Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  <IfModule mod_authz_core.c>
    Require all granted
  <IfModule !mod_authz_core.c>
    Order allow,deny
    Allow from all

and restart apache

sudo apachectl restart

Then, open http://localhost/phpmyadmin



or no-password install

cd /usr/local/share/phpmyadmin



~/Sites as localhost

sudo nano /etc/apache2/httpd.conf


DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
  Options FollowSymLinks Multiviews
  AllowOverride None


DocumentRoot "/Users/suvozit/Sites"
<Directory "/Users/suvozit/Sites">
  Options Indexes FollowSymLinks Multiviews
  AllowOverride All

restart it

sudo apachectl restart




Installing mcrypt library

brew install mcrypt php56-mcrypt

Restart Apache:

sudo apachectl restart


brew install --with-openssl curl


Install globally

curl -sS | php
mv composer.phar /usr/local/bin/composer

Using Composer

cd ~/Sites/project_name
composer install
composer update


cd /tmp/
mkdir -m 0777 aws-cache
mkdir -m 0777 ci
mkdir -m 0777 ci/upload

rm -rf /tmp/ci
# rm -rf drag/n/drop-directory
# -r "recursive" -f "force" (suppress confirmation messages)

ls -a -l
# drwxrwxrwx   2 suvozit  wheel       68 Mar 18 14:58 aws-cache
# drwxrwxrwx   3 suvozit  wheel      102 Mar 18 14:58 ci


  1. In Terminal: crontab -e
  2. Press i to go into vim's insert mode
  3. Type your cron jobs, for example:
[Minute] [hour] [Day_of_the_Month] [Month_of_the_Year] [Day_of_the_Week] [command]
0-59 * * * * echo "Hello World"
* * * * * cd ~/Sites/rime && php index.php controller method param1 param2
  1. Press Esc to exit vim's insert mode

  2. Type ZZ (must be capital letters) (Shift + Z + Z)

  3. Verify by using crontab -l

  4. Check log

cat /var/mail/suvozit
  1. Remove mail
sudo rm -f /var/mail/suvozit


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment