從零搭建LNMP環境(二) - 整合Nginx與PHP
安裝Nginx的方式有很多種,這裡我們還是編譯原始碼進行安裝,使用下列命令:
$ wget http://nginx.org/download/nginx-1.6.2.tar.gz
$ tar -zxvf nginx-1.6.2.tar.gz
$ cd nginx-1.6.2
$ ./configure --prefix=/usr/local/nginx
$ make
$ sudo make install
如果安裝過程中出現如下錯誤
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
則需要先安裝pcre
$ sudo yum install pcre-devel
安裝完成之後,我們的Nginx安裝目錄在/usr/local/nginx
。
接下來修改nginx的配置檔案(/usr/local/nginx/conf/nginx.conf),使其能夠處理php指令碼。
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name _;
root /vagrant;
location / {
index index.html index.htm index.php;
}
location /demo {
index index.php;
if (!-e $request_filename) {
rewrite ^/demo/(.*)$ /demo/index.php?$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
最後,啟動Nginx時,需要先啟動PHP-FPM。
$ sudo /usr/local/php/sbin/php-fpm
$ sudo /usr/local/nginx/sbin/nginx
對於Nginx的重啟以及關閉操作,可以使用以下命令
$ sudo /usr/local/nginx/sbin/nginx -s [reload|restart|stop]
而PHP-FPM,則麻煩一點,需要先使用ps -ef|grep php-fpm
獲取master process的程式ID,
再使用kill -USR2
:
$ ps -ef|grep php-fpm
root 6221 1 0 02:17 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody 6222 6221 0 02:17 ? 00:00:00 php-fpm: pool www
nobody 6223 6221 0 02:17 ? 00:00:00 php-fpm: pool www
vagrant 6233 1623 0 02:18 pts/0 00:00:00 grep php-fpm
$ sudo kill -USR2 6221
注意:
-USR2
引數為重啟,-INT
引數為關閉。
相關文章
- LNMP環境搭建(二):NginxLNMPNginx
- Mac os 使用 (homebrew) 從零搭建 PHP,nginx,MySQL,Redis (LNMP) 開發環境MacPHPNginxMySqlRedisLNMP開發環境
- LNMP環境搭建——Nginx篇LNMPNginx
- 從零搭建LNMP環境(一) - 編譯原始碼安裝PHPLNMP編譯原始碼PHP
- PHP-lnmp 環境搭建PHPLNMP
- 搭建 lnmp 環境之 nginx 篇LNMPNginx
- LNMP 環境搭建LNMP
- 搭建lnmp環境LNMP
- lnmp環境搭建LNMP
- Mac下安裝LNMP(Nginx+PHP5.6)環境MacLNMPNginxPHP
- docker搭建lnmp環境DockerLNMP
- docker 搭建 lnmp 環境DockerLNMP
- 如何搭建LNMP環境LNMP
- ubuntu lnmp環境搭建UbuntuLNMP
- 從零搭建LNMP環境(三) - 安裝MySQL資料庫伺服器LNMPMySql資料庫伺服器
- Docker LNMP Redis 環境搭建DockerLNMPRedis
- Windows 下搭建 lnmp 環境WindowsLNMP
- VUE從零開始環境搭建Vue
- MAC使用brew搭建nginx、php、mysql環境MacNginxPHPMySql
- win11搭建nginx+php環境NginxPHP
- HHvm建站環境搭建方法:Nginx、lnmp/lamp等安裝部署NginxLNMPLAMP
- Mac下使用Brew搭建PHP(LNMP/LAMP)開發環境MacPHPLNMPLAMP開發環境
- Mac搭建PHP開發環境(PHP+Nginx+MySQL)MacPHP開發環境NginxMySql
- 從零開始搭建Nginx和Tomcat的web叢集環境NginxTomcatWeb
- Deepin 15 搭建 LNMP 環境 + swooleLNMP
- Dockfile搭建極簡LNMP環境LNMP
- 基於Docker搭建LNMP環境DockerLNMP
- PHP 一鍵 Docker LNMP 環境PHPDockerLNMP
- 從零開始搭建Jenkins+Docker自動化整合環境JenkinsDocker
- PHP環境LAMP/LNMP安裝與配置筆記PHPLAMPLNMP筆記
- PHP入門-Window 下利用Nginx+PHP 搭建環境PHPNginx
- 在 Ubuntu 上搭建 nginx+PHP+Laravel 環境UbuntuNginxPHPLaravel
- linux下nginx+php+mysql環境搭建LinuxNginxPHPMySql
- MNMP (Mac + Nginx + MySQL + PHP) 開發環境搭建MacNginxMySqlPHP開發環境
- 從零搭建 Node.js 線上環境Node.js
- docker 學習筆記之實戰 lnmp 環境搭建系列 (2) ------ 手動搭建 lnmp 環境Docker筆記LNMP
- 利用 Docker 一鍵搭建 LNMP 環境DockerLNMP
- docker搭建laravel開發環境lnmpDockerLaravel開發環境LNMP