Getting Apache, PHP and MySQL to work on Leopard

Enabling PHP

If you have upgraded from Tiger, you may need to complete this step to get Leopard’s version of Apache to work with UserDir (otherwise ignore this bit):

  • Copy your old userdir configurations from /etc/httpd/users/ to /etc/apache2/users/

PHP is normally disabled by the default Apache configuration, so you will need to load up a text editor and then:

  • Uncomment LoadModule php5_module libexec/apache2/ in /etc/apache2/httpd.conf

Once you’ve saved this, you’ll need to restart apache. The easiest way to do this is to go to System Preferences > Sharing and to turn Web sharing off then on again.

Installing MySQL

To install MySQL, just follow these steps:

  • Download the MySQL OS X disk image from a MySQL mirror
  • Mount the image, and install the main package, the startup item package, and then the preferences pane
  • Add the mysql bin folder to your path:
    sudo echo 'export PATH=$PATH:/usr/local/mysql/bin' >> ~/.bash_profile
  • If no /private/etc/php.ini exists, make a copy of php.ini.default
  • Update php.ini to point at the new MySQL socket mysql.default_socket = /private/tmp/mysql.sock – do this for both mysql and mysqli.
    mysql.default_socket = /private/tmp/mysql.sock
    mysqli.default_socket = /private/tmp/mysql.sock

Other tips if you having problems with .htaccess

Ensure the following directives are enabled (e.g. look in /etc/apache2/users/username.conf) :

Options FollowSymLinks
AllowOverride All

Generating a Certificate Signing Request

When applying for a secure certificate you will need to generate a certificate signing request (CSR). If you are renewing an existing certificate you might want to keep your existing private key, if it’s a new certificate then you will probably need to create a new private key.

If you have previously registered a secure cert and nothing has changed since then, you can even re-use the existing CSR. The most important part of a CSR is the embedded public key, which must correspond to your private key, hence why it only really needs to change if you have changed private key.

What is in a Certificate Signing Request?
A CSR can contain the following information:

  • Domain name (or person’s name)
  • Address details
  • E-mail address
  • Public Key

When you send the CSR to a CA (certificate authority), they will use the information embedded within it to create you a full certificate, which has been signed by them. Some CAs will let you change the address information before generating the certificate.

You can decode a CSR with the following command:

openssl req -in old/ -text -noout
Certificate Request:
       Version: 0 (0x0)
       Subject: C=GB, ST=Hampshire, L=Aldershot, O=Fubra Ltd,
       Subject Public Key Info:
           Public Key Algorithm: rsaEncryption
           RSA Public Key: (1024 bit)
               Modulus (1024 bit):
               Exponent: 65537 (0x10001)
   Signature Algorithm: md5WithRSAEncryption

Generating a new CSR and a new private key
To create a brand new private key and certificate signing request just run:

openssl req -new -nodes -keyout newprivate.key -out server.csr

Generating a new CSR with an existing private key

If you need to generate a certificate signing request from an existing private key, you can do so with the following command:

openssl req -new -key existingprivate.key -out server.csr

Using an existing CSR with an existing private key
You don’t need to run any new commands, just send your existing CSR to the certificate issuer.

When sudo echo ‘test’ > /root/test gives permission denied

If you get a permission denied error when trying to redirect the output of a sudo command then the reason for this is normally because the superuser permissions only apply to the first part of the statement, e.g. the echo command. They do not carry through to the bash redirection.

paul@backups:~$ sudo echo 'test' >> /root/test
-bash: /root/test: Permission denied

One way to get round this is to use the tee command, as follows:

echo 'test' | sudo tee -a /root/test

Note that the -a switch means append to the file if it already exists.

Installing Zend Framework on Ubuntu (Hardy)

As of the 8.04 Hardy release of Ubuntu, Zend Framework has been added to the repositories, so you can install it by simply running:

sudo apt-get install zend-framework

The package installs 17M of files into /usr/share/php/libzend-framework-php/.

Once that has finished, you then need to ensure that the framework is in your PHP include path. The best way to do this is to add the include to your PHP scripts directly, or better still via a global include file. The line you would need to add is:


An example project would then look like:

require_once 'Zend/Mail.php';
$mail = new Zend_Mail();
$mail->setBodyText('My Nice Test Text');
$mail->setBodyHtml('My Nice Test Text');
$mail->setFrom('[email protected]', 'Mr Example');
$mail->addTo('[email protected]', 'Mr Test');

As Andy pointed out in a comment, Zend Framework is evolving quite rapidly, so if the Ubuntu repository version fails to meet your needs, then you could easily install and switch to a newer version for certain projects if you modify the include path this way.