2013年1月8日火曜日

CentOS上yum安装Nginx服务


CentOS上yum安装Nginx服务

一、更改yum源为网易的源加快速度

vi /etc/yum.repos.d/CentOS-Base.repo
更改内容如下
 
[plain] view plaincopy
  1. # CentOS-Base.repo   
  2. #   
  3. # This file uses a new mirrorlist system developed by Lance Davis for CentOS.   
  4. # The mirror system uses the connecting IP address of the client and the   
  5.   
  6.    
  7.   
  8.    
  9.   
  10.    
  11.   
  12. # update status of each mirror to pick mirrors that are updated to and   
  13. # geographically close to the client. You should use this for CentOS updates   
  14. # unless you are manually picking other mirrors.   
  15. #   
  16. # If the mirrorlist= does not work for you, as a fall back you can try the   
  17. # remarked out baseurl= line instead.   
  18. #   
  19. #   
  20.     
  21. [base]   
  22. name=CentOS-$releasever - Base   
  23. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os  
  24. #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/   
  25. baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/   
  26. gpgcheck=1   
  27. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5   
  28.     
  29. #released updates   
  30. [updates]   
  31. name=CentOS-$releasever - Updates   
  32. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates  
  33. #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/   
  34. baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/   
  35. gpgcheck=1   
  36. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5   
  37.     
  38. #packages used/produced in the build but not released   
  39. [addons]   
  40. name=CentOS-$releasever - Addons   
  41. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons  
  42. #baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/   
  43. baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/   
  44. gpgcheck=1   
  45. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5   
  46.     
  47. #additional packages that may be useful   
  48. [extras]   
  49. name=CentOS-$releasever - Extras   
  50. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras  
  51. #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/   
  52. baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/   
  53. gpgcheck=1   
  54. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5   
  55.     
  56. #additional packages that extend functionality of existing packages   
  57. [centosplus]   
  58. name=CentOS-$releasever - Plus   
  59. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus  
  60. #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/   
  61. baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/   
  62. gpgcheck=1   
  63. enabled=0   
  64. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5  

 

二、update yum

yum -y update

三、利用CentOS Linux系统自带的yum命令安装、升级所需的程序库

安装依赖包
#yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
下载nginx
#wget http://www.nginx.org/download/nginx-1.0.9.tar.gz
#tar zxvf nginx-1.0.9.tar.gz
#cd nginx-1.0.9
配置安装:
#./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
#make
#make install
建立用户:
#/usr/sbin/groupadd nginx
#/usr/sbin/useradd -g nginx -M nginx
#mkdir -p /var/tmp/nginx/client
启动nginx
#/usr/sbin/nginx

四、安装php和mysql

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

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

rpm -Uvh http://download.Fedora.RedHat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum -y install nginx

设置开机启动

chkconfig nginx on

六、安装spawn-fcgi来运行php-cgi
 
yum install spawn-fcgi

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

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

启动php_cgi

/etc/init.d/php_cgi start

查看进程

netstat -tulpn | grep :9000

若出现如下代表一切正常

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

八、配置nginx(详细配置见nginx.conf详细说明)

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;
include fastcgi_params;
}

九、查看phpinfo
编写脚本
 tpo/
phpinfo();

十、安装phpmyadmin
修改/var/lib/php/session的权限和nginx和php_cgi一致

chown -R www.www /var/lib/php/session







安装依赖包
#yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
下载nginx
#wget http://www.nginx.org/download/nginx-1.0.9.tar.gz
#tar zxvf nginx-1.0.9.tar.gz
#cd nginx-1.0.9
配置安装:
#./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
#make
#make install
建立用户:
#/usr/sbin/groupadd nginx
#/usr/sbin/useradd -g nginx -M nginx
#mkdir -p /var/tmp/nginx/client
启动nginx
#/usr/sbin/nginx

0 件のコメント:

コメントを投稿