This post documents the steps for setting up Apache on OS X Lion. Now the way I setup the server is a little different, but I will try to explain why.
- Start Apache Web Server
- Choose System Preferences in the Dock.
- Under Internet and Wireles and choose Sharing.
- Check Web Sharing.
Apache should start up. If it does not, see the Troubleshooting section.
- Uncheck Web Sharing. This stops the Apache server. The server should be stopped so changes can be made to the directory structure.
- Set up the Apache home directory.
The Apache home directory is located at /Library/WebServer/Documents. Of course you can set up your website and do your development there. However, if you perform an
ls -l
on the directory you will see the permissions set to 755 with user ofroot
and a group ofwheel
. So effectively, you have no access to the directory. So you can either make files as root, or add yourself to thewheel
group. Neither is very convenient, so this is the approach I take.- Open a terminal window
- Switch to the root user:
sudo bash
- In your home directory, create a directory to hold your web pages (e.g., www). Note that the permissions will be set to 775 with a user of
root
and a group ofstaff
. Since you are a member of the staff group by default, you have read and execute rights to the directory. - Add write permissions to the directory:
chmod 775 www
. Now this directory can be edited by both the web server and by you. Now we can have the web server point at this directory as its document directory. - Change to web server directory:
cd /Library/WebServer
- Rename the Documents directory:
mv Documents Documents.bk
- Link to the directory our created:
ln -s ~/www Documents
- Type
exit
to exit from your root shell.
- Now enable PHP
- Open a terminal window
- Switch to the root user:
sudo bash
- Change to the configuration directory:
cd /etc/apache2
- Change the permissions so you can edit the configuration directory:
chmod 744 httpd.conf
- Edit the file with your editor of choice.
vi httpd.conf
. Note: If you do not know how to usevi
, learning it is highly recommended as it is almost always available on Unix based systems. - Uncomment this line:
LoadModule php5_module libexec/apache2/libphp5.so
- Restart the Web Server
This should setup the server to work with PHP and allows you to easily edit and manipulate files.
Troubleshooting Tips
Problem: Apache will not start after upgrading from OS X Snow Leopard to Lion
Solution: The first thing to do is find out what error messages are being generated by Apache when it starts. This can be found in the Console application found in the Applications > Utilities > Console. This should list the error messages generated. In my case, the errors were related to directives in the Apache configuration file located at /etc/apache2/httpd.conf. Just commenting out the specific lines indicated in the console solved the startup problems for me.
No comments:
Post a Comment