CentOS 6.5安裝php-7.0.32+apache-2.2.15

Linux下安裝php環境並且配置Nginx支持php-fpm模塊
Linux環境安裝PHP7
查看Linux 、Apache 、 MySQL 、 PHP 版本的方法
Linux下PHP開發環境搭建(Apache2.4+PHP7.1+MySQL5.7)
添加php-fpm系統服務


1、安裝

  • find apache的apxs配置文件
/usr/sbin/apxs

安裝apache
yum -y install  httpd

開啓
service httpd start

關閉
pkill -9 httpd

apache的錯誤日誌
tail -f /etc/httpd/logs/error_log

配置文件
vim /etc/httpd/conf/httpd.conf
  • ./configure
#./configure --prefix=/usr/local/php 
--with-apxs2=/usr/sbin/apxs 
--with-curl 
--with-freetype-dir 
--with-gd 
--with-gettext 
--with-iconv-dir 
--with-kerberos 
--with-libdir=lib64 
--with-libxml-dir 
--with-mysqli 
--with-openssl 
--with-pcre-regex 
--with-pdo-mysql 
--with-pdo-sqlite 
--with-pear 
--with-png-dir 
--with-jpeg-dir 
--with-xmlrpc 
--with-xsl 
--with-zlib 
--with-bz2 
--with-mhash 
--enable-fpm 
--enable-bcmath 
--enable-libxml 
--enable-inline-optimization 
--enable-gd-native-ttf 
--enable-mbregex 
--enable-mbstring 
--enable-opcache 
--enable-pcntl 
--enable-shmop 
--enable-soap 
--enable-sockets 
--enable-sysvsem 
--enable-sysvshm 
--enable-xml 
--enable-zip

# chmod 755 /usr/lib64/httpd/modules/libphp7.so
  • 啓動php-fpm
# /usr/local/php/sbin/php-fpm
# netstat -tunlp |grep 9000  //linux端口占用
  • 文件php.ini的默認路徑
/usr/local/php/lib/php.ini
  • apache配置

安裝 
yum -y install  httpd

開啓
service httpd start

vim /etc/httpd/conf/httpd.conf
service httpd restart

防火牆
vim /etc/sysconfig/iptables
service iptables restart

打印錯誤日誌
tail -f /etc/httpd/logs/error_log

  • 修改80端口
[root@guowei-baidu-cloud init.d]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

解決方法
#ServerName www.example.com:80
ServerName localhost:80
  • 解決端口占用問題
[root@keyog-baidu-cloud conf]# netstat -lnp|grep 81
tcp        0      0 127.0.0.1:9999              0.0.0.0:*                   LISTEN      12814/php server.ph
tcp        0      0 :::781                      :::*                        LISTEN      1409/./bcm-agent
tcp        0      0 :::81                       :::*                        LISTEN      12230/httpd
udp        0      0 fe80::f816:3eff:fee8:452:123 :::*                                    1553/ntpd

[root@keyog-baidu-cloud conf]# pkill -9 httpd
  • 配置apache支持php
[root@iZ2ze2n6ep53tcs3n7df8xZ ~]# find / -name libphp5.so
/usr/lib64/httpd/modules/libphp5.so

修改Apache的配置文件httpd.conf
DirectoryIndex index.html index.php #添加index.php
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
添加如下內容
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php
檢查LoadModule php5_module modules/libphp5.so 是否已經添加 libphp5.so文件是否存在
編寫測試文件index.php內容如下,放到Apache的默認的Web站點目錄DocumentRoot #默認路徑/var/www/html
<?php
phpinfo();
?>
  • 查看php的版本
爲了以後方便,可以編輯 /etc/profile 添加環境變量 ,添加到最後面

vim  /etc/profile
PATH=$PATH:/usr/local/php/bin
export PATH
#source /etc/profile
#php -v
PHP 7.0.32 (cli) (built: Nov  4 2018 11:19:33) ( NTS )
  • 查看php安裝的依賴
#php -m

2、優化

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章