Show Menu

OSX Setup Web Server PHP MySQL Cheat Sheet by

Setting up web server on osx 10.10

Apache Setup

> Check version
httpd -v

> Start & version
sudo apachectl start
> Test localhost in browser

Setup user
> Create user Sites folder
mkdir ~/Sites

> Create or edit user apache .conf file, don't forget to replace USERNAME by yours
sudo nano /etc/apache2/users/USERNAME.conf

> Paste in USERNAME.conf
<Directory "/Users/*/Sites/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Require all granted

> Edit httpd.conf
sudo nano /etc/apache2/httpd.conf

> Uncomment these line to activate mandatories modules
LoadModule userdir_module libexec/apache2/
LoadModule alias_module libexec/apache2/
LoadModule rewrite_module libexec/apache2/
LoadModule php5_module libexec/apache2/

> Change default apache user _www to USERNAME in httpd.conf
Group staff

> Allow .htaccess and Override
<Directory "/Library/WebServer/Documents">
    AllowOverride All

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

> Edit httpd-userdir.conf
sudo nano /etc/apache2/extra/httpd-userdir.conf
> Uncomment or add this line at the end
Include /private/etc/apache2/users/*.conf

Restart apache
sudo apachectl restart

PHP test file
> Create php test file
printf "<?php phpinfo(); ?>" > ~/Sites/phpinfo.php
> Test phpinfo in browser

Auto start apache
> Set to auto start
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
> Unset to auto start
sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist

Add New Website

You can either way create a new folder in /Library/WebServer/Documents/ or in /Users/USERNAME/Sites/

> Create MYWEBSITE folder
sudo mkdir /Library/WebServer/Documents/MYWEBSITE
> And the access in browser

> Create MYWEBSITE folder
> And the access in browser

Install PHP70


MySQL Setup

Download MySQL
> Get the .dmg install file for OSX 10.10 and install it

Command line MySQL
> Start MySQL
sudo /usr/local/mysql/support-files/mysql.server start
> Check version
/usr/local/mysql/bin/mysql -v

Change $PATH
> edit profile
nano ~/.bash_profile
> add this line
export PATH="/usr/local/mysql/bin:$PATH"
> validate new profile
source ~/.bash_profile
> test change
mysql -v

Change MySQL root password
/usr/local/mysql/bin/mysqladmin -u root password 'yourpasswordhere'

Fix the 2002 MySQL Socket error
> Error in PhpMysql
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock


Download PhpMyAdmin

Extract in /Users/USERNAME/Sites/
> Then access it

Extract in /Library/WebServer/Documents/
> Then access it

Setup a local domain

Set httpd.conf
> Edit httpd.conf
sudo nano /etc/apache2/httpd.conf
> Uncomment
Include /private/etc/apache2/extra/httpd-vhosts.conf
LoadModule vhost_alias_module libexec/apache2/

Set the vhosts.conf file
> Edit vhosts.conf
sudo nano /etc/apache2/extra/httpd-vhosts.conf

> Exemple vhost
<VirtualHost *:80>
    DocumentRoot "/Users/USERNAME/Sites/mywebsite"
    ErrorLog "/private/var/log/apache2/"
    CustomLog "/private/var/log/apache2/" common

    <Directory "/Users/USERNAME/Sites/mywebsite">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all

Restart apache
sudo apachectl restart

Set the hosts file
> Edit hosts
sudo nano /etc/hosts
> Add this to map domain
> Flush cache
dscacheutil -flushcache
sudo dscacheutil -flushcache

Losing localhost
Fix the 403 Forbidden Error

> Edit httpd-vhosts.conf
sudo nano /etc/apache2/extra/httpd-vhosts.conf
> Add in
<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /Library/WebServer/Documents/

Change default apache user and group
> Get username and group
uid=501(USERNAME) gid=20(staff)
> Edit httpd.conf
sudo nano /etc/apache2/httpd.conf
> Change these lines to
Group staff

Restart apache
sudo apachectl restart



No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          HTTP Status Codes Cheat Sheet
          1Password X Mac Keyboard Shortcuts
          Selenium WebDriver Cheat Sheet Cheat Sheet