在Mac中如何安装PHP7

来源:互联网 发布:股票行情数据接口 编辑:程序博客网 时间:2024/06/09 17:29

经历了一个漫长的等待,在我们的PHP5.6发布后,我们最新的PHP7终于发布了(等等,我们的6到哪去了?),根据官方的说法,现在的PHP7要比PHP5.6快一倍,那么我们如果要尝鲜,怎么去体验呢?
其实我们有好几种方法来安装。
第一种,我们可以去官网上下源码去编译,这个就不多说了。
第二种,我们可以使用我们的第三方包来安装,比如说homebrew。本文就会讲述如何使用这种方法安装。

安装方法

  1. 首先我们需要安装Homebrew
  2. 通过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 unlink php56

    $ brew install php70 --with-httpd24

    //删掉以前安装的PHP5.6,必须加--with-httpd24 不然不会有libphp7.so文件 //你可以根据自己的情况来修改 $ 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
  3. $ brew info php70//出现信息放在附录里,仔细阅读

    3.配置Apache 

    $ sudo vim /etc/apache2/httpd.conf找到这行注释掉(大概在168行)#Comment out the PHP5 module   #LoadModule php5_module libexec/apache2/libphp5.so找到这行并注释掉(大概在最后一行)#Include /private/etc/apache2/other/*.conf 
    LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
     
        <FilesMatch .php$>
          SetHandler application/x-httpd-php
        </FilesMatch>
     
        <IfModule php7_module>
          AddType application/x-httpd-php .php
          AddType application/x-httpd-php-source .phps
          <IfModule dir_module>
            DirectoryIndex index.html index.php
          </IfModule>
        </IfModule>
  4. 重启Apache
     sudo apachectl restart
  5. 到你的Apache的默认目录/Library/WebServer/Documents下面去增加一个info.php的文件。
     <?php     phpinfo();     ?>


最后到你的 http://localhost/info.php 去看看测试以下,如果看到相关的信息,就说明已经安装好了。

附录:



########brew info php70 命令后的信息###########
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
 
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
 
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
 
The php.ini file can be found in:
/usr/local/etc/php/7.0/php.ini
 
✩✩✩✩ Extensions ✩✩✩✩
 
If you are having issues with custom extension compiling, ensure that
you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
 
PATH="/usr/local/bin:$PATH"
 
PHP70 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.
 
✩✩✩✩ PHP CLI ✩✩✩✩
 
If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell's equivalent configuration file:
 
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
 
GMP has moved to its own formula, please install it by running: brew install php70-gmp
 
✩✩✩✩ FPM ✩✩✩✩
 
To launch php-fpm on startup:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
 
The control script is located at /usr/local/opt/php70/sbin/php70-fpm
 
OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
 
PATH="/usr/local/sbin:$PATH"
 
You may also need to edit the plist to use the correct "UserName".
 
Please note that the plist was called 'homebrew-php.josegonzalez.php70.plist' in old versions
of this formula.
 
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system
you have to install php with the --with-apache option. See brew options php70 for more details.
 
To have launchd start josegonzalez/php/php70 now and restart at login:
brew services start josegonzalez/php/php70
 
 ########brew info php70 命令后的信息###########



########brew info php70 命令后的信息###########
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
 
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
 
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
 
The php.ini file can be found in:
/usr/local/etc/php/7.0/php.ini
 
✩✩✩✩ Extensions ✩✩✩✩
 
If you are having issues with custom extension compiling, ensure that
you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
 
PATH="/usr/local/bin:$PATH"
 
PHP70 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.
 
✩✩✩✩ PHP CLI ✩✩✩✩
 
If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell's equivalent configuration file:
 
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
 
GMP has moved to its own formula, please install it by running: brew install php70-gmp
 
✩✩✩✩ FPM ✩✩✩✩
 
To launch php-fpm on startup:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
 
The control script is located at /usr/local/opt/php70/sbin/php70-fpm
 
OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
 
PATH="/usr/local/sbin:$PATH"
 
You may also need to edit the plist to use the correct "UserName".
 
Please note that the plist was called 'homebrew-php.josegonzalez.php70.plist' in old versions
of this formula.
 
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system
you have to install php with the --with-apache option. See brew options php70 for more details.
 
To have launchd start josegonzalez/php/php70 now and restart at login:
brew services start josegonzalez/php/php70
 
 ########brew info php70 命令后的信息###########


########brew info php70 命令后的信息###########
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
 
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
 
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
 
The php.ini file can be found in:
/usr/local/etc/php/7.0/php.ini
 
✩✩✩✩ Extensions ✩✩✩✩
 
If you are having issues with custom extension compiling, ensure that
you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
 
PATH="/usr/local/bin:$PATH"
 
PHP70 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.
 
✩✩✩✩ PHP CLI ✩✩✩✩
 
If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell's equivalent configuration file:
 
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
 
GMP has moved to its own formula, please install it by running: brew install php70-gmp
 
✩✩✩✩ FPM ✩✩✩✩
 
To launch php-fpm on startup:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
 
The control script is located at /usr/local/opt/php70/sbin/php70-fpm
 
OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
 
PATH="/usr/local/sbin:$PATH"
 
You may also need to edit the plist to use the correct "UserName".
 
Please note that the plist was called 'homebrew-php.josegonzalez.php70.plist' in old versions
of this formula.
 
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system
you have to install php with the --with-apache option. See brew options php70 for more details.
 
To have launchd start josegonzalez/php/php70 now and restart at login:
brew services start josegonzalez/php/php70
 
 ########brew info php70 命令后的信息###########




原创粉丝点击