search
HomeBackend DevelopmentPHP TutorialDelete the old php version and install the latest php version and Xdebug under mac system

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
PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP: The Foundation of Many WebsitesPHP: The Foundation of Many WebsitesApr 13, 2025 am 12:07 AM

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

Beyond the Hype: Assessing PHP's Role TodayBeyond the Hype: Assessing PHP's Role TodayApr 12, 2025 am 12:17 AM

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

What are Weak References in PHP and when are they useful?What are Weak References in PHP and when are they useful?Apr 12, 2025 am 12:13 AM

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

Explain the __invoke magic method in PHP.Explain the __invoke magic method in PHP.Apr 12, 2025 am 12:07 AM

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools