首先你得去官網下載php7 beta1的版本
這里由于我是在mac上安裝,所以就去下載linux相關的版本,地址也直接附上了
php7 beta1
windows版的官方也有發布詳情猛戳:這里
解壓安裝包,進入源代碼目錄
tar -zxvf php-7.0.0beta1.tar.gz cd php-7.0.0beta1
建立配置
./buildconf --force ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/sbin/apxs --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
這里列出以下我編譯過程遇到的錯誤和解決辦法:
-
configure: error: Cannot locate header file libintl.h
安裝 gettext
sudo brew install gettext
編輯 configure 文件,找到 $PHP_GETTEXT /usr/local /usr 在后面加上gettext的路徑 $PHP_GETTEXT /usr/local /usr /usr/local/opt/gettext
重新配置即可【后面參數和上面一樣,這里省略了】
-
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
sudo brew install mcrypt libmcrypt
再次重新configure即可。。。
我這里可能是因為之前就裝過php7 alpha版本,所以錯誤會少一點,不過大家過程中有什么錯誤的話,直接貼出來大家一起研究了。
編譯
make#
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
directorygraphiterator.inc
directorytreeiterator.inc
invertedregexiterator.inc
pharcommand.inc
phar.incBuild complete.
Don't forget to run 'make test'. #
這里會持續一段時間,一般是不會出現什么錯誤的,除非你人品的問題了。。。
安裝
sudo make install
上面的步驟都順利的話,這一步做起來就是那么的簡單了,但是安裝過程的信息要記得留意一下,后面配置會需要。。。
命令行測試
/usr/local/php7/bin7 -v#為了以后事業方便,直接替換系統默認的php命令
#當人你也可以備份一下,我這里直接覆蓋算求了。。。
sudo cp /usr/local/php7/bin/ph* /usr/bin/
毫無違和感,運行的如此流暢,哈哈!
配置apache
打開apache的配置文件httpd.conf
,找到原來的LoadModule php5_module
這里,直接注釋掉,下面加入LoadModule php7_module /usr/libexec/apache2/libphp7.so
,最后如下:
sudo vim /etc/apache2/httpd.conf...
#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php7_module /usr/libexec/apache2/libphp7.so
...
重啟apache,然后測試一把看看
驚奇的發現,php文件直接輸出到瀏覽器了。。。
感覺是apache不知道要解析php文件了!!!
這里我排查了好久,發現切換成php5版本就沒問題,php7就無法解析???
最后才發現apache在解析php的適合是判斷了模塊的,例如ifModule php5_module
這樣,在httpd.conf里面找到這一句:Include /private/etc/apache2/other/*.conf
,進入到該目錄一看,你就明白了...
里面有一個php5.conf文件,那是不是php7的就該對應一個php7的文件呢,于是趕緊復制一份,打開這個文件,看到類似php5_module
的字樣,直接替換成php7_module
即可,相關內容如下:
#httpd.conf改動
...
<IfModule php5_module>
Include /private/etc/apache2/other/php5.conf
</IfModule><IfModule php7_module>
Include /private/etc/apache2/other/php7.conf
</IfModule> #Include /private/etc/apache2/other/*.conf ... #php7.conf內容 <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>
最后再次重啟apache,測試一下
sudo apachectl restart
久違的畫面出現了。。。