Httpd.conf is normally protected from editing by Mac OS X. This article shows the easiest way to overcome this security and edit httpd.conf.
Theses editing methods have been tested on Mac OS X 10.6 Snow Leopard (10.6.7, 10.6.8) and Mac OS X Lion 10.7.
Edit Httpd.conf on Mac OS X 10.6 Snow Leopard
If you’re running Snow Leopard, you’ve got it easy! You can edit httpd.conf using the TextEdit app. This method does not work for Lion. If you’re using Lion, go on to the next section.
If you open the httpd.conf file with TextEdit normally, you won’t be able to save. You can’t save httpd.conf because Mac OS X protects httpd.conf, so that people don’t accidentally damage or delete their web server config, or open up security holes.
To edit httpd.conf, you will need superuser or root privileges.
To edit httpd.conf:
- Open the Terminal application.
It’s in the Utilities folder, inside the Applications folder.
- Type in the command below.
It will prompt you with “Password:” on the next line.
- Enter your Mac password.
The TextEdit application will start with httpd.conf loaded.
- Edit httpd.conf.
- Save httpd.conf.
The command to enter is:
sudo open /Applications/TextEdit.app \ --args /etc/apache2/httpd.conf
This method doesn’t work on Lion. Lion has increased security over Snow Leopard. On Lion, opening TextEdit with sudo doesn’t confer enough privileges to TextEdit to open httpd.conf. If I find a workaround to edit httpd.conf in TextEdit on Lion, I’ll post it here. If you know a workaround for Lion, please comment below.
Edit Httpd.conf on Mac OS X 10.7 Lion
Since we can’t edit httpd.conf with TextEdit or other apps on Lion due to tighter security, our next best bet is the simple terminal-based text editor that ships with OS X, pico.
Here’s how to edit httpd.conf with pico:
sudo pico /etc/apache2/httpd.conf
To make life easy, Pico displays a list of keyboard commands at the bottom of the screen, such as
^X Exit. It’s important to know that the hat character “
^” means the control key. So
^X is the same as
Control-X, which means hold down the control key and press and release the X key.
If your familiar with the vi text editor, you could use that instead.
Let me know how you go!