Mac超快速搭建Nginx、PHP、PHPStorm、XDebug環境

1、安裝本身須要的版本php

  1. 以php7.1爲例,執行:curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1
    (去這個連接下找本身想要下載的php版本 https://php-osx.liip.ch/
  2. 安裝結束後,/usr/local/php5目錄下即剛剛install的php
  3. 此時在終端中輸入php -v 顯示的仍是老的版本,能夠將這個新的PHP路徑追加到$path中。
vi ~/.profile
在文件中增長如下一行
export PATH=/usr/local/php5/bin:/usr/local/php5/sbin:$PATH
執行下面的命令使改動當即生效
source ~/.profile
  1. 此時運行php -v,已是剛剛安裝的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
  1. 運行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
  1. php.ini在/usr/local/php5/lib/php.ini
  2. 擴展的一些配置都在/usr/local/php5/php.d/目錄下,能夠看到xdebug擴展已經安裝了。
-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
  1. 已經安裝編譯的擴展鏡像在/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

2、安裝nginx

  1. 利用brew神器,brew install nginx
  2. 安裝完畢後,nginx的相關配置在/usr/local/etc/nginx/目錄下,沒有nginx.conf的話,將nginx.conf.default拷貝一份命名爲nginx.conf
  3. 若是80端口衝突的話能夠把mac自帶的apache2的httpd進程殺死,或者在nginx.conf的server部分監聽一個非80端口,好比8080等。
  4. /usr/local/etc/nginx/servers/目錄下是各個域名單獨的配置。

3、安裝mysql、mongodb

mysql和mongodb均可以使用brew來安裝。php

4、Xdebug配置

  1. 前面已經安裝好了Xdebug擴展
  2. 配置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
  1. 執行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
  1. 執行命令殺死php-fpm進程,sudo kill -9 29992 31455 31431 31428

5、配置PHPStorm的Xdebug工具

  1. 打開phpstorm,選擇preferences,找到php下的Debug,配置以下:
    image.png
  2. preferences下找到php下的servers,配置以下:
    image.png
  3. preferences下找到php下的Debug下的DBGp Proxy,配置以下:
    image.png
  4. 增長web debug配置:
    image.png
  5. 配置完畢!打上斷點進行愉快的debug吧~
    image.png

參考連接:

  1. https://www.cnblogs.com/spareribs/archive/2017/06/27/7084828.html
  2. https://blog.csdn.net/ty_hf/article/details/72081965?locationNum=9&fps=1
  3. https://www.tuicool.com/articles/aiE322z
相關文章
相關標籤/搜索