Centos7 安装配置 PHP7 Nginx 并部署开源后台系统Fasadmin

2022-09-21 08:58:31 浏览数 (1)

1、查看是否安装过Nginx

代码语言:javascript复制
 rpm -qa|grep -E "nginx"

2、安装Nginx前需要提前安装以下这些依赖

2.1、查看gcc版本

代码语言:javascript复制
 gcc -v

若有内容输出说明已安装了gcc。否则,需使用以下命令进行安装。

代码语言:javascript复制
 yum -y install gcc

2.2、pcre、pcre-devel安装

代码语言:javascript复制
yum install -y pcre pcre-devel

2.3、zlib安装

代码语言:javascript复制
yum install -y zlib zlib-devel

2.4、安装openssl

代码语言:javascript复制
yum install -y openssl openssl-devel

3、 安装Nginx

3.1、下载Nginx源码并解压到 /home/nginx-php/

代码语言:javascript复制
tar -zxvf  nginx-1.10.3.tar.gz

3.2、切换到 /home/nginx-php/nginx-1.10.3

代码语言:javascript复制
 ./configure
    make
    make install

3.3、切换到/usr/local/nginx/conf 配置目录,编辑nginx.conf

代码语言:javascript复制
  server {
            listen 8001;

            set   $root  /home/ecspadmin/public;

            location ~ .*.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
                root $root;

            }
            location / {
                root    $root;

                index    index.html index.php;

                if ( -f $request_filename) {
                    break;

                }
                if ( !-e $request_filename) {
                    rewrite ^(.*)$ /index.php/$1 last;

                    break;

                }
            }
            location ~ ^/(uploads|assets)/.*.(php|php5|jsp)$ {
                deny all;

            }
            location ~ . .php($|/) {
                #fastcgi_pass    unix:/var/run/php/php7.1-fpm.sock;

                fastcgi_pass 127.0.0.1:9000; 

                fastcgi_split_path_info ^((?U). .php)(/?. )$;

                fastcgi_param PATH_INFO $fastcgi_path_info;

                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

                fastcgi_param    SCRIPT_FILENAME    $root$fastcgi_script_name;

                include        fastcgi_params;

            }
        }

4、源码编译安装 PHP7.1.33

4.1、在安装PHP7.1.33前,需安装以下依赖

代码语言:javascript复制
 yum install -y openssl-devel libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel recode-devel libicu-devel libzip-devel sqlite-devel oniguruma-devel

4.2、解压下载好的PHP7.1.33 并切换到

代码语言:javascript复制
tar  zxvf  php-7.1.33.tar.gz

4.3、预编译

代码语言:javascript复制
 ./configure --prefix=/usr/local/php7 
     --with-apxs2=/usr/bin/apxs 
     --with-config-file-path=/usr/local/php/etc  
     --with-curl 
     --with-freetype-dir 
     --with-gd 
     --with-gettext 
     --with-iconv-dir 
     --with-kerberos 
     --with-libdir=lib64 
     --with-libxml-dir 
     --with-mysqli 
     --with-openssl 
     --with-pcre-regex 
     --with-pdo-mysql 
     --with-pdo-sqlite 
     --with-pear 
     --with-png-dir 
     --with-xmlrpc 
     --with-xsl 
     --with-zlib 
     --enable-fpm 
     --enable-bcmath 
     --enable-libxml 
     --enable-inline-optimization 
     --enable-gd-native-ttf 
     --enable-mbregex 
     --enable-mbstring 
     --enable-opcache 
     --enable-pcntl 
     --enable-shmop 
     --enable-soap 
     --enable-sockets 
     --enable-sysvsem 
     --enable-xml 
     --enable-zip
     
     make && make install

4.4、修改php.ini、php-fpm.conf

代码语言:javascript复制
 cp php.ini-production /etc/php.ini
    cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    
    chmod  x /etc/rc.d/init.d/php-fpm
    
    cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
    
    cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
    
    vim /usr/local/php7/etc/php-fpm.conf
     最后 添加
    pm.max_children =50
    pm.start_servers=5
    pm.min_spare_servers=2
    pm.max_spare_servers=8
    
    tail -4 /usr/local/php7/etc/php-fpm.conf
    
    service php-fpm start

5、启动Nginx服务

5.1、切换目录到/usr/local/nginx/sbin下面

代码语言:javascript复制
  ./nginx

5.2、启动、暂停服务

代码语言:javascript复制
 ./nginx -s stop
    ./nginx -s quit
    ./nginx -s reload

最终效果如图:

0 人点赞