LNMP部署

1.首先安装如下 rpm 包,以满足LNMP 环境需求.

[root@centos1 ~] # rpm -qa libjpeg-devel libpng-devel libtiff-devel  fontconfig-devel freetype-devel libXpm-devel gettext-devel openssl-devel libtool-ltdl-devel
[root@centos1 ~] # yum install libjpeg-devel libpng-devel libtiff-devel  fontconfig-devel freetype-devel libXpm-devel gettext-devel openssl-devel libtool-ltdl-devel
 
[root@centos1 ~] unzip pcre-8.12.zip
[root@centos1 ~] cd pcre-8.12
[root@centos1 ~]. /configure
[root@centos1 ~] make && make install

 

2.编译安装nginx

[root@server lnmp] # useradd nginx
[root@server lnmp] # tar xf nginx-0.8.46.tar.gz
[root@server lnmp] # cd nginx-0.8.46
[root@centos6 nginx-1.0.10] # ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module --with-sha1=/usr/lib
[root@server nginx-0.8.46] # make && make install
 
 

 

 

3.安装mysql依赖包

[root@centos6 mysql-5.1.63] # yum install ncurses ncurses-devel

 

4.安装mysql

[root@server lnmp] tar zxvf mysql-5.1.63. tar .gz -C /usr/src
[root@server lnmp] cd /usr/src/mysql-5 .1.63
[root@centos6 mysql-5.1.63] #./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=all --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-pthread --with-big-tables --without-debug --with-ssl
[root@centos6 mysql-5.1.63] make && make install
[root@centos6 mysql-5.1.63] /usr/local/mysql/bin/mysql_install_db --user=mysql
[root@centos6 mysql-5.1.63] chown -R root.mysql /usr/local/mysql
[root@centos6 mysql-5.1.63] cp support-files /my-medium .cnf /etc/my .cnf
[root@centos6 mysql-5.1.63] cp support-files /mysql .server /etc/init .d /mysqld
[root@centos6 mysql-5.1.63] chmod +x /etc/init .d /mysqld
[root@centos6 mysql-5.1.63]chkconfig --add mysqld
[root@centos6 mysql-5.1.63]chkconfig --level 35 mysqld on
[root@centos6 mysql-5.1.63]service mysqld start
 
 

 

 

3.安装PHP依赖包

下载:

wget http: //cn .php.net /distributions/php-5 .3.16. tar .gz
 
wget http: //google-desktop-for-linux-mirror .googlecode.com /files/gd-2 .0.35. tar .gz
wget http: //ftp .gnu.org /gnu/libiconv/libiconv-1 .14. tar .gz
wget http: //sourceforge .net /projects/mcrypt/files/Libmcrypt/2 .5.8 /libmcrypt-2 .5.8. tar .gz /download
wget http: //www .lighttpd.net /download/spawn-fcgi-1 .6.3. tar .gz
wget https: //github .com /downloads/libevent/libevent/libevent-2 .0.18-stable. tar .gz
wget http: //nchc .dl.sourceforge.net /project/mhash/mhash/0 .9.9.9 /mhash-0 .9.9.9. tar .bz2

安装

[root@centos1 LNMP] # yum install gd2 libiconv libmcrypt mhash  spawn-fcgi libevent libxml2 libxml2-devel curl curl-devel php-gd
 
[root@server lnmp] # tar xf gd-2.0.35.tar.bz2 
[root@server lnmp] # cd gd-2.0.35 
[root@server gd-2.0.35] # ./configure
[root@server gd-2.0.35] # make &&  make install
 
[root@server lnmp] # tar xf libiconv-1.13.1.tar.gz 
[root@server lnmp] # cd libiconv-1.13.1 
[root@server libiconv-1.13.1] # ./configure
[root@server libiconv-1.13.1] # make && make install
 
 
[root@server lnmp] # tar xf libmcrypt-2.5.7.tar.gz 
[root@server lnmp] # cd libmcrypt-2.5.7 
[root@server libmcrypt-2.5.7] # ./configure
[root@server libmcrypt-2.5.7] # make && make install 
 
[root@server lnmp] # tar xf mhash-0.9.9.9.tar.bz2 
[root@server lnmp] # cd mhash-0.9.9.9 
[root@server mhash-0.9.9.9] # ./configure
[root@server mhash-0.9.9.9] # make && make install
 
  [root@server lnmp] # tar xf spawn-fcgi-1.6.3.tar.gz 
  [root@server lnmp] # cd spawn-fcgi-1.6.3 
  [root@server spawn-fcgi-1.6.3] # ./configure --prefix=/usr/local/spawn-fcgi
  [root@server spawn-fcgi-1.6.3] # make && make install
 
 
  [root@server lnmp] # tar xf libevent-1.4.14b-stable.tar.gz 
  [root@server lnmp] # cd libevent-1.4.14b-stable 
  [root@server libevent-1.4.14b-stable] # ./configure
  [root@server libevent-1.4.14b-stable] # make  && make install 
 
 
 
 

 

 

4. 编译安装 php

