◎匯入源碼
X64 (64 bit)
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
i386 (32 bit)
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
Step 1
LNMP 環境 安裝 ( 視需求,不需要可跳過此步驟)
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5* krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
Step 2
移除apache
yum remove httpd
Step2.1
安裝 mysql
yum -y install mysql mysql-server
chkconfig mysqld on
/etc/init.d/mysqld start
Step3
安裝 Nginx
yum -y install nginx
chkconfig nginx on
/etc/init.d/nginx start
※ nainx 預設文件
/etc/nginx/nginx.conf
※ nainx 虛擬主機文件 ( 如同 apache 的虛擬主機配置,也可以併入到 nginx.conf )
※ nginx web_root文件
/usr/share/nginx/html
Step4
安裝 PHP
yum -y install php-pecl-apc php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-mcrypt php-pear-Net-Socket php-pear php-common php-gd php-devel php php-mbstring php-pear-Mail php-cli php-imap php-snmp php-pdo php-xml php-pear-Auth-SASL php-ldap php-pear-Net-SMTP php-mysql php-soap
yum -y install spawn-fcgi memcached net-snmp* (安裝與否視需求)
Step5
下載PHP啟動腳本
wget http://bash.cyberciti.biz/dl/419.sh.zip
unzip 419.sh.zip
mv 419.sh /etc/init.d/php_cgi
chmod +x /etc/init.d/php_cgi
vim /usr/share/nginx/html/info.php (放置在預設路徑)
- <?php
- phpinfo();
- ?>
vim /etc/nginx/nginx.conf
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;
}
vim /etc/php.ini
cgi.fix_pathinfo = 1
chkconfig php_cgi on
/etc/init.d/php_cgi start
※ PHP Reflection extension :
PCER、SPL、DOM、PDO、PDO MySQL、MEMCACHE、MCRYPT、SOAP、GD、CTYPE
※(有安裝memcached snmp 時才需要啟動)
chkconfig memcached on
/etc/init.d/memcached start
chkconifg snmpd on
/etc/init.d/snmpd start
如果想更新 PHP 與 MYSQL
請參閱如何 更新 php 5.4.8+mysql5.5.28+nginx1.2.4 一文
參考處 yum安装nginx构建LNMP服务器(fast-cgi)
Red Hat / CentOS Install nginx PHP5 FastCGI Webserver