PHP教程

linux系统下安装配置Nginx、PHP环境

本文主要是介绍linux系统下安装配置Nginx、PHP环境,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

参考地址:https://www.cnblogs.com/evai/p/5991525.html

 

下载新的CentOS-Base.repo 到/etc/yum.repos.d/

 

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

运行yum makecache生成缓存:

 

 

yum clean all
yum makecache
yum update

安装Nginx

 

1.由于yum源中没有我们想要的nginx,那么我们就需要创建一个“/etc/yum.repos.d/nginx.repo”的文件,其实就是新增一个yum源。

 

vim /etc/yum.repos.d/nginx.repo

把如下内容复制进去

 

 

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

2.输入 yum list nginx 查看可安装的nginx包

 

 

[root@iZ2zeemzju81bld21k77icZ html]# yum list nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cloud.aliyuncs.com
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
 * webtatic: uk.repo.webtatic.com
Installed Packages
nginx.x86_64

如果执行命令是这样的显示效果,表示nginx的yum源配置成功

 

3.安装nginx

 

yum -y install nginx

4.启动nginx、查看启动状态

 

 

service nginx restart
service nginx status

安装PHP7

 

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

执行命令安装php7:

 

 

yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64

安装php-fpm:

 

 

yum install php70w-fpm php70w-opcache

启动php-fpm:

 

 

systemctl start php-fpm

修改 /etc/nginx/conf.d/default.conf 文件:

 

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

 


 

 

nginx配置位置

/etc/nginx/nginx.conf

 

 

php配置位置

/etc/php.ini

######避免PHP信息暴露在http头中
expose_php = Off

######设置PHP的时区
date.timezone = PRC

######设置PHP脚本允许访问的目录(需要根据实际情况配置)
open_basedir = /usr/share/nginx/html

 

 

配置www.conf

/etc/php-fpm.d/www.conf

user = nginx

######设置用户和用户组
user = nginx
group = nginx

######设置php的session目录(所属用户和用户组都是nginx)
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session

设置PHP监听
; listen = 127.0.0.1:9000   #####不建议使用

配置php-fpm.conf

/etc/php-fpm.conf

######引入www.conf文件中的配置
include=/etc/php-fpm.d/*.conf

 

 

 

 

4.配置文件所在地址

php.ini             /etc/php.ini
php加载ini文件       /etc/php.d/*.ini
php-fpm.conf        /etc/php-fpm.conf    
php-fpm.pid         /var/run/php-fpm/php-fpm.pid
php-fpm启动          php-fpm

这篇关于linux系统下安装配置Nginx、PHP环境的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!