1. 程式人生 > >Centos6.9 yum安裝apache+php7

Centos6.9 yum安裝apache+php7

一、 環境

Linux作業系統: centos6.9

Apache版本: Apache2.2

 

二、 安裝步驟

1、 檢查系統上是否有舊版本的apache

[[email protected]_0_11_centos ~]# rpm -qa httpd

      如果有舊版本就執行解除安裝

[[email protected]_0_11_centos ~]# rpm -e httpd

2、 檢視yum上的apache版本

[[email protected]_0_11_centos ~]# yum list httpd
Loaded plugins: fastestmirror, priorities, security
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * webtatic: uk.repo.webtatic.com
Available Packages
httpd.x86_64                                                2.2.15-69.el6.centos   

3、 安裝apache2.2

[[email protected]_0_11_centos ~]# yum install httpd

4、 啟動apache(預設埠為80)

[[email protected]_0_11_centos httpd]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]

5、 訪問apache

6、 apahce 主要配置目錄

[[email protected]_0_11_centos httpd]# cd /etc/httpd/

7、 伺服器預設部署根目錄

[[email protected]_0_11_centos httpd]# cd /var/www/html/

8、 設定開機自動啟動

[[email protected]_0_11_centos html]# chkconfig --add httpd

9、 監聽埠修改(預設 80)

[[email protected]_0_11_centos ~]# vi /etc/httpd/conf/httpd.conf

  

三、支援php

1、 安裝php7環境

先解除安裝掉舊版本的php,檢視系統上所有的關於php的安裝包

[[email protected]_0_11_centos httpd]# rpm -qa|grep php 
php71w-common-7.1.18-1.w6.x86_64
php71w-cli-7.1.18-1.w6.x86_64
php71w-pdo-7.1.18-1.w6.x86_64
php71w-gd-7.1.18-1.w6.x86_64
php71w-mbstring-7.1.18-1.w6.x86_64
php71w-mcrypt-7.1.18-1.w6.x86_64
php71w-ldap-7.1.18-1.w6.x86_64
php71w-mysql-7.1.18-1.w6.x86_64
php71w-fpm-7.1.18-1.w6.x86_64

    按順序解除安裝

[[email protected]_0_11_centos httpd]# rpm -e php71w-mysql-7.1.18-1.w6.x86_64
[[email protected]_0_11_centos httpd]# rpm -e php71w-pdo-7.1.18-1.w6.x86_64
[[email protected]_0_11_centos httpd]# rpm -e php71w-cli-7.1.18-1.w6.x86_64
[[email protected]_0_11_centos httpd]# rpm -e php71w-gd-7.1.18-1.w6.x86_64
[[email protected]_0_11_centos httpd]# rpm -e php71w-mcrypt-7.1.18-1.w6.x86_64
[[email protected]_0_11_centos httpd]# rpm -e php71w-mbstring-7.1.18-1.w6.x86_64
[[email protected]_0_11_centos httpd]# rpm -e php71w-ldap-7.1.18-1.w6.x86_64
[[email protected]_0_11_centos httpd]# rpm -e php71w-fpm-7.1.18-1.w6.x86_64
[[email protected]_0_11_centos httpd]# rpm -e php71w-common-7.1.18-1.w6.x86_64

查詢是否解除安裝乾淨

[[email protected]_0_11_centos httpd]# php -v
-bash: /usr/bin/php: No such file or directory

解除安裝乾淨後,開始安裝php7

  安裝epel-release

[[email protected]_0_11_centos httpd]# yum -y install epel-release

  獲取php7的yum源

[[email protected]_0_11_centos ~]# rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm

  安裝php7

[[email protected]_0_11_centos ~]# yum install php70w

  驗證php是否安裝完成

[[email protected]_0_11_centos ~]# php -v
PHP 7.0.30 (cli) (built: Apr 28 2018 10:41:40) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

 

3、 重啟httpd服務

[[email protected]_0_11_centos httpd]# service httpd restart         
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]

4、 在伺服器根目錄建立index.php

<?php
 phpinfo();
?>

5、 開啟瀏覽器訪問index.php

        ip地址 / index.php

6、 php7的擴充套件

[[email protected]_0_11_centos html]# yum install php70w.x86_64 php70w-bcmath.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-dba.x86_64 php70w-devel.x86_64 php70w-embedded.x86_64 php70w-enchant.x86_64 php70w-fpm.x86_64 php70w-gd.x86_64 php70w-imap.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysqlnd.x86_64 php70w-odbc.x86_64 php70w-opcache.x86_64 php70w-pdo.x86_64 php70w-pdo_dblib.x86_64 php70w-pear.noarch php70w-pecl-apcu.x86_64 php70w-pecl-apcu-devel.x86_64 php70w-pecl-imagick.x86_64 php70w-pecl-imagick-devel.x86_64 php70w-pecl-mongodb.x86_64 php70w-pecl-redis.x86_64 php70w-pecl-xdebug.x86_64 php70w-pgsql.x86_64 php70w-xml.x86_64 php70w-xmlrpc.x86_64 nginx php70w-intl -y
[[email protected]_0_11_centos html]# yum install php70w-mysqlnd.x86_64