一:編譯PHP並與nginx整合 【yum安裝方式】
yum搭建lnmp環境(CentOS6.4)
1.關閉防火牆
[root
@CentOS ~]# chkconfig iptables off
2.關閉selinux
vi /etc/sysconfig/selinux
//將SELINUX=enforcing修改成disabled而後重啓生效
三、配置CentOS 6.0 第三方yum源(CentOS默認的標準源裏沒有nginx軟件包)
[root
@CentOS ~]# yum install wget
//下載wget工具
[root
@CentOS ~]# wget http://www.atomicorp.com/installers/atomic
//下載atomic yum源
[root
@CentOS ~]# sh ./atomic
//安裝提示輸入時輸yes
[root
@CentOS ~]# yum check-update //更新yum軟件包 4.安裝開發包和庫文件 [root@CentOS ~]# 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 5.卸載已安裝的apache、mysql、php [root@CentOS ~]# yum remove httpd [root@CentOS ~]# yum remove mysql [root@CentOS ~]# yum remove php 6.安裝nginx [root@CentOS ~]# yum install nginx [root@CentOS ~]# service nginx start [root@CentOS ~]# chkconfig --levels 235 nginx on //設二、三、5級別開機啓動 7.安裝mysql [root@CentOS ~]# yum install mysql mysql-server mysql-devel [root@CentOS ~]# service mysqld start [root@CentOS ~]# chkconfig --levels 235 mysqld on [root@CentOS ~]# mysqladmin -u root password "123456" //爲root用戶設置密碼 [root@CentOS ~]# service mysqld restart //重啓mysql 8.安裝php [root@CentOS ~]# yum install php lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap \ php-odbc php-pear php-xml \ php-xmlrpc php-mbstring php-mcrypt \ php-mssql php-snmp php-soap \ php-tidy php-common \ php-devel php-fpm //安裝php和所需組件使PHP支持MySQL、FastCGI模式 [root@CentOS ~]# service php-fpm start [root@CentOS ~]# chkconfig --levels 235 php-fpm on 9.配置nginx支持php [root@CentOS ~]# mv /etc/nginx/nginx.conf /etc/nginx/nginx.confbak //將配置文件改成備份文件 [root@CentOS ~]# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf //因爲原配置文件要本身去寫所以能夠使用默認的配置文件做爲配置文件 //修改nginx配置文件,添加fastcgi支持 [root@CentOS ~]# 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 [root@CentOS ~]# vi /etc/php.ini 11.重啓nginx php-fpm [root@CentOS ~]# service nginx restart [root@CentOS ~]# service php-fpm restart 12.創建info.php文件 [root@CentOS ~]# vi /usr/share/nginx/html/info.php <?php phpinfo(); ?> 13.測試nginx是否解析php 輸入:192.168.1.105/info.php 顯示php界面說明解析成功