mac下php环境搭建

作者: chong2230
发布时间:2015-07-21 10:20:15

安装过程:


1.安装eclipse或phpstorm
解压即可


2.在eclipse中安装svn(phpstorm可以略过)
地址:http://subclipse.tigris.org/update_1.8.x


3.安装pecl
命令:
cd /usr/lib/php
sudo php install-pear-nozlib.phar
sudo cp /etc/php.ini.default /etc/php.ini
sudo vi /etc/php.ini
   修改include_path = ".:/php/includes"  --> include_path = ".:/usr/lib/php/pear"
sudo pear channel-update pear.php.net 
sudo pecl channel-update pecl.php.net 
sudo pear upgrade-all


4.安装brew
命令:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Whoops, the Homebrew installer has moved! Please instead run:


ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"


Mac 升级10.10 Yosemite系统 brew 报错无法使用解决办法
vim /usr/local/Library/brew.rb
#!/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -W0


5.安装autoconf
命令:
brew install autoconf


6.安装memcached
命令:
brew search memcache
brew install memcached


Error: Failed to download resource "memcached"
wget http://memcached.org/latest
tar -zxvf memcached-1.x.x.tar.gz
cd memcached-1.x.x
./configure && make && make test && sudo make install


brew install libmemcached
启动:
memcached -p 11211 -m 64 -d


开机自启动:
a.编辑可执行脚本
sudo vim /usr/bin/start-memcached
#!/bin/bash
/usr/bin/memcached -p 11211 -m 64 -d
b.修改脚本权限
sudo chmod +x /usr/bin/start-memcached
c.编辑plist
sudo vim /Library/LaunchDaemons/com.memcached.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.memcached.plist</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/start-memcached</string>
    </array>
    <key>KeepAlive</key>
    <false/>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/tmp/memcached.err</string>
    <key>StandardOutPath</key>
    <string>/tmp/memcached.out</string>
</dict>
</plist>
d.载入plist
sudo launchctl load -w /Library/LaunchDaemons/com.memcached.plist


7.安装php扩展
sudo pecl search memcache
sudo pecl install memcache
sudo pecl install memcached
sudo pecl search redis


sudo pecl install redis
#Mac系统升级到10.9(mavericks)时安装php扩展问题解决
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/include


sudo pecl install redis


8安装xdebug
命令:
brew install zlib

#Error: No available formula for zlib 

brew tap homebrew/dupes

brew install homebrew/dupes/xar

brew install zlib

brew install php54-xdebug

Error: No available formula for php54-xdebug

brew tap josegonzalez/homebrew-php

brew install php54-xdebug


9.修改/etc/php.ini
命令:
sudo vi /etc/php.ini
在文件最后增加:
[xdebug]
zend_extension="/usr/local/Cellar/php54-xdebug/2.2.5/xdebug.so"
xdebug.idekey="PHPSTORM"
xdebug.remote_enable=on


extension=memcache.so
extension=memcached.so
extension=redis.so
修改时区:
date.timezone = Asia/Shanghai


10.通过svn导入php工程
地址:
(根据自己的项目不同,地址不一样)


11.创建路径(根据实际项目路径)
mkdir /Users/san.zhang/documents/workspace_php/mojo/xxx
chmod 777 xxx


12.修改/etc/Apache2/httpd.conf
命令:
sudo vi /etc/apache2/httpd.conf
修改内容:
取消注释:LoadModule php5_module libexec/apache2/libphp5.so
修改运行用户为实际用户:User san.zhang
修改运行组:Group wheel
修改DocumentRoot为实际项目所在目录:DocumentRoot "/Users/san.zhang/documents/workspace_php"
修改Directory为实际项目所在目录:<Directory "/Users/san.zhang/documents/workspace_php">
<Directory "/Library/WebServer/Documents">下AllowOverride None -> AllowOverride All
另一处,如果还不行,则修改:Deny from all -> Allow from all


13.启动apache
命令:
sudo apachectl restart


开机自启动:
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist


14.phpstorm配置
a.菜单phpstorm-preference-Project Setting-Directories
标记当前项目的protected/runtime, assets为excluded
标记工程项目的根目录问resource root
点击Add Content Root,把yii框架的路径添加进来,标记cli/views目录为excluded
b.菜单phpstorm-preference-IDE Settings-File Types
右下角的ignore files里面添加yiilite.php
c.菜单phpstorm-preference-Project Setting-PHP-servers
添加server,host:localhost,port:80,debugger:xdebug
d.菜单run-debug configurations
添加php web application,starturl=/
e.菜单phpstorm-preference-Project Setting-PHP
添加Interpreter:php5.4,路径:全部


15.访问地址,显示游戏画面则表示正常
http://localhost/xxx


16.查看日志:/private/var/log/apache2/



版权声明:本文为博主原创文章,未经博主允许不得转载。

标签: Mac php
来源:http://blog.csdn.net/chong2230/article/details/41733947

推荐: