首頁  >  文章  >  後端開發  >  mac 系統下刪除舊的php版本安裝最新的php版本及Xdebug

mac 系統下刪除舊的php版本安裝最新的php版本及Xdebug

不言
不言原創
2018-05-28 17:07:148331瀏覽

這篇文章介紹的內容是關於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

    

        SetHandler appli#        SetHandler appli

#        SetHandlerappli#        SetHandlerappli

#        SetHandlerappli#-httpd# -php

######    ############Finally, check DirectoryIndex includes index.php#######Finally, check DirectoryIndex includes index.php#######

    DirectoryIndex index.php index.html


##php.ini 和php-fpm. ini檔案位於:

    /usr/local/etc/php/7.1/


#此公式僅包含桶,這表示它未符號連結到/usr/local,

因為這是另一個公式的替代版本。


##如果您需要在PATH 中先執行此軟體:

  echo '匯出PATH ="/usr/local/opt/php@7.1/bin:$PATH"'>> ~/.bash_profile

  echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >>> ~/.bash_profile


##為了讓編譯器找到這個軟體,你可能需要設定:

   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-fpm
root     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 www
nobody   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 Zend1, vpy7. 1999-2018, 由 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
卷Zend OPcache v7.1.16, Copyright (c) 1999-2018, 由 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 拿来运行,绝对路径运行就可以执行了。还有官方下载的页面有两级目录,而且名字一样,别弄错了,不然运行不了。

  1. Download xdebug-2.6.0.tgz

  2. Unpack the downloaded file with tar -xvzf xdebug-2.6.0.tgz

  3. Run: cd xdebug-2.6.0

  4. 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:      20160303
    Zend Extension Api No:   320160303

    If it does not, you are using the wrong phpize. Please followthis FAQ entry and skip the next step.

  5. Run: ./configure

  6. Run: make

  7. Run: cp modules/xdebug.so /usr/local/lib/php/pecl/20160303

  8. Edit /usr/local/etc/php/7.1/php.ini and add the line
    zend_extension = /usr/local/lib/php/pecl/20160303/xdebug.so

  9. Restart the webserver

   然后,刷新pathinfo()  ,command+f 查找xdebug


    看到这样就成功了

  然后就是配置xdebug 了

 相关推荐:

Mac上通过docker配置PHP开发环境

Mac apache php 和CGI 的配置

以上是mac 系統下刪除舊的php版本安裝最新的php版本及Xdebug的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn