這里要先聲明一下,針對Nginx的php安裝和針對apache的php安裝是有區別的,因為Nginx中的php是以fastcgi的方式結合nginx的,可以理解為nginx代理了php的fastcgi,而apache是把php作為自己的模塊來調用的。
先把php 和php-fpm編譯安裝吧 請看http://heilinux.blog.51cto.com/6123663/1575582
修改配置文件
cp php.ini-production /usr/local/php/etc/php.inicp /usr/local/php/etc/php-fpm.conf.default.conf php-fpm.conf
保存配置文件后,檢驗配置是否正確的方法為:
/usr/local/php/sbin/php-fpm -t
如果出現諸如 “test is successful” 字樣,說明配置沒有問題。
啟動php-fpm
cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod 755 /etc/init.d/php-fpmservice php-fpm start
如果想讓它開機啟動,執行:
chkconfig php-fpm on
檢測是否啟動:
ps aux |grep php-fpm
netstat -ant |grep 9000
看看是不是有很多個進程(大概20多個)還有你的9000端口開啟了么?。
》》》》》》》》》》》》》》》》華華麗麗的分隔符《《《《《《《《《《《《《《《《《《《
安裝nginx開始安裝nginx吧
解壓nginx
tar zxvf nginx-1.6.2.tar.gz
配置編譯參數
cd nginx-1.6.2./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_html' target='_blank'>static_module --with-http_stub_status_module --with-pcre
編譯nginx
make
安裝nginx
make install
因為nginx比較小,所以很快就會安裝完,而且也不會出什么錯誤,如果出錯了,yum安裝pcre-devel(嘿嘿,我是這個問題了,至于你出別的問題問度娘吧。)
》》》》》》》》》》》》》》》》》》華麗的分隔符《《《《《《《《《《《《《《《《《《《《《
添加一個nginx主程序的符號鏈接
更改nginx配置
首先把原來的配置文件清空:
> /usr/local/nginx/conf/nginx.conf
“>” 這個符號之前阿銘介紹過,為重定向的意思,單獨用它,可以把一個文本文檔快速清空。
vim /usr/local/nginx/conf/nginx.conf
寫入如下內容:
user nobody nobody;worker_processes 2;error_log /usr/local/nginx/logs/nginx_error.log crit;pid /usr/local/nginx/logs/nginx.pid;worker_rlimit_nofile 51200;events{ use epoll; worker_connections 6000;}http{ include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526; 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 localhost; index index.html index.htm index.php; root /usr/local/nginx/html; location ~ .php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; }}}
》》》》》》》》》》》》》》》》你相信么,你已經搞定了LNMP了《《《《《《《《《《《《《《
測試是否解析php文件創建測試文件:
vim /usr/local/nginx/html/2.php
內容如下:
<?php echo "測試php是否解析";?>
測試:
curl localhost/2.php
看到什么了。。不要懷疑自己的眼睛,不要熱淚盈眶。你已經成功了。
PHP編程鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答
圖片精選