6. Nginx + PHP + FastGCI安装
LNAMP Linux Nginx Apache Mysql PHP
Nginx + PHP(fast CGI)
可以理解為一個(gè)php加速的一個(gè)接口
?
Php-fpm 可以實(shí)現(xiàn)fastcgi協(xié)議需要的進(jìn)程池,php-fpm實(shí)現(xiàn)的fastcgi進(jìn)程叫php-cgi,所以php-fmp其實(shí)是他自身的fastcgi 或 php-cgi進(jìn)程管理器
?
Ngix+FastCGI安裝
?
前期準(zhǔn)備工作:
#yum install ??gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mariadb mariadb-server?mariadb-devel -y
?
[root@nginx php-5.3.10]# systemctl start mariadb.service
[root@nginx php-5.3.10]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
?
注意:如果碰到以下的錯(cuò)誤,查看一下解決方案
配置之前需要做一個(gè)軟鏈接
因?yàn)樵?/span>64位的linux系統(tǒng)中,libmysqlclient 默認(rèn)安裝到了 /usr/lib64/mysql/ 目錄下,但是php編譯時(shí),要去/usr/lib目錄下查找
?
# ln -s /usr/lib64/mysql/libmysqlclient.so.18.0.0 /usr/lib/libmysqlclient.so
否則會(huì)報(bào)錯(cuò):
configure: error: Cannot find libmysqlclient under /usr.
Note that the MySQL client library is not bundled anymore!
?
?
#使用編譯安裝php-fast
下載php7.1.12
解壓---配置---
[root@nginx ]# tar xvf php-7.1.12.tar.gz
[root@nginx php-7.1.12]# ./configure --prefix=/usr/local/php7.1 --enable-fpm --enable-debug --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-curl --with-mysqli=/usr/bin/mysql_config
?
---編譯---安裝---
?
[root@nginx php-7.1.12]# make
[root@nginx php-7.1.12]# make install
?
[root@nginx php-7.1.12]# cp php.ini-production /usr/local/php7.1/lib/php.ini
[root@nginx ~]# cp /usr/local/php7.1/etc/php-fpm.conf.default /usr/local/php7.1/etc/php-fpm.conf
#配置文件
[root@nginx php-7.1.12]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#啟動(dòng)腳本文件
[root@nginx ~]# chmod o+x?/etc/init.d/php-fpm
#加權(quán)限
[root@nginx ~]# /etc/init.d/php-fpm start
Starting php-fpm ?done
[root@nginx ~]# ps -ef | grep php
root ??????3223 ?????1 ?0 17:39 ? ???????00:00:00 php-fpm: master process (/usr/local/php7.1/etc/php-fpm.conf)
nobody ????3224 ??3223 ?0 17:39 ? ???????00:00:00 php-fpm: pool www
nobody ????3225 ??3223 ?0 17:39 ? ???????00:00:00 php-fpm: pool www
root ??????3227 ??2877 ?0 17:39 pts/0 ???00:00:00 grep --color=auto php
?
?
?
?
報(bào)錯(cuò):
[root@nginx ~]# /etc/init.d/php-fpm start
Starting php-fpm [29-Nov-2017 16:43:01] WARNING: Nothing matches the include pattern '/usr/local/php7.1/etc/php-fpm.d/*.conf' from /usr/local/php7.1/etc/php-fpm.conf at line 125.
[29-Nov-2017 16:43:01] ERROR: No pool defined. at least one pool section must be specified in config file
[29-Nov-2017 16:43:01] ERROR: failed to post process the configuration
[29-Nov-2017 16:43:01] ERROR: FPM initialization failed
?failed
解決:
[root@nginx php-fpm.d]# pwd
/usr/local/php7.1/etc/php-fpm.d
[root@nginx php-fpm.d]#?cp www.conf.default www.conf
如果還有報(bào)錯(cuò)可能是配置文件php-fpm.conf最后一行,默認(rèn)是注釋的,去掉注釋即可。
include=/usr/local/php7.1/etc/php-fpm.d/*.conf
?
?
?
安裝完成:
Wrote PEAR system config file at: /usr/local/php7.1/etc/pear.conf
You may want to add: /usr/local/php7.1/lib/php to your php.ini include_path
/root/php-7.1.12/build/shtool install -c ext/phar/phar.phar /usr/local/php7.1/bin
ln -s -f phar.phar /usr/local/php7.1/bin/phar
Installing PDO headers: ??????????/usr/local/php7.1/include/php/ext/pdo/
[root@nginx php7.1]# tree /usr/local/php7.1/ | grep php-fpm
│?? ├── php-fpm.conf.default
│?? └── php-fpm.d
│?? │?? ????└── php-fpm.8
│?? └── php-fpm
?
其他鏈接:
https://www.howtoforge.com/tutorial/how-to-install-php-7-on-debian/
?
安裝完配置:
[root@nginx ~]# vi /usr/local/nginx/nginx.conf
[...]
#C
????????server {
???????????????listen 80;
???????????????server_name www.doudou0826c.com;
????????????????location / {
????????????????????????root ???html/c;
????????????????????????index ??index.html index.htm;
????????????????}
????????#PHP
????????location ~ \.php$ {
????????????????root ???html;
????????????????fastcgi_pass ???127.0.0.1:9000;
????????????????fastcgi_index ??index.php;
????????????????fastcgi_param ??SCRIPT_FILENAME /usr/local/nginx/html/c$fastcgi_script_name;
????????????????include ????????fastcgi_params;
????????????????}
????????}
[...]
[root@nginx ~]# cat /usr/local/nginx/html/c/index.php
<?php
phpinfo();
?>
?
?
[root@nginx ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful
[root@nginx ~]# /usr/local/nginx/sbin/nginx -s reload
?
?
nginx的配置文件記錄
[root@nginx nginx]# cat nginx.conf
user nginx nginx;
worker_processes? 1;
error_log logs/error.log info;
pid?? ?logs/nginx.pid;
events {
??? worker_connections? 1024;
}
http {
??? include?????? mime.types;
??? default_type? application/octet-stream;
??? sendfile??????? on;
??? tcp_nopush?? ???? on;
??? keepalive_timeout? 65;
#A
?? ?server {
?? ??? ?listen 80;
?? ??? ?server_name doudou0826a.com www.doudou0826a.com dd0826a.com ;
?? ??? ?location / {
?? ??? ??? ?root?? ?html/a;
?? ??? ??? ?index?? ?index.html index.htm;
?? ??? ?expires?? ?3d;?? ?
?? ??? ?}
?? ??? ?if ($host != 'www.doudou0826a.com') {
?? ??? ??? ?rewrite ^/(.*) http://www.doudou0826a.com/$1 permanent;
?? ??? ?}
?? ??? ?#rewrite ^/$ http://www.doudou0826a.com/index.html permanent;
?? ??? ?if ( !-e $request_filename )
?? ??? ?{
?? ??? ??? ?rewrite ^/(.*)$ /index.php last;
?? ??? ?}
?? ?}
#B
??????? server {
??????????????? listen 80;
??????????????? server_name www.doudou0826b.com;
??????????????? location / {
??????????????????????? root??? html/b;
??????????????????????? index?? index.html index.htm;
?????? ??? ?}
?? ??? ?if ($http_user_agent ~* "wget" ) { return 404; }
?? ??? ?location ~* \.(gif|jpg|png|swf|flv)$ {
??????????????????????? valid_referers none blocked *.doudou0826b.com;
??????????????????????? root??? /html/b ;
??????????????? if ($invalid_referer) {
??????????????????????? return 403;
??????????????????????? }
??????????????? }
?? ?
?? ??? ?location /NginxStatus {
?? ??? ??? ?stub_status?? ?on;
?? ??? ?}
?? ?}
#C
?? ?server {
?????????????? listen 80;
?????????????? server_name www.doudou0826c.com;
??????????????? location / {
??????????????????????? root??? html/c;
??????????????????????? index?? index.html index.htm;
?? ??? ?}?? ?
?? ?#PHP
??????? location ~ \.php$ {
??????????????? root??? html;
??????????????? fastcgi_pass??? 127.0.0.1:9000;
??????????????? fastcgi_index?? index.php;
??????????????? fastcgi_param?? SCRIPT_FILENAME /usr/local/nginx/html/c$fastcgi_script_name;
??????????????? include???????? fastcgi_params;
????? ??? ??? ?}
??????? }
}
?
?
其他:
./configure --prefix=/usr/local/php7.1 --enable-fpm --disable-rpath --with-pear --disable-debug --with-openssl --with-pcre-regex --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --enable-inline-optimization --with-gd --enable-gd-native-ttf --with-gettext --with-imap --with-imap-ssl --with-kerberos --with-ldap --enable-mbstring --enable-mbregex --with-mcrypt --with-mysql --with-mysqli --enable-pcntl --enable-pdo --with-pdo-firebird --with-pdo-mysql --with-pdo-pgsql --with-pgsql --enable-shmop --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --enable-wddx --with-xmlrpc --with-xsl --enable-zip --with-pic --enable-ftp --enable-dom --enable-xmlwriter --enable-xmlreader --enable-tokenizer --enable-simplexml --enable-session --enable-posix --enable-phar --enable-libxml --enable-json --with-iconv --enable-filter --enable-fileinfo --enable-dba --enable-ctype
轉(zhuǎn)載于:https://www.cnblogs.com/lingxiaolong/p/7921850.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的6. Nginx + PHP + FastGCI安装的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 打一波鸡血
- 下一篇: Bluetooth LE for iOS