PHP 7 還未發佈正式版, 只發佈了 RC 1 版本, 但對於 PHP 的開發者, 預先在測試環境安裝好 PHP 7 的環境, 測試程式碼是否可以正常運作也很重要, 這裡會介紹在 RHEL 及 CentOS 安裝 Apache + MariaDB + PHP 7。
安裝 MariaDB
執行以下指令安裝 MariaDB:
# yum install mariadb-server mariadb
啟動及設定開機自動執行 MariaDB:
# systemctl start mariadb
# systemctl enable mariadb
# systemctl enable mariadb
執行以下指令設定 MariaDB 的 root 密碼, 預設是空密碼, 所以建議盡快修改:
# /usr/bin/mysql_secure_installation
完成後可以用測試一下 MariaDB 是否已經啟動:
# mysql -u root -p
安裝 Apache
# yum install httpd
跟著回答 “y” 後便會完成安裝, 然後輸入以下指令啟動及設定 Apache 開機自動執行:
# systemctl start httpd
# systemctl enable httpd
# systemctl enable httpd
這時 Apache 已經啟動了, 可以在瀏覽器輸入伺服器的位置試試, 例如 http://localhost
安裝 PHP 7
在編譯 PHP 前, 先用 YUM 安裝 PHP 相關的套件, 例如 curl, lobjpeg 等, 編譯 PHP 一些常用模組時需要用到這些套件。
# yum install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel libtool-ltdl-devel
然後下載 PHP, 目前最新的 PHP 7 版本為 PHP 7.0.0 RC1:
# cd /usr/local/src
# wget https://downloads.php.net/~ab/php-7.0.0RC1.tar.gz
# mv mirror php-7.0.0RC1.tar.gz
# wget https://downloads.php.net/~ab/php-7.0.0RC1.tar.gz
# mv mirror php-7.0.0RC1.tar.gz
解壓及編譯 PHP:
# tar zxvf php-7.0.0RC1.tar.gz
# cd php-7.0.0RC1
# ./configure –prefix=/usr/local/php7 –with-apxs2 –with-curl –with-mcrypt –enable-mbstring –with-iconv –with-gd –with-jpeg-dir=/usr –enable-pdo –with-pdo-mysql=/usr –with-mysqli=/usr/bin/mysql_config
# make && make install
# cd php-7.0.0RC1
# ./configure –prefix=/usr/local/php7 –with-apxs2 –with-curl –with-mcrypt –enable-mbstring –with-iconv –with-gd –with-jpeg-dir=/usr –enable-pdo –with-pdo-mysql=/usr –with-mysqli=/usr/bin/mysql_config
# make && make install
編譯完成後, 將 PHP 內建的 development 版 php.ini 檔複製到 /usr/local/lib:
# cp php.ini-development /usr/local/lib
然後開啟 Apache 的 httpd.conf:
# vi /etc/httpd/conf/httpd.conf
找到 DirectoryIndex, 加入 index.php, 即這樣:
DirectoryIndex index.html index.htm index.php
然後再加入幾下幾行行:
1 2 3 4 |
LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> |
修改後儲存檔案, 重新啟動 Apache:
# systemctl restart httpd
您好我在安裝PHP 相關的套件時出現
[root@adamantium ~]# yum install libmcrypt
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: http://ftp.ksu.edu.tw
* extras: http://ftp.ksu.edu.tw
* updates: http://ftp.ksu.edu.tw
No package libmcrypt available.
Error: Nothing to do
沒有裝libmcrypt可以嗎?
試試這樣安裝:
安裝 EPEL
# yum -y install epel-release
安裝 php-mcrypt
#yum -y install php-mcrypt
您說的步驟可以成功執行,謝謝您,我再繼續往下做。
對不起,沒有一次問完,libmcrypt-deel也沒有辦法安裝
我剛查了一下,是不是libmcrypt-deel打錯,是要裝libmcrypt-devel啊?
沒聽過 libmcrypt-deel, 應該是 libmcrypt-devel 吧.
恩對是libmcrypt-devel,上面文章有打錯。
請問下載PHP的步驟中
mv mirror php-7.0.0RC1.tar.gz
這行指令是做什麼用的呢?
為什麼要搬移「mirror」至php-7.0.0RC1.tar.gz?
我下載(php-7.0.6.tar.gz)後在/usr/local/src 底下用ls -al沒有看到「mirror」
因為我用 wget 下載 php 時, 下載後的檔案會儲存為 mirror 檔名, 只是用 mv 將 mirror 改名, 如果下後後已經是 php-7.0.6.tar.gz, 那便不需要執行 mv 了.