Home >Backend Development >PHP7 >How to install php7 on macbook pro

How to install php7 on macbook pro

藏色散人
藏色散人Original
2021-09-18 10:43:203737browse

How to install php7 on macbook pro: 1. Install Homebrew; 2. Install PHP7 through brew and execute commands such as "$ brew install php70"; 3. Configure Apache; 4. Restart Apache.

How to install php7 on macbook pro

The operating environment of this article: macOS10.15 system, php7 version, macbook pro 2020 computer

How to install php7 on macbook pro?

Mac installation PHP7:

After a long wait, after our PHP5.6 was released, our latest PHP7 was finally released (waiting Wait, where is our 6?), according to the official statement, the current PHP7 is twice as fast as PHP5.6, so if we want to try it out, how can we experience it?

In fact, we have several ways to install it.

First, we can go to the official website and download the source code to compile it, so I won’t go into details about this.

Second, we can use our third-party package to install, such as homebrew. This article will describe how to install using this method.

Installation method

First we need to install Homebrew

Install through brew:

$ brew tap homebrew/dupes  
$ brew tap homebrew/versions  
$ brew tap homebrew/homebrew-php  
   
// 创建目录 
sudo mkdir /usr/local/var
sudo chmod 777 /usr/local/var 
//修改成你自己的用户名和组
sudo chown -R <username>:<group> /usr/local/sbin   
sudo mkdir /usr/local/sbin/
//安装PHP7  
$ brew install php70  
//删掉以前安装的PHP5.6  
//你可以根据自己的情况来修改  
$ brew unlink php56
$ brew link php70
//大功告成
$ php -v
PHP 7.0.0 (cli) (built: Dec  2 2015 13:06:23) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

Configure Apache

$ sudo vim /etc/apache2/httpd.conf

Find this line and comment it out (about line 168)

#Comment out the PHP5 module   
#LoadModule php5_module libexec/apache2/libphp5.so
#Enable PHP 7 module  
LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so  <FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

Restart Apache

sudo apachectl restart

Go to your Apache’s default directory/Library/WebServer/Documents and add an info.php document.

<?php    
phpinfo();    
?>

Finally go to your http://localhost/info.php to see the test below. If you see relevant information, it means it has been installed.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to install php7 on macbook pro. 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