`
alvin.zane
  • 浏览: 12002 次
社区版块
存档分类
最新评论

RHEL / CentOS 安裝 PHP 7, Apache, MariaDB

 
阅读更多

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:

# yum install mariadb-server mariadb

啟動及設定開機自動執行 MariaDB:

# systemctl start 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

這時 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-deel 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

解壓及編譯 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

編譯完成後, 將 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

然後再加入幾下幾行行:

修改後儲存檔案, 重新啟動 Apache:

# systemctl restart httpd
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics