生活随笔
收集整理的這篇文章主要介紹了
(7)nginx: 搭建 nginx+php环境
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這里要先聲明一下,針對Nginx的PHP安裝和針對apache的php安裝是有區別的,因為Nginx中的php是以fastcgi的方式結合nginx的,可以理解為nginx代理了php的fastcgi,而apache是把php作為自己的模塊來調用的。
注意: 我們編譯的PHP 要有如下功能:
連接mysql, gd,ttf, 以fpm(fascgi)方式運行
安裝PHP
1 安裝 mysql : yum -y install mysql mysql-server mysql-devel
2 下載php-5.6.2 wgethttp://cn2.php.NET/distributions/php-5.6.2.tar.gz
3 解壓 tar -zxvf php-5.6.2.tar.gz
4 切換到 php-5.6.2./configure --prefix=/usr/local/software/php/install \--with-mysql=mysqlnd \--enable-mysqlnd \--with-gd \--enable-gd-native-ttf\--enable-gd-jis-conv \--enable-fpm
5.出現未安裝的錯誤,直接用yum 進行安裝即可 記得不要忘了裝上 -devel (libcurl libpng libcrul12等等)
6.出現找不到文件路徑的情況下 用find / -name 'name'去查找一下
7.出現warning 的情況大多是因為版本已經默認安裝了,可以去掉該行8.make
9.make install
修改配置文件
cp?php.ini-production?/usr/local/php/etc/php.ini
cp?/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-fpm
chmod?755?/etc/init.d/php-fpm
service?php-fpm?start
如果想讓它開機啟動,執行:
chkconfig?php-fpm?on
檢測是否啟動:
ps?aux?|grep?php-fpm
netstat?-ant?|grep?9000
看看是不是有很多個進程(大概20多個)還有你的9000端口開啟了么?。
》》》》》》》》》》》》》》》》華華麗麗的分隔符《《《《《《《《《《《《《《《《《《《
安裝nginx
開始安裝nginx吧??
| 1 2 | wget? http://nginx.org/download/nginx-1.6.2.tar.gz?//最新穩定版哦 |
?
解壓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_static_module?\
--with-http_stub_status_module??\
--with-pcre
編譯nginx
make
安裝nginx
make?install
因為nginx比較小,所以很快就會安裝完,而且也不會出什么錯誤,如果出錯了,yum安裝pcre-devel(嘿嘿,我是這個問題了,至于你出別的問題問度娘吧。)
》》》》》》》》》》》》》》》》》》華麗的分隔符《《《《《《《《《《《《《《《《《《《《《
添加一個nginx主程序的符號鏈接 ?
| 1 2 | ?? ln?-sf?/usr/local/nginx/sbin/nginx??/usr/sbin |
| 1 | nginx?-t??????測試一下吧,成功了吧,是不是很有成就感,別著急?咱們繼續! |
更改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/software/ngnix/install/z_com/test.php;}}}
》》》》》》》》》》》》》》》》你相信么,你已經搞定了LNMP了《《《《《《《《《《《《《《
測試是否解析php文件
創建測試文件:
vim?/usr/local/nginx/html/2.php
內容如下:
<?phpecho?"測試php是否解析";
?>
測試:
?curl?localhost/2.php
總結
以上是生活随笔為你收集整理的(7)nginx: 搭建 nginx+php环境的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。