通过yum安装nginx-mysql-php-fastcgi配置LNMP

时间:2021-01-02 15:06:05

最近指想服务器跑静态文件,所以想单独配置个nginx的webserver,然而并不是我想象的那么简单,使用rpm包来安装会发生很多软件依赖的错误;

当我尝试使用yum安装nginx的时候,总是提示未找到nginx包,最终yum update
解决问题。

安装nginx

yum update

wget
http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/epel-release-5-4.noarch.rpm

wget
http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1-4.ius.el5.noarch.rpm

rpm -Uvh
epel-release*.rpm ius-releas*.rpm

yum -y install nginx

chkconfig nginx on

#chkconfig --levels 235 nginx on

/etc/init.d/nginx start

nginx根目录

/usr/share/nginx/html

由于现在的webserver不可能只是跑静态文件,索性安装了php

yum -y install 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 fastcGI

vi /etc/php.ini

最后添加

cgi.fix_pathinfo = 1

启动php fastcGI守护进程,并以用户组nginx和用户nginx身份运行

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f
/usr/bin/php-cgi -P /var/run/fastcgi-php.pid

开机启动fastcgi

vi /etc/rc.local

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f
/usr/bin/php-cgi -P /var/run/fastcgi-php.pid

修改nginx配置文件,添加fastcgi支持

vi /etc/nginx/nginx.conf

#去掉下面几行的注释

location ~ \.php$ {

***

fastcgi_param  SCRIPT_FILENAME
 $document_root$fastcgi_script_name;

#$document_root:/usr/share/nginx/html

include     
  fastcgi_params;

}

/etc/init.d/nginx restart

安装mysql

yum -y install mysql mysql-server

chkconfig --levels 235 mysqld on

/etc/init.d/mysqld start

设置mysql密码及相关设置

mysql_secure_installation

第一次启动上述命令,根据提示操作,直接回车即可。