Home  >  Article  >  Backend Development  >  Delete the old php version and install the latest php version and Xdebug under mac system

Delete the old php version and install the latest php version and Xdebug under mac system

不言
不言Original
2018-05-28 17:07:148404browse

The content of this article is about deleting the old php version and installing the latest php version and Xdebug under the mac system. It has a certain reference value. Now I share it with everyone. Friends in need can refer to it

My 2015 macpro system has version php5.6.28 installed by default. I installed php7.0 and php7.1 using brew or other online methods. However, when I print phpinfo(), my php5. It happened again on 6.28. I felt like I had obsessive-compulsive disorder and I had to fix it. I wasted more than a day and tried almost every method on the Internet. However, many of them can only be used for reference and are of little use, because everyone's computer environment may be slightly different. Now that it's done, record it here.

My first step is to delete the php version I see. I plan to delete all php on the computer and then reinstall the latest version. This operation is risky and requires caution. This is what the Internet says: ps: It is not recommended to delete the built-in PHP version because some software may depend on the PHP environment. Although you can self-compile or use brew to install a new version of PHP, it is not recommended for novices. Remember to do it before operating. Use TM to back up the system so that files can be restored after a mistake.

But you don’t have to do this. One more version should be fine. During the deletion process, the executable file php in the user/bin directory cannot be deleted. Although there is a way to delete any file in safe mode on Mac, I did not do it. This file is retained, and there is also php. -config, when you open the file with vi, you can see that the php version is the oldest. I guess this may be the cause.

#When I thought the others were deleted, I used brew to reinstall the php7.1 version. At this time, you will find that this directory issue has become a top priority. Many tutorials and paths on the Internet are no longer available. . Then follow this article.

brew After installing php7.1, there will be a paragraph below:

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 application/x-httpd -php

##

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

This information is very useful, it tells Some methods and installation paths. I only read this information when I was desperate, and realized that I really couldn’t ignore it and couldn’t follow the above tips step by step. You should all be able to understand it, if not you can leave a message. After finishing, don’t forget to restart php-fpm

Let’s talk about the detour I took when restarting npm


There may be two errors when restarting php-fpm, one is that it cannot be found Or open php-fpm. The second is that the error_log cannot be found or opened according to the path.


Solution to the first error

Execute ps aux|grep php-fpm to see php-fpm The process

such as

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
can see that there is a path above. I copied php-fpm.conf under the brew installation path to the above path using the cp command. If you do not delete the old php, there will be a php-fpm.config.default in this path. You can copy this file directly and change it to php-fpm.conf.


The second error is a log problem. Then find the corresponding php-fpm.conf and open it. There is a log in it and the corresponding address. Find the address of the log under mac. Mine is in the /usr/local/var path and is changed to the real address. The default address is wrong.

Then restart fpm, still no problem.

php-fpm --fpm-config /usr/local/etc/php/5.4/php-fpm.conf --prefix /usr/local/var

After executing this sentence, I found that as long as the terminal is not closed, php can be used, but if it is closed, it will hang. . .

What’s better, let’s introduce it first.

brew services start php@7.1 This command

Then I run php -v and php-fpm -v

mengdeMacBook in the terminal -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

At first, my php-v displayed the latest version, but php-fpm still executed the old version. Now the explanation is ok

Open the web page and look at 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 的配置

The above is the detailed content of Delete the old php version and install the latest php version and Xdebug under mac system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn