6. Nginx + PHP + FastGCI安装

LNAMP Linux Nginx Apache Mysql PHP

Nginx + PHPfast CGI

可以理解为一个php加速的一个接口

 

Php-fpm 可以实现fastcgi协议需要的进程池,php-fpm实现的fastcgi进程叫php-cgi,所以php-fmp其实是他自身的fastcgi php-cgi进程管理器

 

Ngix+FastCGI安装

 

前期准备工作:

#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.

 

注意:如果碰到以下的错误,查看一下解决方案

配置之前需要做一个软链接

因为在64位的linux系统中,libmysqlclient 默认安装到了 /usr/lib64/mysql/ 目录下,但是php编译时,要去/usr/lib目录下查找

 

# ln -s /usr/lib64/mysql/libmysqlclient.so.18.0.0 /usr/lib/libmysqlclient.so

否则会报错:

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

#启动脚本文件

[root@nginx ~]# chmod o+x /etc/init.d/php-fpm

#加权限

[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

 

 

 

 

报错:

[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

如果还有报错可能是配置文件php-fpm.conf最后一行,默认是注释的,去掉注释即可。

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

posted @ 2017-11-29 17:41  ling小龙  阅读(531)  评论(0编辑  收藏  举报