1. 程式人生 > >centos搭建php+php-fpm環境

centos搭建php+php-fpm環境

親測搭建centos6好使,centos7還沒測試,有用的什麼問題的可以反饋
1:檢視環境:

[[email protected] html]# cat /etc/redhat-release

CentOS release 6.5 (Final)

2:關掉防火牆

[[email protected] html]# chkconfig iptables off

3:配置CentOS 6.0 第三方yum源(CentOS預設的標準源裡沒有nginx軟體包)
CentOs 5.x

rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm 

CentOs 6.x

rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm 

CentOs 7.X

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm 
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#wget http://www.atomicorp.com/installers/atomic
#sh ./atomic
#yum check-update

4:安裝開發包和庫檔案

#yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel libevent2 libevent2-devel

5:解除安裝已安裝的apache、mysql、php

#yum remove httpd
#yum remove mysql
#yum remove php

6:安裝nginx

# yum install nginx -y
# service nginx start
# chkconfig --levels 235 nginx on //設2、3、5級別開機啟動

7:安裝mysql

# yum install mysql mysql-server mysql-devel -y
# service mysqld start
# chkconfig --levels 235 mysqld on

登陸MySQL刪除空使用者,修改root密碼

mysql>select user,host,password from mysql.user;

mysql>drop user ''@localhost;

mysql>update mysql.user set password = PASSWORD('K8gP0ZGOh') where user='root';

mysql>flush privileges;

8:安裝php

# yum -y install php56w lighttpd-fastcgi php56w-cli php56w-mysql php56w-gd php56w-imap php56w-ldap php56w-odbc php56w-pear php56w-xml php56w-xmlrpc php56w-mbstring php56w-mcrypt php56w-mssql php56w-snmp php56w-soap php56w-pecl-redis php56w-tidy php56w-common php56w-devel php56w-fpm php56w-mysql

#pecl install event

當出現 include libevent OpenSSL support [yes]: 的時候輸入 NO 回車

# service php-fpm start
# chkconfig --levels 235 php-fpm on

9:配置nginx支援php

# mv /etc/nginx/nginx.conf /etc/nginx/nginx.confbak

//將配置檔案改為備份檔案

# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf

//由於原配置檔案要自己去寫因此可以使用預設的配置檔案作為配置檔案

//修改nginx配置檔案,新增fastcgi支援

# vi /etc/nginx/nginx.conf

index index.php index.html index.htm;
//加入index.php

location ~ .php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

//將以上程式碼註釋去掉,並修改成nginx預設路徑

10:配置php

// 編輯檔案php.ini,在檔案末尾新增cgi.fix_pathinfo = 1

[[email protected] ~]# vi /etc/php.ini

11:重啟nginx php-fpm

#service nginx restart
#service php-fpm restart  

12:建立info.php檔案

#vi /usr/share/nginx/html/info.php
<?php phpinfo(); ?>

13:測試nginx是否解析php

本地瀏覽器輸入:192.168.1.1/info.php
顯示php介面 環境搭建成功