Spinning up a local web server on OS X shouldn't be difficult, but it's a little fussy. This is a reminder list.
Update the path of the mysql socket. This fixes an OS X bug.
If you have a file at /tmp/mysql.sock but none at /var/mysql/mysql.sock, then:
$ sudo mkdir /var/mysql
$ sudo chmod 755 /var/mysql
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
If you have /var/mysql/mysql.sock but no /tmp/mysql.sock, then:
$ ln -s /var/mysql/mysql.sock /tmp/mysql.sock
Create a MySQL user for the webserver to use:
CREATE DATABASE newdb;
CREATE USER 'example'@'localhost' IDENTIFIED BY 'examplepass';
GRANT ALL ON newdb.* TO 'example'@'localhost';
(Obviously, this user might not need ALL permissions.)
Edit /etc/apache2/httpd.conf
to look in the right places, and allow full access:
Find the section that begins:
<Directory "/Library/Webserver/Documents">
Edit the path to your Sites directory, or some other full path you put you web stuff:
<Directory "/Users/YourUsername/Sites">
Within the indented block begining with that '', make these changes:
Replace AllowOverride None
with AllowOverride All
. This will let .htaccess work.
Replace Options FollowSymLinks Multiviews
with Options Indexes FollowSymLinks Multiviews
. This will enable indexes in directories without index.*
files.
Remove the comment (#) from the line:
#LoadModule php5_module libexec/apache2/libphp5.so
If you use .htaccess files, you'll probably want to enable url rewriting by removing the comment here, too:
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
If you have multiple users, or whatever: Uncomment:
LoadModule userdir_module libexec/apache2/mod_userdir.so
and
Include /private/etc/apache2/extra/httpd-userdir.conf
Optionally, create a vhosts entry to use a domain name other than localhost
.
To do this, uncomment this line in httpd.conf:
Include /private/etc/apache2/extra/httpd-vhosts.conf
Then edit /etc/apache2/httpd/extra/httpd-vhosts.conf
:
<VirtualHost example.domain:80>
ServerAdmin example@example.com
DocumentRoot "/path/to/files"
ServerName example.domain
ErrorLog "/private/var/log/apache2/example.domain-error_log"
CustomLog "/private/var/log/apache2/example.domain-access_log" common
<Directory /path/to/files>
Order allow,deny
Require all granted
</Directory>
</VirtualHost>
Check the syntax of Apache's config files:
$ apachectl -S
If everything looks good, start apache (if not - Google):
$ mkdir ~/Sites
$ sudo apachectl start
Make sure that Apache can read your web files. It runs as the _www
user in the _www
group.
- Add all of your web folders to the _www group by running:
sudo chgrp -R _www /path/to/www
If that's a problem, here's another way:
- Add _www to an ACL for your web folders:
chmod -R +a "_www allow read,execute" /path/to/www
If you'll be using web caches or logs, give the server permission to use the caches and/or logs:
- By changing the group and giving the group write permission
$ sudo chgrp -R _www /path/to/log/or/cache
$ sudo chmod -R g+w /path/to/log/or/cache
If that doesn't work for some reason:
- By adding write to the acl:
chmod -R +a "_www allow read,write,execute" /path/to/www/cache