如何在Mac中搭建一個(gè)PHP7開(kāi)發(fā)環(huán)境?針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
建立配置
復(fù)制代碼 代碼如下:
./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
這里列出以下我編譯過(guò)程遇到的錯(cuò)誤和解決辦法:
復(fù)制代碼 代碼如下:
configure: error: Cannot locate header file libintl.h
安裝 gettext
復(fù)制代碼 代碼如下:
sudo brew install gettext
編輯 configure 文件,找到 $PHP_GETTEXT /usr/local /usr 在后面加上gettext的路徑
復(fù)制代碼 代碼如下:
$PHP_GETTEXT /usr/local /usr /usr/local/opt/gettext
重新配置即可【后面參數(shù)和上面一樣,這里省略了】
我這里可能是因?yàn)橹熬脱b過(guò)php7 alpha版本,所以錯(cuò)誤會(huì)少一點(diǎn),不過(guò)大家過(guò)程中有什么錯(cuò)誤的話(huà),直接貼出來(lái)大家一起研究了。
編譯
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.inc
Build complete.
Don't forget to run 'make test'.
#
這里會(huì)持續(xù)一段時(shí)間,一般是不會(huì)出現(xiàn)什么錯(cuò)誤的,除非你人品的問(wèn)題了。。。
安裝
復(fù)制代碼 代碼如下:
sudo make install
上面的步驟都順利的話(huà),這一步做起來(lái)就是那么的簡(jiǎn)單了,但是安裝過(guò)程的信息要記得留意一下,后面配置會(huì)需要。。。
命令行測(cè)試
復(fù)制代碼 代碼如下:
/usr/local/php7/bin7 -v
#為了以后事業(yè)方便,直接替換系統(tǒng)默認(rèn)的php命令
#當(dāng)人你也可以備份一下,我這里直接覆蓋算求了。。。
復(fù)制代碼 代碼如下:
sudo cp /usr/local/php7/bin/ph* /usr/bin/
毫無(wú)違和感,運(yùn)行的如此流程,哈哈!
配置apache
打開(kāi)apache的配置文件httpd.conf,找到原來(lái)的LoadModule php5_module這里,直接注釋掉,下面加入LoadModule php7_module /usr/libexec/apache2/libphp7.so,最后如下:
復(fù)制代碼 代碼如下:
sudo vim /etc/apache2/httpd.conf
...
#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php7_module /usr/libexec/apache2/libphp7.so
...
重啟apache,然后測(cè)試一把看看
驚奇的發(fā)現(xiàn),php文件直接輸出到瀏覽器了。。。
感覺(jué)是apache不知道要解析php文件了?。。?/p>
這里我排查了好久,發(fā)現(xiàn)切換成php5版本就沒(méi)問(wèn)題,php7就無(wú)法解析???
最后才發(fā)現(xiàn)apache在解析php的適合是判斷了模塊的,例如ifModule php5_module這樣,在httpd.conf里面找到這一句:Include /private/etc/apache2/other/*.conf,進(jìn)入到該目錄一看,你就明白了...
里面有一個(gè)php5.conf文件,那是不是php7的就該對(duì)應(yīng)一個(gè)php7的文件呢,于是趕緊復(fù)制一份,打開(kāi)這個(gè)文件,看到類(lèi)似php5_module的字樣,直接替換成php7_module即可,相關(guān)內(nèi)容如下:
#httpd.conf改動(dòng) ... <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內(nèi)容 <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,測(cè)試一下
復(fù)制代碼 代碼如下:
sudo apachectl restart
久違的畫(huà)面出現(xiàn)了。。。
關(guān)于如何在Mac中搭建一個(gè)PHP7開(kāi)發(fā)環(huán)境問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
當(dāng)前名稱(chēng):如何在Mac中搭建一個(gè)PHP7開(kāi)發(fā)環(huán)境-創(chuàng)新互聯(lián)
文章鏈接:http://chinadenli.net/article46/dgdeeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、電子商務(wù)、網(wǎng)站排名、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容