這篇文章介紹的內容是關於mac 系統下刪除舊的php版本安裝最新的php版本及Xdebug,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下
我的2015版的macpro 系統下預設安裝了php5.6.28的版本,我用brew 或其它網上的方式安裝了php7.0以及php7.1,然而當我列印phpinfo()的時候,我的php5.6.28又出現了,我感覺我有強迫症,我非要搞定它不行,整整浪費了一天多時間,網上的各種方法差不都都試了。然而很多隻能借鑒,用處不大,因為每個人的電腦環境可能略有不同。現在搞定了,這裡記錄一下。
我的第一步是刪除我所看到的php版本,我準備將電腦上的所有php全部刪乾淨,然後重新安裝一個最新的版本。此操作有風險,須謹慎。網上是這樣說的:ps:不建議刪除內建的php版本.因為一些軟體可能依賴於php環境.雖然可以自編譯或使用brew安裝新版本的php,但是不建議新手操作.切記操作前.先使用TM備份下系統.以便失誤後可以還原檔案。
不過你沒必要這麼做。多一個版本應該也沒問題的。刪除過程中,user/bin 目錄下的可執行檔php 無法刪掉,雖然說mac 下有中方式在安全模式下可以刪除任何檔案的操作,但是我沒做,這個檔案保留了,還有個php-config, vi開啟檔案可以看到php版本是最老的,我猜測有可能是這個導致的。
等我覺得其它刪除了,我用brew 重新安裝了php7.1的版本。這時候你會發現這個目錄問題成了頭等問題,網上的很多教程和路徑,現在都沒有了。。 那就跟著這篇文章走吧。
brew 安裝完php7.1,下面會有一段東西:
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.1
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.1/
This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.bash_profile
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/php@7.1/lib
CPPFLAGS: -I/usr/local/opt/php@7.1/include
To have launchd start php@7.1 now and restart at login:
brew services start php@7.1
Or, if you don't want/need a background service you can just run:
php-fpm
這個資訊很都有用,它告訴了你一些方法和安裝路徑。這個資訊我是走投無路的時候才去看的,才發現真的不能忽略,沒辦法按照上面的提示一步一步做。應該都能看懂吧,不能的話可以留言。完了之後別忘記重啟php-fpm
下面說一下我重啟npm走的彎路
重啟php-fpm時有可能會有兩種報錯,一種是無法找到或開啟php-fpm 第二種就是無法按路徑找到或開啟error_log
解決第一個錯誤
執行 ps aux|grep php-fpm 可以看到php-fpm 的進程
如
root 21891 0.0 0.0 112660 960 pts/3 R+ 16:18 0:00 grep --color=auto php-fpmroot 42891 0.0 0.1 182796 1220 ? Ss 4月18 0:19 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)nobody 42892 0.0 0.6 183000 6516 ? S 4月18 0:07 php-fpm: pool wwwnobody 42893 0.0 0.6 183000 6508 ? S 4月18 0:17 php-fpm: pool www
可以看到上面有個路徑,我是將brew 安裝路徑下的php-fpm.conf,用cp命令copy 到上面這個路徑下的。 如果不刪除舊的php的話,這個路徑下會有一個php-fpm.config.default,可以直接copy 這個檔案然後改成php-fpm.conf也可以的。
第二種錯誤是log 的問題,那就找到對應的php-fpm.conf 開啟,裡面有log 以及需要對應的地址,找到mac 下log 的地址。我的在/usr/local/var 路徑下,改成真實的地址,預設的地址是錯誤的。
然後重啟fpm ,依然沒好。
php-fpm --fpm-config /usr/local/etc/php/5.4/php-fpm.conf --prefix /usr/local/var
執行了這句,發現只要終端不關,php 能用,關了,就掛了。。。
咋好的呢,還是開頭優先介紹的。brew services start php@7.1 這句命令
然後我在終端php -v 以及 php-fpm -v
mengdeMacBook-Pro:var GHM$ php-fpm -v
PHP 7.1.16 (fpm-fcgi) (built: Apr 12 2018 03:25:57)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
with Zend OPcache v7.1.16, Copyright (c) 1999-2018, by Zend Technologies
mengdeMacBook-Pro:var GHM$ php -v
PHP 7.1.16 (cli) (built: Apr 12 2018 03:25:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
with Zend OPcache v7.1.16, Copyright (c) 1999-2018, by Zend Technologies
剛開始我的php-v 顯示的是最新的,php-fpm 執行的還是舊的版本。現在說明ok了
再開啟網頁看下phpinfo()
PHP Version 7.1.16
| System |
Darwin mengdeMacBook-Pro.local 16.4.0 Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64 |
| Build Date |
Apr 12 2018 03:24:25 |
| Configure Command |
'./configure' '--prefix=/usr/local/Cellar/php@7.1/7.1.16_1' '--localstatedir=/usr/local/var' '--sysconfdir=/usr/local/etc/php/7.1' '--with-config-file-path=/usr/local/etc/php/7.1' '--with-config-file-scan-dir=/usr/local/etc/php/7.1/conf.d' '--with-pear=/usr/local/Cellar/php@7.1/7.1.16_1/share/php@7.1/pear' '--enable-bcmath' '--enable-calendar' '--enable-dba' '--enable-dtrace' '--enable-exif' '--enable-ftp' '--enable-fpm' '--enable-intl' '--enable-mbregex' '--enable-mbstring' '--enable-mysqlnd' '--enable-opcache-file' '--enable-pcntl' '--enable-phpdbg' '--enable-phpdbg-webhelper' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-wddx' '--enable-zip' '--with-apxs2=/usr/local/opt/httpd/bin/apxs' '--with-bz2' '--with-fpm-user=_www' '--with-fpm-group=_www' '--with-freetype-dir=/usr/local/opt/freetype' '--with-gd' '--with-gettext=/usr/local/opt/gettext' '--with-gmp=/usr/local/opt/gmp' '--with-icu-dir=/usr/local/opt/icu4c' '--with-jpeg-dir=/usr/local/opt/jpeg' '--with-kerberos' '--with-layout=GNU' '--with-ldap' '--with-ldap-sasl' '--with-libedit' '--with-libzip' '--with-mcrypt=/usr/local/opt/mcrypt' '--with-mhash' '--with-mysql-sock=/tmp/mysql.sock' '--with-mysqli=mysqlnd' '--with-ndbm' '--with-openssl=/usr/local/opt/openssl' '--with-pdo-dblib=/usr/local/opt/freetds' '--with-pdo-mysql=mysqlnd' '--with-pdo-odbc=unixODBC,/usr/local/opt/unixodbc' '--with-pdo-pgsql=/usr/local/opt/libpq' '--with-pgsql=/usr/local/opt/libpq' '--with-pic' '--with-png-dir=/usr/local/opt/libpng' '--with-pspell=/usr/local/opt/aspell' '--with-unixODBC=/usr/local/opt/unixodbc' '--with-webp-dir=/usr/local/opt/webp' '--with-xmlrpc' '--with-xsl' '--with-zlib' '--with-curl' |
坑多,兩天了有些我也忘了,誰有遇到問題可以留言。。。
下面說下xdebug 安裝
建議按官方,少走彎路
開啟這個xdebug 官方頁面
然後command+a 全選,command +v 複製,放到框框裡面,運行底部的按鈕,會列印出很多我們安裝xdebug所需要用到的資訊
按步驟走就好了,有一點坑就是,當執行phpsize 的時候報:command cannot find ,這時候找到brew 安裝php 的可執行bin目錄,直接用那個裡面的phpsize 拿來運行,絕對路徑運行就可以執行了。還有官方下載的頁面有兩級目錄,而且名字一樣,別弄錯了,不然運行不了。
Download xdebug-2.6.0.tgz
Unpack the downloaded file with tar -xvzf xdebug-2.6.0.tgz
Run: cd xdebug-2.6.0
Run: phpize (See the FAQ if you don't have phpize.
As part of its output it should show:
Configuring for:...Zend Module Api No: 20160303Zend Extension Api No: 320160303
If it does not, you are using the wrong phpize. Please followthis FAQ entry and skip the next step.
Run: ./configure
Run: make
Run: cp modules/xdebug.so /usr/local/lib/php/pecl/20160303
Edit /usr/local/etc/php/7.1/php.ini and add the line
zend_extension = /usr/local/lib/php/pecl/20160303/xdebug.so
Restart the webserver
然後,重新整理pathinfo() ,command+f 尋找xdebug
看到這樣就成功了
然後就是配置xdebug 了