和LAMP不同的是LNMP中的N指的是是Nginx(類似於Apache的一種web服務軟體)其他都一樣。目前這種環境應用的也是非常之多。 Nginx設計的初衷是提供一種快速高效多併發的web服務軟體。在靜態頁面的處理上Nginx的確勝Apache一籌,然而在動態頁面的處理上 Nginx並不比Apache有多少優勢。但是,目前還是有很多愛好者對Nginx比較熱衷,隨著Nginx的技術逐漸成熟,它在web服務軟體領域的地 位越來越高。
【MySQL安裝】
1. 下載mysql到/usr/local/src/
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/mysql-5.0.86-linux-i686-icc-glibc23.tar.gz
2. 解壓
tar zxvf /usr/local/src/ mysql-5.0.86-linux-i686-icc-glibc23.tar.gz
3. 把解壓完的資料移動到/usr/local/mysql
mv mysql-5.0.86-linux-i686-ii-glibc23 /usr/local/mysql
4. 建立mysql使用者
useradd mysql
5. 初始化資料庫
cd /usr/local/mysql
mkdir /data/mysql ; chown -R mysql:mysql /data/mysql
./scripts/mysql_install_db –user=mysql –datadir=/data/mysql
–user定義資料庫的所屬主,–datadir定義資料庫安裝到哪裡,建議放到大空間的分割槽上,這個目錄需要自行建立。
6. 拷貝配置檔案
cp support-files/my-large.cnf /etc/my.cnf
7. 拷貝啟動指令碼檔案並修改其屬性
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
8. 修改啟動指令碼
vim /etc/init.d/mysqld
需要修改的地方有datadir=/data/mysql(前面初始化資料庫時定義的目錄)
9. 把啟動指令碼加入系統服務項,並設定開機啟動,啟動mysql
chkconfig –add mysqld
chkconfig mysqld on
service mysqld start
如果啟動不了,請到/data/mysql/ 下檢視錯誤日誌,該日誌格式為主機名.err。
【php的安裝】
這裡要先宣告一下,針對Nginx的php安裝和針對apache的php安裝是有區別的,因為Nginx中的php是以fastcgi的方式結合nginx的,可以理解為nginx代理了php的fastcgi,而apache是把php作為自己的模組來呼叫的。
useradd www
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/php-5.2.10.tar.gz
wget http://syslab.comsenz.com/downloads/linux/php-5.2.10-fpm-0.5.13.diff.gz
下載的第二個包php-5.2.10-fpm-0.5.13.diff.gz是用來給php打補丁的,預設情況下,php是無法編譯出fastcgi的。
tar zxvf php-5.2.10.tar.gz
gzip -cd php-5.2.10-fpm-0.5.13.diff.gz | patch -d php-5.2.10 -p1
cd php-5.2.10
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql –with-mysql-sock=/tmp –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv-dir –with-zlib-dir –with-mcrypt=/usr/local/libmcrypt –enable-soap –enable-gd-native-ttf –enable-ftp –enable-mbstring –enable-exif –enable-zend-multibyte –disable-ipv6 –enable-fastcgi –enable-fpm
make && make install
mkdir /usr/local/php/etc
cp php.ini-dist /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php-fpm.conf
<value name=”listen_address”>/tmp/php-fcgi.sock</value> 這一行要改成這樣,這裡這樣修 改了以後,在配置nginx的時候就需要注意這個路徑了。修改使用者和組的名稱為”www” 去掉註釋,改成這樣:Unix user of processes <value name=”user”>www</value> Unix group of processes <value name=”group”>www</value>
/usr/local/php/sbin/php-fpm start
其他關於php的擴充套件模組安裝請參考:
CentOS 5.5下安裝mysql5.1.57+php5.2.17(FastCGI)+nginx1.0.1高效能Web伺服器
【nginx 安裝以及配置】
1. nginx原始碼安裝
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/nginx-0.9.6.tar.gz
tar zxvf nginx-0.9.6.tar.gz
cd nginx-0.9.6
./configure –prefix=/usr/local/nginx –sbin-path=/usr/local/nginx/sbin/nginx –conf-path=/usr/local/nginx/conf/nginx.conf –error-log-path=/usr/local/nginx/logs/error.log –http-log-path=/usr/local/nginx/logs/access.log –pid-path=/usr/local/nginx/var/nginx.pid –lock-path=/usr/local/nginx/var/nginx.lock –http-client-body-temp-path=/dev/shm/nginx_temp/client_body –http-proxy-temp-path=/dev/shm/nginx_temp/proxy –http-fastcgi-temp-path=/dev/shm/nginx_temp/fastcgi –user=www –group=www –with-cpu-opt=pentium4F –without-select_module –without-poll_module –with-http_realip_module –with-http_sub_module –with-http_gzip_static_module –with-http_stub_status_module –without-http_ssi_module –without-http_userid_module –without-http_geo_module –without-http_memcached_module –without-http_map_module –without-mail_pop3_module –without-mail_imap_module –without-mail_smtp_module –with-pcre
make && make install
mkdir /dev/shm/nginx_temp
有 的nginx版本編譯時會因為pcre編譯不過去,需要修改一下 –with-pcre=/usr/local/src/pcre-7.8,前提是已經 下載了pcre原始碼包pcre-7.8.tar.gz,並解壓到/usr/local/src/pcre-7.8,不需要編譯pcre
2. 編寫nginx的啟動指令碼,並加入系統服務
vi /etc/init.d/nginx 寫入以下內容:
#!/bin/bash# chkconfig: – 30 21# description: http service.# Source Function Library. /etc/init.d/functions# Nginx SettingsNGINX_SBIN=”/usr/local/nginx/sbin/nginx”NGINX_CONF=”/usr/local/nginx/conf/nginx.conf”NGINX_PID=”/usr/local/nginx/var/nginx.pid”RETVAL=0prog=”Nginx”start() {echo -n $”Starting $prog: ” mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL}stop() { echo -n $”Stopping $prog: ” killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL}reload(){ echo -n $”Reloading $prog: ” killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL}restart(){ stop start}configtest(){ $NGINX_SBIN -c $NGINX_CONF -t return 0}case “$1″ in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $”Usage: $0 {start|stop|reload|restart|configtest}” RETVAL=1esacexit $RETVAL
儲存後,更改/etc/init.d/nginx的許可權
chmod 755 /etc/init.d/nginx
chkconfig –add nginx
chkconfig nginx on
3. nginx的配置
vim /usr/local/nginx/conf/nginx.conf
把原來的檔案清空,然後貼上如下內容:
user www www;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/var/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 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 2048;
server_names_hash_max_size 4096;
log_format combined_realip `$remote_addr $http_x_forwarded_for [$time_local] `
`$host “$request_uri” $status `
`”$http_referer” “$http_user_agent”`;
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;
server
{
listen 80;
server_name www.example.com;
index index.html index.htm index.php;
root /data/www;
location ~ .php$ {
include fastcgi_params;
fastcgi_pass unix:/ php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
保 存後就可以啟動nginx了,在重啟之前最好先檢查一下是否有問題/usr/local/nginx/sbin/nginx -t 如果顯示 “syntax is ok 和 nginx.conf was tested successfully”這樣的資訊,就說明配置沒有問題了,否則就需要根據提示修改了。service nginx start
如果啟 動不了,請到/usr/local/nginx/logs/目錄下檢視nginx_error.log這個日誌檔案。若是沒有這個日誌檔案,很有可能是那 個目錄沒有寫許可權,請執行chmod +w /usr/local/nginx/logs/ service nginx restart
【測試是否解析php檔案】
vim /data/www/1.php
寫入如下內容:
<?phpphpinfo();?>
然後設定hosts檔案,訪問 www.92csz.com/1.php 看是否能解析出這個頁面。
來源http://jingyan.baidu.com/article/fc07f9891c2b6412ffe51908.html