5分钟搭建 nginx +php (LNMP)新手专用
这里要先声明一下,针对Nginx的php安装和针对apache的php安装是有区别的,因为Nginx中的php是以fastcgi的方式结合nginx的,可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的。
先把php 和php-fpm编译安装吧 请看http://heilinux.blog.51cto.com/6123663/1575582
修改配置文件
1 |
cd php-5.6.2 |
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吧
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/nginx/html$fastcgi_script_name; }}}
》》》》》》》》》》》》》》》》你相信么,你已经搞定了LNMP了《《《《《《《《《《《《《《
测试是否解析php文件
创建测试文件:
vim /usr/local/nginx/html/2.php
内容如下:
<?php echo "测试php是否解析";?>
测试:
curl localhost/2.php
看到什么了。。不要怀疑自己的眼睛,不要热泪盈眶。你已经成功了。
欢迎大家访问我的个人网站 萌萌的IT人

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

Laravel使用其直觀的閃存方法簡化了處理臨時會話數據。這非常適合在您的應用程序中顯示簡短的消息,警報或通知。 默認情況下,數據僅針對後續請求: $請求 -

PHP客戶端URL(curl)擴展是開發人員的強大工具,可以與遠程服務器和REST API無縫交互。通過利用Libcurl(備受尊敬的多協議文件傳輸庫),PHP curl促進了有效的執行

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显著减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

您是否想為客戶最緊迫的問題提供實時的即時解決方案? 實時聊天使您可以與客戶進行實時對話,並立即解決他們的問題。它允許您為您的自定義提供更快的服務

文章討論了PHP 5.3中介紹的PHP中的晚期靜態結合(LSB),允許靜態方法的運行時間分辨率調用以更靈活的繼承。 LSB的實用應用和潛在的觸摸

JWT是一種基於JSON的開放標準,用於在各方之間安全地傳輸信息,主要用於身份驗證和信息交換。 1.JWT由Header、Payload和Signature三部分組成。 2.JWT的工作原理包括生成JWT、驗證JWT和解析Payload三個步驟。 3.在PHP中使用JWT進行身份驗證時,可以生成和驗證JWT,並在高級用法中包含用戶角色和權限信息。 4.常見錯誤包括簽名驗證失敗、令牌過期和Payload過大,調試技巧包括使用調試工具和日誌記錄。 5.性能優化和最佳實踐包括使用合適的簽名算法、合理設置有效期、
