|
http://akrabat.com/php/setting-up-php-mysql-on-os-x-10-7-lion/
Setting up PHP & MySQL on OS X 10.7 Lion
With OS X 10.7, Apple continues to ship PHP 5.3 with PEAR, GD and PDO_MYSQL out of the box. This is how to set it up from a clean install of 10.7.
/usr/local
Ensure that the following directories exist:
sudo mkdir /usr/local/include
sudo mkdir /usr/local/bin
sudo mkdir /usr/local/lib
sudo mkdir -p /usr/local/man/man1
MySQL
- Download the 64bit DMG version of MySQL 5.1.x (or 5.5.x) for OS X 10.6 from mysql.com and install the pkg, the startup item and the pref pane.
- Add /usr/local/mysql/bin to the path: vim ~/.bash_profile and add:
export PATH=~/bin:/usr/local/bin:/usr/local/mysql/bin:$PATH
export EDITOR=vim
at top of file. (Note that we set EDITOR whilst we are here so that svn is happy!)
- Set up MySQL root password:
mysqladmin -u root password {new-password}
mysqladmin -u root -p{new-password} -h localhost password {new-password}
mysqladmin -u root -p{new-password} reload
Clear the history file by typing history -c so that {new-password} isn't in plain text on the disk.
- Now ensure that the mysql.sock file can be found by PHP:
- Ensure that MySQL is running
- sudo mkdir /var/mysql
- sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Apache
- cd /etc/apache2
- Give write permission the config file to root: sudo chmod u+w httpd.conf
- sudo vim httpd.conf
- Find #LoadModule php5_module libexec/apache2/libphp5.so and remove the leading #
- Find AllowOverride None within the <Directory "/Library/WebServer/Documents">section and change toAllowOverride All so that .htaccess files will work.
- Change permissions back: sudo chmod u-w httpd.conf
- Restart Apache by unticking and then ticking again the Web Sharing checkbox in System Preferences -> Sharing
- Open Finder and navigate to /Library/WebServer/Documents/ using shift+cmd+g
- Create a new folder called "orig" and place all files currently in the Documents folder into it. (note that it will ask for your password as the Documents folder is only writable by root.
- Create a new file called info.php with <?php phpinfo(); inside it.
- Use Safari to navigate to http://localhost/info.php and check that the PHP version is displayed (5.3.6 at the time of writing).
php.ini
- cd /etc
- sudo cp php.ini.default php.ini
- sudo chmod ug+w php.ini
- sudo chgrp admin php.ini
- vim php.ini (assuming your user is a member of the admin group) and change settings appropriately. Change:
error_reporting = E_ALL | E_STRICT
display_errors = On
html_errors = On
extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20090626"
(I like to see my xdebug errors in bright orange!)
Also, change all instances of /var/mysql/mysql.sock to /tmp/mysql.sock
Xdebug
Can't have a PHP development environment without xdebug! Apple appears to agree as Lion ships with it.
- vim /etc/php.ini
- Find the line:
;zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
and remove the semicolon at the start
- If you want to configure your xdebug settings, then scroll to the end of the file and look for the [xdebug] section. I like these settings:
xdebug.var_display_max_children = 999
xdebug.var_display_max_data = 99999
xdebug.var_display_max_depth = 100
(use with caution…)
- Restart apache: sudo apachectl restart and check in the phpinfo that xdebug is now loaded.
PEAR
We need PEAR! For some reason, it's not set up ready to on Lion, but the install phar file is here, so we just need to run it.
- cd /usr/lib/php
- sudo php install-pear-nozlib.phar
- Edit/etc/php.ini and find the line: ;include_path = ".:/php/includes" and change it to:
include_path = ".:/usr/lib/php/pear"
- sudo pear channel-update pear.php.net
- sudo pecl channel-update pecl.php.net
- sudo pear upgrade-all
PHPUnit and friends
I assume that everyone needs these…
- sudo pear channel-discover pear.phpunit.de
- sudo pear channel-discover components.ez.no
- sudo pear channel-discover pear.symfony-project.com
- sudo pear install phpunit/PHPUnit
- sudo pear install phpunit/phpcpd
- sudo pear install PHP_CodeSniffer
PECL OAuth
A couple of projects I work on use the PECL OAuth component:
- Ensure you have installed Xcode from the Mac App Store
- Download the latest PCRE source code from http://sourceforge.net/projects/pcre/files/pcre/ and unzip to a folder on your desktop
- cd ~/Desktop/pcre-8.12
- ./configure
- sudo cp pcre.h /usr/include/
- Remove the pcre folder on your desktop as you don't need it any more
- sudo pecl install oauth
- Edit/etc/php.ini add these lines to the end of the file:
[oauth]
extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/oauth.so"
- Restart apache: sudo apachectl restart and check in the phpinfo that OAuth is now loaded.
mcrypt
This is useful! Follow the installation details by Michale Gracie here: http://michaelgracie.com/2011/07/21/plugging-mcrypt-into-php-on-mac-os-x-lion-10-7/)
It all works on this machine, anyway :)
Other options
If you'd rather use a packaged version, then these are two alternatives:
- PHP 5.3 for OS X as binary package
- Zend Server CE
|
|