一、查看一下CentOS版本
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.10 (Final)
二、升級系統
yum -y update
三、安裝gcc、gcc-c++、kernel、apahce、mysql
yum -y install gcc gcc-c++ kernel kernel-devel httpd httpd-devel mysql mysql-server mysql-devel
四、設置系統新的更新源(CentOS默認的更新源安裝的php版本是5.3),並安裝php及php相關擴展
wget http://mirror.webtatic.com/yum/el6/latest.rpm && rpm -Uvh latest.rpm && yum -y install php55w php55w-bcmath php55w-cli php55w-common php55w-devel php55w-fpm php55w-gd php55w-imap php55w-ldap php55w-mbstring php55w-mcrypt php55w-mysql php55w-odbc php55w-pdo php55w-pear php55w-pecl-igbinary php55w-xml php55w-xmlrpc php55w-opcache php55w-intl php55w-pecl-memcache php55w-soap
1、如果這步安裝報錯提示:
錯誤:Package: php55w-mcrypt-5.5.38-1.w6.x86_64 (webtatic)
Requires: libmcrypt.so.4()(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
a、32位系統下載:
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
b、64位系統下載:
http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
2、安裝
rpm -ivh epel-release-6-8.noarch.rpm
3、導入key
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
4、再次安裝php及其相關擴展
yum -y install php55w php55w-bcmath php55w-cli php55w-common php55w-devel php55w-fpm php55w-gd php55w-imap php55w-ldap php55w-mbstring php55w-mcrypt php55w-mysql php55w-odbc php55w-pdo php55w-pear php55w-pecl-igbinary php55w-xml php55w-xmlrpc php55w-opcache php55w-intl php55w-pecl-memcache php55w-soap
五、啓動apache和查詢php版本
[root@localhost ~]# service httpd start && php -v
正在啓動 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[確定]
PHP 5.5.38 (cli) (built: Jul 21 2016 12:51:12)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
六、刪除剛纔下載的兩個安裝包
rm -rf epel-release-6-8.noarch.rpm latest.rpm
七、創建php文件並查看phpinfo,並保存
vim /var/www/html/phpinfo.php
<?php
phpinfo();
?>
八、訪問http://www.test.com/phpinfo.php如圖,phpinfo頁面