http://www.phpini.com/php/rhel-centos-install-php-7-apache-mariadb
http://www.dingguofeng.com/?p=1741
PHP 7 還未發佈正式版, 只發佈了 RC 1 版本, 但對於 PHP 的開發者, 預先在測試環境安裝好 PHP 7 的環境, 測試程式碼是否可以正常運作也很重要, 這裡會介紹在 RHEL 及 CentOS 安裝 Apache + MariaDB + PHP 7。
安裝 MariaDB
執行以下指令安裝 MariaDB:
啟動及設定開機自動執行 MariaDB:
# systemctl enable mariadb
執行以下指令設定 MariaDB 的 root 密碼, 預設是空密碼, 所以建議盡快修改:
完成後可以用測試一下 MariaDB 是否已經啟動:
安裝 Apache
跟著回答 “y” 後便會完成安裝, 然後輸入以下指令啟動及設定 Apache 開機自動執行:
# systemctl enable httpd
這時 Apache 已經啟動了, 可以在瀏覽器輸入伺服器的位置試試, 例如 http://localhost
安裝 PHP 7
在編譯 PHP 前, 先用 YUM 安裝 PHP 相關的套件, 例如 curl, lobjpeg 等, 編譯 PHP 一些常用模組時需要用到這些套件。
然後下載 PHP, 目前最新的 PHP 7 版本為 PHP 7.0.0 RC1:
# wget https://downloads.php.net/~ab/php-7.0.0RC1.tar.gz
# mv mirror php-7.0.0RC1.tar.gz
解壓及編譯 PHP:
# 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:
然後開啟 Apache 的 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: