搭建nginx、php环境

参考:
https://help.aliyun.com/document_detail/97251.html?spm=a2c4g.50774.0.0.62e981d5Rl5971#section-5tw-l02-k4s
https://help.aliyun.com/zh/ecs/use-cases/build-a-lamp-stack-on-a-centos-7-instance?spm=a2c4g.11186623.0.0.454a6eaewGiBGj
https://www.codenong.com/cs105322604/
https://www.cnblogs.com/dongqiliang/p/11921954.html
https://zhuanlan.zhihu.com/p/74003058

安装及配置

1、安装相应程序

	安装nginx
		yum install nginx -y
	安装php
		yum install php php-fpm -y
		yum install php-gd* -y

	注:
		使用上面命令安装的php版本可能比较低,可以使用一下命令升级,以下方法
			第一种(推荐使用):
				1、运行以下命令,添加EPEL源
					rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-relearse-latest-7.noarch.rpm
				2、运行以下命令添加Webtatic源
					rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
				3、运行以下命令安装PHP
					sudo yum -y install php72w-devel php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64  php72w-pdo.x86_64   php72w-mysqlnd  php72w-fpm php72w-opcache php72w-pecl-redis php72w-pecl-mongodb php72w-bcmath
			第二种:
				1、添加EPEL和REMI存储库
					sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
					sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

				2、在CentOS 7上安装PHP 7.4版本
					sudo yum -y install yum-utils
					sudo yum-config-manager --enable remi-php74

				3、升级软件和系统内核
					sudo yum update
				执行完后,再去安装,即可发现php版本已升级

2、配置文件

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

		打开后修改里面配置,将相应属性改为如下内容
			user = nginx
			group = nginx
			pm.status_path = /phpfpm
			listen = /run/php-fpm/www.sock
			listen.owner = nginx
			listen.group = nginx
			listen.mode = 0660

3、nginx配置

server {
    listen  80; //监听端口
    index index.html index.htm index.php; //首页文件
    root /usr/share/nginx/html; //根目录
    
                   
    location / {
       try_files $uri $uri/ /index.php?$query_string;
    }

        .
        .
        .

    location ~ \.php(/|$) {
        fastcgi_read_timeout 150;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
    
    access_log  /var/log/access.log  main; //日志路径
    error_log  /var/log/error.log  notice; //错误日志路径
}

4、开启服务

systemctl start php-fpm
systemctl start nginx
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值