申明:此文檔目的是搭建基礎的lnmp環境,不作nginx、php-fpm過多優化說明。wordpress安裝參考官方文檔便可,過程介紹比較粗略,爲的是驗證lnmp環境正常,同時不介紹wordpress個性化設置。
nginx+mysql+php+memcache+Zend Optimizer+eaccelerator
zend optimizer 是一個代碼優化的模塊,能夠調優php代碼,實現的原理是對那些在被最終執行以前由運行編譯器(Run-Time Compiler)產生的代碼進行優化。代碼性能能夠提升40%到100%,
eAccelerator 是一個將編譯以後的php代碼緩存在share memory中的模塊。經過訪問共享內存能夠獲得編譯後的代碼並直接執行用以提升效率,這個對於php的執行效率的提升仍是很大的。
1、環境準備:
一、系統約定:
系統:centos5.6 32Bit
軟件包存放:/usr/local/src
apache網站根目錄:/home/wwwroot/
mysql數據目錄:/data/mysql
vhost日誌根目錄:/home/wwwlogs/
apache運行帳戶:www
mysql運行帳戶:www
服務器ip:172.16.57.10
domainname:www.iceman10.com
軟件下載URL
wget -c http://soft.vpser.net/web/pcre/pcre-8.12.tar.gz
wget -c http://soft.vpser.net/web/nginx/nginx-1.0.10.tar.gz
wget -c http://soft.vpser.net/datebase/mysql/mysql-5.1.60.tar.gz
wget -c http://soft.vpser.net/web/php/php-5.2.17.tar.gz
wget -c http://memcached.googlecode.com/files/memcached-1.4.7.tar.gz
wget -c http://soft.vpser.net/web/memcache/memcache-3.0.6.tgz
wget -c
http://soft.vpser.net/web/phpfpm/php-5.2.17-fpm-0.5.14.diff.gz
wget -c
http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.13-stable.tar.gz
wget -c http://soft.vpser.net/web/zend/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
wget -c
http://nchc.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2
wget -c http://cn.wordpress.org/wordpress-3.3.1-zh_CN.tar.gz
二、yum 安裝開發包
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel openssl openssl-devel openldap openldap-devel gd gd-devel libmcrypt libmcrypt-devel libtool gcc gcc-c++
gd庫使用yum安裝
2、編譯安裝NMP環境
2.一、建立Nginx帳戶及目錄
建立nginx用戶
groupadd www
useradd -s /sbin/nologin -g www www
建立nginx數據、日誌目錄
mkdir -p /home/wwwroot
mkdir -p /home/wwwlogs
chown -R www:www wwwlogs wwwroot
2.二、安裝pcre
安裝pcre 是爲了nginx支持rewrite模塊
tar zxvf pcre-8.12.tar.gz
cd pcre-8.12/
./configure
make && make install
2.三、安裝、配置nginx
tar zxvf nginx-1.0.10.tar.gz
cd nginx-1.0.10/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
make && make install
nginx.conf配置
/usr/local/nginx/conf/nginx.conf
user www www;
worker_processes 1;
error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
include vhost/*.conf;
}
建立 vhost/www.iceman10.com.conf
server
{
listen 80;
server_name www.iceman.com bbs.iceman.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.iceman10.com/htdocs;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
#expires 12h;
access_log off;
}
log_format www.iceman.com '$remote_addr - $remote_user [$time_local] $request '
'$status $body_bytes_sent $http_referer '
'$http_user_agent $http_x_forwarded_for';
access_log /home/wwwlogs/www.iceman.com.log www.iceman.com;
}
/usr/local/nginx/sbin/nginx –t \\檢測nginx.conf配置文件
2.四、建立mysql運行帳戶及目錄
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql/
2.五、mysql 編譯安裝
tar xzvf mysql-5.1.60.tar.gz
cd mysql-5.1.60
./configure --prefix=/usr/local/mysql --with-extra-charsets=all --with-charset=utf8 --enable-thread-safe-client --with-big-tables --enable-assembler --with-mysqld-ldflags=-all-static --with-plugins=all
make && make install
cd /usr/local/mysql/
chown -R mysql:mysql .
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R root .
chown -R mysql var
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
修改my.cnf
datadir = /data/mysql
sed -i "s/skip-locking/skip-external-locking/g" /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
2.六、php編譯安裝
tar zxvf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17/
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql --enable-fastcgi --enable-fpm --enable-discard-path --enable-force-cgi-redirect --with-libxml-dir --with-xmlrpc --with-gd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-curl --with-curlwrappers --enable-mbstring --with-mcrypt --enable-soap --enable-ftp
make
make install
cp php.ini-dist /usr/local/php5/etc/php.ini
2.7
、
php-fpm
配置
/usr/local/php5/etc
Unix user of processes
<value name="user">www</value>
Unix group of processes
<value name="group">www</value>
2.8
、
lnmp
驗證
/usr/local/nginx/sbin/nginx
啓動
nginx
服務
/usr/local/php5/sbin/php-fpm restart
啓動
php-fpm
建立
/home/wwwroot/www.iceman10.com/htdocs/phinfo.php
[root@demo10 htdocs]# cat phpinfo.php
<?
phpinfo();
?>