且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CentOS 5.5-yum安装配置LNMP

更新时间:2021-09-24 14:32:59

Centos 5.5-yum安装配置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

二、安装php和mysql

yum -y install php mysql mysql-server mysql-devel php-mysql php-cgi php-mbstring php-gd php-fastcgi

service mysqld start        //启动mysql服务
chkconfig mysqld on      //设置开机自动启动

三、安装nginx,由于centos没有默认的nginx软件包,需要启用REHL的附件包

   1. rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
   2. yum -y install nginx

 chkconfig nginx on   //设置开机启动
 service nginx start    //启动ngin服务

四、安装spawn-fcgi来运行php-cgi   //spawn-fcgi是用来调用php提供动态php格式的网页

 yum install spawn-fcgi

五、下载spawn-fcgi 的启动脚本

   1. wget http://bash.cyberciti.biz/dl/419.sh.zip  //这是别人写好的脚本,直接拿来用
   2. unzip 419.sh.zip
   3. mv 419.sh /etc/init.d/php_cgi
   4. chmod +x /etc/init.d/php_cgi

 /etc/init.d/php_cgi start    //启动php_cgi
 

1. netstat -tulpn | grep :9000    //查看进程,查看服务有没有正常启动,若出现如下代表一切正常

 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4352/php-cgi

六、配置nginx
vim /etc/nginx/nginx.conf      //下面就是修改nginx.conf配置文件

user nginx                           //修改ngin守护进程的用户
worker_processes  4;         //工作进程数,一般与 CPU 核数等同,但实际的可以多一些
error_log logs/error.log;       //错误日志位置


events {
    worker_connections  2048;#每个工作进程允许最大的同时连接数,可以稍微大一些,1024的倍数
}


gzip  on;
server {
        listen       80;
        server_name  192.168.175.208;  //nginx服务器地址

 

 location ~ \.php$ {
 root html;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;   //这里SCRIPT_FILENAME后面指定的是nginx的网站目录
 include fastcgi_params;
}
把前面注释全部去掉,找到

  location / {
             root   /html;
             index  index.php index.html index.htm;
         }

修改为如上所示 主要是添加index  后面的index.php
七、编写脚本,测试nginx与php有没有结合
vim /usr/share/nginx/html/index.php

<?php
phpinfo
?>

最后通过浏览器访问服务器测试是否成功,出现php信息页面表示成功。


下面是我工作过程中遇到的一个问题。原来服务器上安装的有apache服务器。但是现在要把图片服务器换成nginx,图片服务器里面网页跳转的就不管用的。查找资料发现apache的rewrite规则需要转换成nginx识别的规则才行,通过下面的网页转换后,在nginx.conf中添加

http://www.anilcetin.com/convert-apache-htaccess-to-nginx/    //先转换原来的.htpaccess

 然后在nginx.conf 中的server里添加这行内容,指定你的htaccess所在的位置

include /var/www/html/webshop/web/.htaccess;    




本文转自 张玉坡 51CTO博客,原文链接:http://blog.51cto.com/fighter/589017