mac lion mysql_[转]在mac os lion 里配置mysql与php

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 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

It all works on this machine, anyway :)

Other options

If you'd rather use a packaged version, then these are two alternatives:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值