一、安裝自己需要的版本php
- 以php7.1為例,執(zhí)行:curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1
(去這個鏈接下找自己想要下載的php版本 https://php-osx.liip.ch/) - 安裝結(jié)束后,/usr/local/php5目錄下即剛剛install的php
- 此時在終端中輸入php -v 顯示的還是老的版本,可以將這個新的PHP路徑追加到$path中。
vi ~/.profile
在文件中增加以下一行
export PATH=/usr/local/php5/bin:/usr/local/php5/sbin:$PATH
執(zhí)行下面的命令使改動立即生效
source ~/.profile
- 此時運行php -v,已經(jīng)是剛剛安裝的7.1版本
PHP 7.1.13 (cli) (built: Feb 1 2018 13:38:42) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.13, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
- 運行php-fpm -v,查看fpm的版本如下
PHP 7.1.13 (fpm-fcgi) (built: Feb 1 2018 13:38:47)
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.13, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
- php.ini在/usr/local/php5/lib/php.ini
- 擴展的一些配置都在/usr/local/php5/php.d/目錄下,可以看到xdebug擴展已經(jīng)安裝了。
-rw-r--r-- 1 root wheel 75 2 1 20:41 10-extension_dir.ini
-rw-r--r-- 1 root wheel 53 2 1 20:41 20-extension-opcache.ini
-rw-r--r-- 1 root wheel 41 2 1 20:41 40-curl.ini
-rw-r--r-- 1 root wheel 44 2 1 20:41 40-openssl.ini
-rw-r--r-- 1 root wheel 103 2 1 20:41 50-extension-apcu.ini
-rw-r--r-- 1 root wheel 18 2 1 20:41 50-extension-curl.ini
-rw-r--r-- 1 root wheel 17 2 1 20:41 50-extension-gmp.ini
-rw-r--r-- 1 root wheel 83 2 1 20:41 50-extension-igbinary.ini
-rw-r--r-- 1 root wheel 18 2 1 20:41 50-extension-imap.ini
-rw-r--r-- 1 root wheel 79 2 1 20:41 50-extension-intl.ini
-rw-r--r-- 1 root wheel 20 2 1 20:41 50-extension-mcrypt.ini
-rw-r--r-- 1 root wheel 84 2 1 20:41 50-extension-memcached.ini
-rw-r--r-- 1 root wheel 82 2 1 20:41 50-extension-mongodb.ini
-rw-r--r-- 1 root wheel 22 2 1 20:41 50-extension-mssql.ini
-rw-r--r-- 1 root wheel 23 2 1 20:41 50-extension-pdo_pgsql.ini
-rw-r--r-- 1 root wheel 19 2 1 20:41 50-extension-pgsql.ini
-rw-r--r-- 1 root wheel 81 2 1 20:41 50-extension-propro.ini
-rw-r--r-- 1 root wheel 80 2 1 20:41 50-extension-raphf.ini
-rw-r--r-- 1 root wheel 22 2 1 20:41 50-extension-readline.ini
-rw-r--r-- 1 root wheel 80 2 1 20:41 50-extension-redis.ini
-rw-r--r-- 1 root wheel 79 2 1 20:41 50-extension-solr.ini
-rw-r--r-- 1 root wheel 79 2 1 20:41 50-extension-ssh2.ini
-rw-r--r-- 1 root wheel 427 5 8 17:20 50-extension-xdebug.ini
-rw-r--r-- 1 root wheel 17 2 1 20:41 50-extension-xsl.ini
-rw-r--r-- 1 root wheel 79 2 1 20:41 60-extension-pecl_http.ini
-rw-r--r-- 1 root wheel 2004 2 1 20:41 99-liip-developer.ini
- 已經(jīng)安裝編譯的擴展鏡像在/usr/local/php5/lib/php/extensions/no-debug-non-zts-20160303/下
-rwxr-xr-x 1 root wheel 71936 2 1 20:41 apcu.so
-rwxr-xr-x 1 root wheel 78668 2 1 20:41 curl.so
-rwxr-xr-x 1 root wheel 44108 2 1 20:41 gmp.so
-rwxr-xr-x 1 root wheel 350380 2 1 20:41 http.so
-rwxr-xr-x 1 root wheel 42828 2 1 20:41 igbinary.so
-rwxr-xr-x 1 root wheel 3188820 2 1 20:41 imap.so
-rwxr-xr-x 1 root wheel 510600 2 1 20:41 intl.so
-rwxr-xr-x 1 root wheel 38652 2 1 20:41 mcrypt.so
-rwxr-xr-x 1 root wheel 84892 2 1 20:41 memcached.so
-rwxr-xr-x 1 root wheel 2807892 2 1 20:41 mongodb.so
-rwxr-xr-x 1 root wheel 322864 2 1 20:41 opcache.so
-rwxr-xr-x 1 root wheel 38228 2 1 20:41 pdo_pgsql.so
-rwxr-xr-x 1 root wheel 108104 2 1 20:41 pgsql.so
-rwxr-xr-x 1 root wheel 16540 2 1 20:41 propro.so
-rwxr-xr-x 1 root wheel 18064 2 1 20:41 raphf.so
-rwxr-xr-x 1 root wheel 28824 2 1 20:41 readline.so
-rwxr-xr-x 1 root wheel 331964 2 1 20:41 redis.so
-rwxr-xr-x 1 root wheel 232832 2 1 20:41 solr.so
-rwxr-xr-x 1 root wheel 63252 2 1 20:41 ssh2.so
-rwxr-xr-x 1 root wheel 213268 2 1 20:41 xdebug.so
-rwxr-xr-x 1 root wheel 30160 2 1 20:41 xsl.so
二、安裝nginx
- 利用brew神器,brew install nginx
- 安裝完畢后,nginx的相關(guān)配置在/usr/local/etc/nginx/目錄下,沒有nginx.conf的話,將nginx.conf.default拷貝一份命名為nginx.conf
- 如果80端口沖突的話可以把mac自帶的apache2的httpd進程殺死,或者在nginx.conf的server部分監(jiān)聽一個非80端口,比如8080等。
- /usr/local/etc/nginx/servers/目錄下是各個域名單獨的配置。
三、安裝mysql、mongodb
mysql和mongodb都可以使用brew來安裝。
四、Xdebug配置
- 前面已經(jīng)安裝好了Xdebug擴展
- 配置php.ini,增加以下幾行,zend_extension填xdebug擴展鏡像路徑,端口要和phpstorm里配置的一致,可以填9001。
[xdebug]
zend_extension =/usr/local/php5/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.remote_enable = On
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "localhost"
xdebug.remote_port = 9001
xdebug.idekey = PHPSTROM
- 執(zhí)行ps aux | grep php-fpm,找到php-fpm的進程號
root 29992 0.0 0.0 4394508 680 ?? Ss 5:20下午 0:00.61 /usr/local/php5/sbin/php-fpm
clive 32520 0.0 0.0 4286184 900 s002 S+ 7:57下午 0:00.00 grep php-fpm
nobody 31455 0.0 0.0 4402220 3408 ?? S 6:43下午 0:00.55 /usr/local/php5/sbin/php-fpm
nobody 31431 0.0 0.0 4408428 3468 ?? S 6:43下午 0:02.31 /usr/local/php5/sbin/php-fpm
nobody 31428 0.0 0.0 4408428 3428 ?? S 6:43下午 0:02.43 /usr/local/php5/sbin/php-fpm
- 執(zhí)行命令殺死php-fpm進程,sudo kill -9 29992 31455 31431 31428
五、配置PHPStorm的Xdebug工具
-
打開phpstorm,選擇preferences,找到php下的Debug,配置如下:
image.png -
preferences下找到php下的servers,配置如下:
image.png -
preferences下找到php下的Debug下的DBGp Proxy,配置如下:
image.png -
增加web debug配置:
image.png -
配置完畢!打上斷點進行愉快的debug吧~
image.png




