首页 > 代码库 > lnmp
lnmp
1、下载 [root@ptr123soft]# wget http://nginx.org/download/nginx-1.9.1.tar.gz
2、安装依赖包
安装pcre库是为了使Nginx支持HTTP Rewrite 模块
[root@ptr123 soft]# yum -y install pcre
[root@ptr123 soft]# yum -y install pcre-devel
Gzip用到zlib模块
[root@ptr123 soft]# yum -y install zlib
查看gcc是否安装 gcc -v,如没有,需安装
[root@ptr123 soft]# yum -y install gcc
安装 OpenSSl
[root@ptr123 soft]# yum -y install OpenSSl
3、安装
建立nginx用户和组
useradd www
./configure--prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module
--user=www--group=www
make makeinstall
更改nginx权限
chown www.www nginx -R
4、配置nginx.conf
user www www;
worker_processes 8;
#pid /var/run/nginx.pid;
worker_rlimit_nofile 32768;
events{
worker_connections 32768;
}
http{
# Basic Settings
server_tokens off;
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
keepalive_timeout 75 20;
# no sendfile on OSX
sendfile on;
# These are good default values.
tcp_nopush on;
tcp_nodelay off;
# output compression saves bandwidth
gzip on;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_proxied any;
gzip_min_length 1024;
gzip_buffers 4 8k;
gzip_types text/plainapplication/x-javascript text/css application/xml;
# Cache Setting
proxy_cache_path temp_path/proxy_cache levels=1:2 keys_zone=proxy_cache:10m;
proxy_temp_path temp_path/proxy_temp;
scgi_temp_path temp_path/scgi_temp;
uwsgi_temp_path temp_path/uwsgi_temp;
fastcgi_temp_path temp_path/fastcgi_temp;
client_body_temp_path temp_path/client_body_temp;
# ErrorLog Settings
error_page 404 = /404.html;
error_page 403 = /403.html;
error_page 502 503 504 = /50x.html;
log_format access
‘$remote_addr - $remote_user[$time_local] "$request" ‘
‘$status $body_bytes_sent"$http_referer" ‘
‘"$http_user_agent""$http_x_forwarded_for"‘;
log_format proxy_log
‘$http_x_real_ip - $remote_user[$time_local] "$request" ‘
‘$status $body_bytes_sent"$http_referer" ‘
‘"$http_user_agent"‘;
access_log logs/access.logaccess;
error_log logs/error.log;
# access_log /dev/null;
# error_log /dev/null crit;
upstream phpserver {
server 127.0.0.1:9000;
}
# Extra Configurations
include Configs/deny-ip.conf;
include Includes/Default.cfg;
include Includes/*.conf;
}
5、配置deny-ip.conf;
#deny 218.240.150.7;
#deny 221.194.136.19; # Qihoo bot
deny 61.160.23.204;
deny 124.228.21.0/24;
allow all;
6、配置Default.cfg
#Default Server Settings
server{
server_name www.hostzu.com;
listen 80;
index index.phpindex.html index.htm;
root /usr/local/nginx/htdocs/html;
include Configs/deny-agent.conf;
# Auto Complete Last Path Slash
location ~* ^/(phpadmin|xcache)$ {
rewrite /(.*) $scheme://$http_host/$1/ permanent;
}
location ~* ^/(phpadmin|xcache)/.+\.php$ {
root /usr/local/nginx/htdocs/var;
include Configs/fcgi-php.conf;
fastcgi_pass phpserver;
}
location ~* ^/(phpadmin|xcache)/.*$ {
root /usr/local/nginx/htdocs/var;
}
# phpStatus
location /status {
include fastcgi_params;
fastcgi_pass phpserver;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
# server status
location /server {
stub_status on;
}
# .php support
include Configs/php-support.conf;
# static cache settings
include Configs/static.conf;
}
upstream CmsServer {
server 172.20.38.19:8086;
}
7、配置Includes下其他conf
注:这些为各个网站的配置
8、配置nginx与php(FastCGI)
缺少环境安装
[root@localhost php-5.3.29]# yum -y install libtool-ltdl-devel
[root@localhost php-5.3.29]# yum -y install libxml2-devel
[root@localhost php-5.3.29]# yum -y install curl-devel
[root@localhost php-5.3.29]# yum -y install libjpeg-devel
[root@localhost php-5.3.29]# yum -y install libpng-devel
[root@localhost php-5.3.29]# yum -y install freetype-devel
[root@localhost php-5.3.29]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@localhost libmcrypt-2.5.8]#./configure make makeinstall
安装freetds-0.91.tar.gz
./configure--prefix=/usr/local/freetds --enable-msdblib make make install
安装如下文件
libiconv-1.14.tar.gz
libmcrypt-2.5.8-9.el6.x86_64.rpm
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
yum -y installopenldap
yum -y install openldap-devel
wgethttp://www.monkey.org/~provos/libevent-1.2.tar.gz
#tar zxvf libevent-1.2.tar.gz
#cd libevent-1.2
#./configure –prefix=/usr
#make
#make install
#ls -al /usr/lib | grep libevent
wget https://launchpadlibrarian.net/105858257/libmemcached-1.0.8.tar.gz
[root@localhostphp-5.3.29]# tar -zxvf libmemcached-1.0.8.tar.gz
./configure --prefix=/usr/local/ --with-memcached
make && make install
[root@localhost php-5.3.29]# cp -frp /usr/lib64/libldap* /usr/lib/
安装mysql
yum -y install mysql
yum -y install mysql-devel
ln -s/usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so
修改mysql编码为utf8
character_set_server=utf8
[mysqld]
character_set_server=utf8
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assortedsecurity risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set=utf8
[root@localhost soft]# tar -zxvf php-5.3.29.tar.gz
[root@localhost soft]# tar -zxvf APC-3.1.9.tgz
[root@localhost soft]# mv APC-3.1.9 php-5.3.29/ext/apc
[root@localhost soft]# tar -zxvf freetype-2.4.2.tar.gz
[root@localhost soft]# mv freetype-2.4.2 php-5.3.29/ext/freetype
[root@localhost soft]# tar -zxvf jpegsrc.v8b.tar.gz
[root@localhost soft]# mv jpeg-8b/ php-5.3.29/ext/jpeg
[root@localhostsoft]# wget http://pecl.php.net/get/memcached-2.2.0.tgz
[root@localhost soft]# mv memcached-2.2.0/ php-5.3.29/ext/ memcached
[root@localhost soft]# mv libmemcached-1.0.8 /php-5.3.29/ext/libmemcached
安装php
./configure --prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc --with-mysql --with-mysqli--with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir --enable-xml --disable-debug --disable-rpath--enable-inline-optimization --with-curl --with-curlwrappers --enable-mbstring--with-mcrypt --with-openssl --enable-soap --enable-shmop --enable-sockets--enable-pcntl --with-mhash --with-pdo-mysql --with-mysql-sock --enable-fpm--with-fpm-user=www --with-fpm-group=www --with-gd--with-libmemcached-dir=/usr/local --enable-memcached --enable-apc--enable-static --with-mssql=/usr/local/freetds--with-pdo-dblib=/usr/local/freetds --without-pear --with-ldap-sasl --with-ldap--enable-gd-native-ttf --enable-mbregex --enable-sysvsem --enable-bcmath--enable-safe-mode
注: /soft/php-5.3.29/ext/apc/apc_mmap.c:91: warning: the use of `mktemp‘ is dangerous, betteruse `mkstemp‘
修改该文件指定行
/soft/php-5.3.29/ext/memcached/php_memcached.c:2641:undefined reference to `memcached_bucket_set‘
复制文件
[root@ptr123etc]# cp php.ini-production /usr/local/php/etc/php.ini-production
[root@ptr123etc]# cp php.ini-production php.ini
[root@ptr123etc]# cp php-fpm.conf.default php-fpm.conf
启动
/usr/local/php/sbin/php-fpm-D
/usr/local/nginx/sbin/nginx
修改php.ini中关于memcached部分
session.save_handler= memcached
session.save_path= "172.20.75.37:11211"
修改php.ini中关于APC部分
extension=apc.so
;APCsetting
apc.enabled=1
apc.shm_segments=1
apc.shm_size=64M
apc.optimization=1
apc.num_files_hint=0
apc.ttl=0
apc.gc_ttl=3600
apc.cache_by_default=on
重新启动php-fpm 和nginx即可
本文出自 “windows与linux” 博客,转载请与作者联系!
lnmp