【Nginx】php+nginx快速搭建
參考文件
http://blog.csdn.net/dyllove98/article/details/41120789
http://www.cnblogs.com/skynet/p/4146083.html
php5.3.3以前
我們用php-fpm來進行重新載入配置檔案(如php.ini):
php 5.3.3 後的php-fpm 不再支援 php-fpm 以前具有的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,需要使用訊號控制:
搭建nginx
http://blog.csdn.net/dyllove98/article/details/41120789
http://www.cnblogs.com/skynet/p/4146083.html
安裝php php-fpm
-
安裝 開發軟體包:yum -y groupinstall "Development Tools"
-
安裝 mysql : yum -y install mysql mysql-server mysql-devel
-
下載php-5.6.2 wget http://cn2.php.net/distributions/php-5.6.2.tar.gz
-
解壓 tar -zxvf php-5.6.2.tar.gz
-
切換到 php-5.6.2
-
./configure \
-
--prefix=/usr/local/php \
-
--with-config-file-path=/usr/local/php/etc \
-
--enable-fpm \
-
--with-fpm-user=php-fpm \
-
--with-fpm-group=php-fpm \
-
--with-mysql=mysqlnd \ //這裡mysqlnd 是內部查詢命令
-
--with-mysql-sock=/tmp/mysql.sock \
-
--with-libxml-dir \
-
--with-gd \
-
--with-jpeg-dir \
-
--with-png-dir \
-
--with-freetype-dir \
-
--with-iconv-dir \
-
--with-zlib-dir \
-
--with-mcrypt \
-
--enable-soap \
-
--enable-gd-native-ttf \
-
--enable-ftp \
-
--enable-mbstring \
-
--enable-exif \
-
--disable-ipv6 \
-
--with-pear \
-
--with-curl \
-
--with-openssl
-
出現未安裝的錯誤,直接用yum 進行安裝即可 記得不要忘了裝上 -devel (libcurl libpng libcrul12等等),dir報錯就去掉--with-dir再configure
-
出現找不到檔案路徑的情況下 用find / -name 'name'去查詢一下
-
出現warning 的情況大多是因為版本已經預設安裝了,可以去掉該行
-
- make
- make install
點選(此處)摺疊或開啟
-
cd php-5.6.2
-
cp php.ini-production /usr/local/php/etc/php.ini
-
cp /usr/local/php/etc/php-fpm.conf.default.conf php-fpm.conf
-
-
-
#測試php-fpm配置
-
/usr/local/php/sbin/php-fpm -t 或
- /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf -t
-
如果出現諸如 “test is successful” 字樣,說明配置沒有問題
-
-
#啟動php-fpm
-
/usr/local/php/sbin/php-fpm 或
-
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf
-
- 啟動PHP報錯ERROR: [pool www] cannot get uid for user '@php_fpm_user@'
- vi php-fpm.conf
- 將user與group改為系統存在的使用者,從新啟動即可!!!
- user=www
- group=www
-
。
php5.3.3以前
我們用php-fpm來進行重新載入配置檔案(如php.ini):
-
/usr/local/php/sbin/php-fpm reload
-
- 注:/usr/local/php/sbin/php-fpm還有其他引數,包括:start|stop|quit|restart|reload|logrotate
php 5.3.3 後的php-fpm 不再支援 php-fpm 以前具有的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,需要使用訊號控制:
-
master程式可以理解以下訊號
-
-
INT, TERM 立刻終止
-
QUIT 平滑終止
-
USR1 重新開啟日誌檔案
-
USR2 平滑過載所有worker程式並重新載入配置和二進位制模組
-
-
示例:
- php-fpm 關閉:
-
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
-
-
php-fpm 重啟:
-
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
-
-
檢視php-fpm程式數:
- ps aux | grep -c php-fpm
搭建nginx
-
wget http://nginx.org/download/nginx-1.6.2.tar.gz //最新穩定版哦
-
yum安裝pcre-devel
-
-
解壓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
新增軟連線
ln -sf /usr/local/nginx/sbin/nginx /usr/sbin
測試
nginx -t
修改nginx配置檔案讓其載入php-fpm模組
-
server部分放開php-fpm模組
-
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
-
-
location ~ \.php$ {
-
root html;
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index.php;
-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ----紅色是與預設配置檔案不一樣的地方
-
include fastcgi_params;
-
}
啟動
/usr/local/nginx/sbin/nginx
重啟動nginx
nginx -s reload
訪問測試:
---大功告成
-
wget http://nginx.org/download/nginx-1.6.2.tar.gz //最新穩定版哦
-
yum安裝pcre-devel
-
-
解壓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
新增軟連線
ln -sf /usr/local/nginx/sbin/nginx /usr/sbin
測試
nginx -t
修改nginx配置檔案讓其載入php-fpm模組
-
server部分放開php-fpm模組
-
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
-
-
location ~ \.php$ {
-
root html;
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index.php;
-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ----紅色是與預設配置檔案不一樣的地方
-
include fastcgi_params;
- }
/usr/local/nginx/sbin/nginx
重啟動nginx
nginx -s reload
訪問測試:
---大功告成
補充:
修改預設web路徑,與多個虛擬目錄
[root@node3 conf]#more /etc/hosts
192.168.6.119 nginx1 nginx2 a.ttlsa.com b.ttlsa.com
如上訴配置檔案:
所以訪問時如下:
[root@node3 conf]# curl test1
test1
[root@node3 conf]# curl test2
test2
[root@node3 conf]# curl a.ttlsa.com:8090
this is a.ttlsa.com
[root@node3 conf]# curl b.ttlsa.com:8090
this is b.ttlsa.com
修改預設web路徑,與多個虛擬目錄
-
[root@node3 conf]# more nginx.conf
-
-
#user nobody;
-
worker_processes 1;
-
-
#error_log logs/error.log;
-
#error_log logs/error.log notice;
-
#error_log logs/error.log info;
-
-
#pid logs/nginx.pid;
-
-
-
events {
-
worker_connections 1024;
-
}
-
-
-
http {
-
include mime.types;
-
default_type application/octet-stream;
-
-
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
-
# '$status $body_bytes_sent "$http_referer" '
-
# '"$http_user_agent" "$http_x_forwarded_for"';
-
-
#access_log logs/access.log main;
-
-
sendfile on;
-
#tcp_nopush on;
-
-
#keepalive_timeout 0;
-
keepalive_timeout 65;
-
-
#gzip on;
-
-
server {
-
listen 80;
-
server_name test1;
-
-
location / { ----location訪問規則詳見文件
- root html; ---nginx1域名 預設訪問web路徑,如果訪問nginx1/index.html 則訪問的是/usr/local/nginx/html/目錄
-
index index.html index.htm;
-
}
-
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root html;
-
}
-
-
location ~ \.php$ {
-
root /var/www/html; ---nginx1域名 預設php檔案訪問路徑.如:訪問的是nginx1/index.php 訪問的是 /var/www/html/路徑。。。一般與上面相比較沒必要配置兩個不一樣的目錄
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index.php;
-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-
include fastcgi_params;
-
}
-
-
}
-
-
-
server {
-
listen 80;
- server_name test2;
-
location / {
-
root /var/www/html2; #目錄
-
index index.html index.php;
-
}
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root html;
-
}
-
-
location ~ \.php$ {
-
root /var/www/html2; #php檔案訪問路徑
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index.php;
-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-
include fastcgi_params;
-
}
-
}
-
-
server {
-
listen 8080;
- server_name a.ttlsa.com;
-
location / {
-
root /var/www/a.ttlsa.com; #目錄
-
index index.html index.php;
-
}
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root html;
-
}
-
-
location ~ \.php$ {
-
root /var/www/a.ttlsa.com;
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index.php;
-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-
include fastcgi_params;
-
}
-
}
-
-
server {
-
listen 8090;
- server_name b.ttlsa.com;
-
location / {
-
root /var/www/b.ttlsa.com; #目錄
-
index index.html index.php;
-
}
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root html;
-
}
-
-
location ~ \.php$ {
-
root /var/www/b.ttlsa.com;
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_index index.php;
-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-
include fastcgi_params;
-
}
-
}
-
-
-
-
-
# another virtual host using mix of IP-, name-, and port-based configuration
-
#
-
#server {
-
# listen 8000;
-
# listen somename:8080;
-
# server_name somename alias another.alias;
-
-
# location / {
-
# root html;
-
# index index.html index.htm;
-
# }
-
#}
-
-
-
# HTTPS server
-
#
-
#server {
-
# listen 443 ssl;
-
# server_name localhost;
-
-
# ssl_certificate cert.pem;
-
# ssl_certificate_key cert.key;
-
-
# ssl_session_cache shared:SSL:1m;
-
# ssl_session_timeout 5m;
-
-
# ssl_ciphers HIGH:!aNULL:!MD5;
-
# ssl_prefer_server_ciphers on;
-
-
# location / {
-
# root html;
-
# index index.html index.htm;
-
# }
-
#}
-
-
-
include vhost/*.conf;
- }
[root@node3 conf]#more /etc/hosts
192.168.6.119 nginx1 nginx2 a.ttlsa.com b.ttlsa.com
如上訴配置檔案:
所以訪問時如下:
[root@node3 conf]# curl test1
test1
[root@node3 conf]# curl test2
test2
[root@node3 conf]# curl a.ttlsa.com:8090
this is a.ttlsa.com
[root@node3 conf]# curl b.ttlsa.com:8090
this is b.ttlsa.com
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-1869911/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Mac搭建php+nginxMacPHPNginx
- Linux下信用盤SGWIN程式搭建PHP+Nginx環境搭建LinuxPHPNginx
- mac上php+nginx配置MacPHPNginx
- phpstudy 使用 PHP+nginx 配置 LaravelPHPNginxLaravel
- CenterOS docker 下簡單部署 PHP+NginxROSDockerPHPNginx
- 使用dockerfile+docker-compose安裝PHP+nginx環境DockerPHPNginx
- Linux微信H5下飛鳥新聖掃碼程式搭建PHP+Nginx環境原始碼搭建公眾號防封LinuxH5PHPNginx原始碼
- 使用ACK和NAS快速搭建彈性NGINX網站Nginx網站
- php+nginx實現最簡單的遠端呼叫rpc(微服務)PHPNginxRPC微服務
- 如何用Nginx快速搭建一個安全的微服務架構Nginx微服務架構
- Nginx篇--Nginx原始碼搭建Nginx原始碼
- 如何用Nginx搭建一個安全的、快速的微服務架構Nginx微服務架構
- 基於Nginx搭建一個安全的、快速的微服務架構Nginx微服務架構
- Nginx快速入門Nginx
- 教你如何用Nginx搭建一個安全的、快速的微服務架構Nginx微服務架構
- vue 快速搭建Vue
- 快速搭建Fx
- nginx 負載均衡搭建Nginx負載
- nginx windows下 快速關閉NginxWindows
- MyCat的快速搭建
- 快速搭建MyBatis 框架MyBatis框架
- LNMP環境搭建(二):NginxLNMPNginx
- Docker 之 Nginx環境搭建DockerNginx
- LNMP環境搭建——Nginx篇LNMPNginx
- 使用 Nginx 搭建 Webdav 服務NginxWeb
- 快速整合搭建SSM框架SSM框架
- express快速搭建web serverExpressWebServer
- 利用rman快速搭建standby
- 工作臺快速搭建流程
- RHEL 8 搭建 Nginx Web 服務NginxWeb
- 搭建 lnmp 環境之 nginx 篇LNMPNginx
- mac下搭建nginx+php+mysqlMacNginxPHPMySql
- nginx伺服器搭建以及配置Nginx伺服器
- Windows下搭建Nginx伺服器WindowsNginx伺服器
- 使用nginx搭建creates.io映象Nginx
- 基於Nginx搭建WebDAV服務NginxWeb
- nginx 靜態伺服器搭建Nginx伺服器
- Nginx搭建檔案伺服器Nginx伺服器