Leopard Development Environment
From ClioWeb Wiki
Here are the steps I took to set up PHP5, MySQL5, PHPMyAdmin, SVN, ImageMagick on my MacBook Pro, running OS 10.5 "Leopard."
For a lot of these steps, you have to edit files from the command line. You can use a command line text editor like Emacs or VI, but if you have Textmate installed and installed the command line tool for it, you can use mate.
Contents |
Enabling PHP5
Leopard comes with PHP5 installed but not enabled. To enable it, do the following:
1. open your httpd.conf file. I open this file in Textmate by going to terminal, and typing:
sudo mate /private/etc/apache2/httpd.conf
Note that I prepend sudo before the command, so the system knows to open the file as the root user. You'll need to do this in most cases. You'll be prompted for a password, which is your users password when logging in to your Mac.
2. Uncomment the line for the php5_module, around 114, by removing the leading "#" so it looks like this:
LoadModule php5_module libexec/apache2/libphp5.so
3. Save the file, then open System Preferences > Sharing, then uncheck and recheck "Web Sharing" to stop and restart your Apache Server
4. To test if PHP is enabled, put a php file in your /Users/username/Sites folder (like phpinfo.php), and add <?php phpinfo(); ?> to it, then visit http://localhost/~youruser/phpinfo.php. If PHP is enabled, you should see a list of information about your PHP installation, including the version number at the top. If not, make sure you uncommented the correct line in the httpd.conf file, that you saved the changes, and that you restarted your server in step 3.
2. Install MySQL5
MySQL has released an installer package for MySQL 5.0.65 for Mac OS 10.5, which makes installation extremely easy. Download the package, unzip it, and first click on the mysql-5.0.67-osx10.5-x86.pkg to install MySQL. Once that installer is finished, you can install the MySQLStartupItem and MySQLprefPane to easily start and stop MySQL from SystemPreferences.
After installing MySQL, we now need to tell PHP5 where the mysql.sock is.
1. In terminal, copy the php configuration example to its expected location
cp /private/etc/php.ini.default /private/etc/php.ini
2. Open the copied file in Textmate
sudo mate /private/etc/php.ini
3. Add /private/tmp/mysql.sock to both mysql.default_socket and mysqli.default_socket, startign around line 760 of the php.ini file.
4. Save, close, and restart Apache by going to System Preferences > Sharing, then uncheck and recheck "Web Sharing."
3. Installing PHPMyAdmin
PHPMyAdmin is a handy system to manage MySQL databased through your browser.
1. Download the relevant package, unzip it in /Users/username/Sites and rename the folder to something useful, like phpmyadmin or mysql, so that you'll go to http://localhost/~username/phpmyadmin to access it.
2. Follow the installation instructions located on phpMyAdmin.net. Its pretty straight-forward. In step 4, I chose to simple enter my mysql user and pass so I wouldn't be prompted for it every time. This isn't very secure if done on a live server, but its probably not a problem on your local machine and no one else has access to it.
4. Installing SVN and ImageMagick with MacPorts
To install ImageMagick and SVN, I use MacPorts. So we'll need to install that first.
Installing MacPorts
1. You'll need to install XCode and X11. I think X11 comes with Leopard, but you'll need to get XCode from the Apple Developer Website, or from the Leopard installer CD that comes with your Mac. If you don't have X11 on your computer, you can install it through the "Optional Installs" package on the Leopard installed CD as well.
2. Download and install MacPorts
3. Follow the instructions for configuring MacPorts from the documentation. In particular, you'll need to add two lines to the top of the ~/.profile or ~/.bash_login file (outlined in the doucmentation here so you can use the "port" command in terminal. MacPorts should add these lines to the .profile file, but if ~/.bash_login exists, you need to add these lines to that file manually, as .bash_login overrides .profile. Those lines are:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH export MANPATH=/opt/local/share/man:$MANPATH
4. Save the file, close and reopen Terminal, and type
port -h
This will show you a help file for how to use the port command. You can also use man port to get a fuller manual for port.
If you get an error message, something like "port command unknown" it can mean:
- Terminal doesn't know where to look for the commands. Check you ~/.bash_login or ~/.profile file to see if the lines we added in step three are there.
- You didn't close and reopen Terminal. After you make changes in ~/.bash_login or ~/.profile, you have to restart Terminal for the changes to take place.
- MacPorts didn't install correctly, so you should try uninstalling MacPorts and rerunning the installer.
Installing ImageMagick
If you installed MacPorts successfully, you can use it to install ImageMagick. In Terminal, type in the following command:
sudo port install ImageMagick
You should get prompted for your password, which is your password for your user account on your computer. Installing ImageMagick will take around 5-10 minutes. The installer will tell you if the installation was successful.
Installing SVN
If you've installed MacPorts successfully, you can install Subversion (SVN) much the same was as installing ImageMagick. Open Terminal, then type in the following command:
sudo port install subversion
You should get prompted for your password, which is your password for your user account on your computer. Installing Subversion will take around 5-10 minutes. The installer will tell you if the installation was successful.
5. Enable mod_rewrite
Most text taken from Enabling Mod_Rewrite by Ben Sekulowicz-Barclay.
mod_rewrite isn't enabled by default, meaning you can do things like custom URLs in WordPress (or use Omeka at all; Omeka requires mod_rewrite enabled). There are a few things you need to do to get it work.
1. Enabling on localhost
The first step is to modify the global Apache configuration file, located in /private/etc/apache2/, (make sure you back it up first).
sudo mate /private/etc/apache2/httpd.conf
The file needs to be edited around line 205, changing AllowOverride None to AllowOverride All.
# AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit AllowOverride All
2. Enabling on your user Sites folder
To have mod_rewrite working in your user Sites folder, you need to edit your user's configuration file. First, type in the following, replacing "username" with your user name:
sudo mate /private/etc/apache2/users/username.conf
Change the line Options None to Options All, so the file would look like this:
<Directory "/Users/username/Sites/">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Save the file, and restart apache for the changes to take effect.
Fancier Stuff
Virtual Hosts
I like having the ability to put all my web sites in my users "Sites" folder, located in /Users/username/Sites, but I hate having to type http://localhost/~username/ to get to it. So, I make an alias and VirtualHost, so /Users/username/Sites can be reached at http://clioweb.dev/. I also have wordpress.dev and omeka.dev for /Users/username/Sites/wordpress/ and /Users/username/Sites/omeka/ respectively. Here's how you do that:
1. To enable virtual hosts, you'll need to edit the httpd.conf file:
mate /private/etc/apache2/httpd.conf
We'll need to uncomment the line that reads:
Include /private/etc/apache2/extra/httpd-vhosts.conf
2. Edit your httpd-vhosts.conf file, located in /private/etc/apache2/extra. I use textmate to edit, but you can use any text editor. For textmate, I use the following command in Terminal:
mate /private/etc/apache2/extra/httpd-vhosts.conf
The file will show you some examples of hosts. You can comment those out, and add your own like so:
<VirtualHost *:80> ServerName clioweb.dev DocumentRoot "/Users/jeremy/Sites" </VirtualHost> <VirtualHost *:80> ServerName wordpress.dev DocumentRoot "/Users/jeremy/Sites/wordpress" </VirtualHost> <VirtualHost *:80> ServerName omeka.dev DocumentRoot "/Users/jeremy/Sites/omeka" </VirtualHost>
2. Edit your hosts file, located at /private/etc/hosts. Again, I edit this in textmate by typing into terminal:
mate /private/etc/hosts
We need to add a host for each of our new server names, like so:
127.0.0.1 clioweb.dev 127.0.0.1 omeka.dev 127.0.0.1 wordpress.dev
You'll need to restart apache for this to work.
