Show Menu
Cheatography

OSX Setup Web Server PHP MySQL Cheat Sheet by

Setting up web server on osx 10.10

Apache Setup

httpd
> Check version
httpd -v


Apache
> Start & version
sudo apachectl start

> Test localhost in browser
http://localhost

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

</Directory>


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


> Uncomment these line to activate mandatories modules
LoadModule userdir_module libexec/apache2/mod_userdir.so

LoadModule alias_module libexec/apache2/mod_alias.so

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

LoadModule php5_module libexec/apache2/libphp5.so


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

Group staff


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

    
...

    
AllowOverride All

    
...

</Directory>


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


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
http://localhost/~USERNAME/phpinfo.php

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/


/Library/WebServer/Documents/

> Create MYWEBSITE folder
sudo mkdir /Library/WebServer/Documents/MYWEBSITE

> And the access in browser
http://localhost/MYWEBSITE

/Users/USERNAME/Sites/

> Create MYWEBSITE folder
mkdir /Users/USERNAME/Sites/MYWEBSITE

> And the access in browser
http://localhost/~USERNAME/MYWEBSITE

Install PHP70

 

MySQL Setup

Download MySQL
http://dev.mysql.com/downloads/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


PhpMyAdmin

Download PhpMyAdmin
https://www.phpmyadmin.net/downloads/

Extract in /Users/USERNAME/Sites/
> Then access it
http://localhost/~USERNAME/phpMyAdmin

Extract in /Library/WebServer/Documents/
> Then access it
http://localhost/phpMyAdmin

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/mod_vhost_alias.so


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


> Exemple vhost
<VirtualHost *:80>

    
ServerName mywebsite.com

    
ServerAlias www.mywebsite.com

    
DocumentRoot "/Users/USERNAME/Sites/mywebsite"

    
ErrorLog "/private/var/log/apache2/mywebsite.com-error_log"

    
CustomLog "/private/var/log/apache2/mywebsite.com-access_log" common

    
ServerAdmin web@mywebsite.com


    
<Directory "/Users/USERNAME/Sites/mywebsite">

        
Options Indexes FollowSymLinks MultiViews

        
AllowOverride All

        
Order allow,deny

        
Allow from all

    
</Directory>

</VirtualHost>


Restart apache
sudo apachectl restart


Set the hosts file
> Edit hosts
sudo nano /etc/hosts

> Add this to map domain
127.0.0.1 mywebsite.com www.mywebsite.com

> 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/

</VirtualHost>


Change default apache user and group
> Get username and group
id

uid=501(USERNAME) gid=20(staff)

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

> Change these lines to
User USERNAME

Group staff


Restart apache
sudo apachectl restart


                               
 

Comments

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
          Selenium WebDriver Cheat Sheet Cheat Sheet
          ISTQB Test Automation Engineering Cheat Sheet