Centos7.6 Nginx+php安装配置

PHP安装

centos安装nginx php74 mysql

一、yum安装PHP
检查当前安装的PHP包
yum list installed | grep php

如果有安装的PHP包,先删除他们
yum list installed | grep php | awk '{print $1}' | yum remove

2.配置epel源
yum install -y epel-release
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

配置remi源
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

使用yum list命令查看可安装的包(Packege)
yum list --enablerepo=remi --enablerepo=remi-php56 | grep '@remi-php56'

3.安装php5.6.x
yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-pear php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof --skip-broken

4.安装php-fpm
yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm 

5.配置开机启动服务
systemctl enable php-fpm

6.启动php-fpm
systemctl restart php-fpm

7.查看是否安装成功
ps -ef | grep php
netstat -anp | grep 9000

安装其他扩展
yum install --enablerepo=remi --enablerepo=remi-php56 php-扩展名称 php-扩展名称2

8.查看PHP版本
php -v

参考:https://www.cnblogs.com/phpdragon/p/14710830.html

 

nginx配置PHP

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {        
        listen       80 default_server;       
        listen       [::]:80 default_server;        # 这里改动了,也可以写你的域名

        server_name  localhost;       
        root         /usr/share/nginx;        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;        
        location / {            # 这里改动了 定义首页索引文件的名称

        index index.php index.html index.htm;
        }        
        error_page 404 /404.html;            
                location = /40x.html {

                }        
        error_page 500 502 503 504 /50x.html;          
                location = /50x.html {

        }        # 这里新加的

        # PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.

        # Fastcgi服务器和程序(PHP,Python)沟通的协议.

        location ~ \\.php$ {            # 设置监听端口

            fastcgi_pass   127.0.0.1:9000;            # 设置nginx的默认首页文件(上面已经设置过了,可以删除)

            fastcgi_index  index.php;            # 设置脚本文件请求的路径

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            # 引入fastcgi的配置文件

            include        fastcgi_params;

        }

        }

# # Settings for a TLS enabled server.

#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;

#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;

#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;

#        error_page 404 /404.html;
#            location = /40x.html {
#        }

#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

PHP测试页面:

<?php

phpinfo();

?>