[root@server lnmp] tar zxvf php-5.4.1. tar .gz -C /usr/src
[root@server lnmp] cd /usr/src/php-5 .4.1
[root@centos1 php-5.4.1] # ./configure --prefix=/usr/local/php --enable-fastcgi --enable-discard-path --enable-force-cgi-redirect --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-gd --with-zlib --with-libxml-dir --with-curl --with-curlwrappers --with-openssl --with-mhash --with-xmlrpc --with-mcrypt --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-gd-native-ttf --enable-ftp --enable-pcntl --enable-sockets --enable-zip --disable-debug --disable-ipv6 --with-pdo-mysql --enable-fpm
[root@centos1 php-5.4.1] # make ZEND_EXTRA_LIBS='-liconv'
[root@centos1 php-5.4.1] # ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
[root@centos1 php-5.4.1] # make install
[root@centos1 php-5.4.1] # cp php.ini-development /usr/local/php/etc/php.ini
 

--enable-fpm   当使用该fastCGI时加入该参数

cp -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so   //如果

报错

checking for mysql_config... /usr/bin/mysql_config is not a directory
configure: error: can not find mysql under the /usr/bin/mysql_config that you specified

处理

[root@yznvm1 php-5.3.8]cp /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config 


# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# vi /usr/local/php/etc/php-fpm.conf 取消以下;分号注释
1 ;pid = run /php-fpm .pid
pm.max_children = 50
2 ;pm.start_servers = 20
3 ;pm.min_spare_servers = 5
4 ;pm.max_spare_servers = 35
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod 755 /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig --levels 2345 php-fpm on
# service php-fpm start


 

 

 

5.整合PHP and nginx

 

[root@centos1 nginx] # vi /usr/local/nginx/conf/nginx.conf
http {
#在http顶部加入
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_intercept_errors on;
proxy_temp_path            /dev/shm/proxy_temp ;
fastcgi_temp_path          /dev/shm/fastcgi_temp ;
client_body_temp_path      /dev/shm/client_body_temp ;
 
.......
 
 
 
server {
#在server下加入
 
...........
 
location  ~ \.php$ {
root           html;
           fastcgi_pass   127.0.0.1:9000;
#fastcgi_pass   spawn;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /scripts $fastcgi_script_name;
#            include        fastcgi_params;
include spawn_php5.conf;
}
 
 
 

 

添加 spawn_php5.conf文件

[root@server  ~] # vi /usr/local/nginx/conf/spawn_php5.conf
fastcgi_param  GATEWAY_INTERFACE  CGI /1 .1; 
fastcgi_param  SERVER_SOFTWARE    nginx; 
fastcgi_param  QUERY_STRING       $query_string; 
fastcgi_param  REQUEST_METHOD     $request_method; 
fastcgi_param  CONTENT_TYPE       $content_type; 
fastcgi_param  CONTENT_LENGTH     $content_length; 
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name; 
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name; 
fastcgi_param  REQUEST_URI        $request_uri; 
fastcgi_param  DOCUMENT_URI       $document_uri; 
fastcgi_param  DOCUMENT_ROOT      $document_root; 
fastcgi_param  SERVER_PROTOCOL    $server_protocol; 
fastcgi_param  REMOTE_ADDR        $remote_addr; 
fastcgi_param  REMOTE_PORT        $remote_port; 
fastcgi_param  SERVER_ADDR        $server_addr; 
fastcgi_param  SERVER_PORT        $server_port; 
fastcgi_param  SERVER_NAME        $server_name;
 
 

 

 

6.配置 spawn-fcgi 启动脚本

[root@server  ~] # vi /usr/local/php/bin/spawn-fcgi
 
#! /bin/sh
set -e
PATH= /usr/local/sbin : /usr/local/bin : /sbin : /bin : /usr/sbin : /usr/bin : /usr/local/spawn-fcgi/bin
DESC= "spawn-fcgi daemon"
NAME=spawn-fcgi
DAEMON= /usr/local/spawn-fcgi/bin/ $NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
$DAEMON -a 127.0.0.1 -p 9000 -C 128 -u nginx -g nginx -f /usr/local/php/bin/php-cgi
> /dev/null 2>&1
$DAEMON -a 127.0.0.1 -p 9001 -C 128 -u nginx -g nginx -f /usr/local/php/bin/php-cgi
> /dev/null 2>&1 || echo -n  " adress already inuse"
}
d_stop() {
/usr/bin/killall -9 php-cgi  > /dev/null 2>&1 || echo -n  " not running"
}
case  "$1" in
start)
echo -n  "Starting $DESC: $NAME"
d_start
echo  "ok"
;;
stop)
echo -n  "Stopping $DESC: $NAME"
d_stop
echo  "ok"
;;
restart)
echo -n  "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
;;
*)
echo  "Usage: $SCRIPTNAME {start|stop|restart}"  >&2
exit 3
;;
esac
exit 0
 
 

 

启动服务

[root@server conf] # chmod  +x /usr/local/php/bin/spawn-fcgi
[root@server  ~] # /usr/local/php/bin/spawn-fcgi start
 
[root@server  ~] # /usr/local/nginx/sbin/nginx -t
 
the configuration file /usr/local/nginx//conf/nginx .conf syntax is ok 
configuration file /usr/local/nginx//conf/nginx .conf test is successful
 
 
 
[root@server  ~] # /usr/local/nginx/sbin/nginx
 
 

 

7.测试

echo "<?php phpinfo(); ?>" > /usr/local/nginx/html/index .php

 

http://127.0.0.1/index.php

返回php安装版本信息,部署成功

你可能感兴趣的:(nginx)