Nginx解析PHP

安装nginx

sudo apt install nginx

添加配置文件

a 新建/etc/nginx/sites-available/配置文件.conf
	server {
	    listen 80;
	    listen [::]:80;
	    root 网站目录;
	    index  index.php index.html index.htm;
	    server_name 网站域名;
	
	    client_max_body_size 100M;
	
	    location / {
	        try_files $uri $uri/ /index.php?$args;        
	    }
	
	    location ~ \.php$ {
	    include snippets/fastcgi-php.conf;
	    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
	    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
	    }
	}
b. 创建php.conf的链接至/etc/nginx/sites-enabled/
	sudo ln -s /etc/nginx/sites-available/配置文件.conf  /etc/nginx/sites-enabled/

重启nginx服务

sudo nginx -s reload

安装PHP

sudo apt install php-fpm php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-ldap php-zip php-curl

启动PHP服务

a. 
    sudo systemctl start php7.2-fpm
b. 
    sudo systemctl enable php7.2-fpm

创建网站目录,并为nginx赋予权限

nginx的账户为www-data,需要为其赋予权限(一般为755)

sudo chown www-data:空格 网站目录

测试

在网站目录内新建简单PHP文件index.php,并浏览器访问

<?PHP
	echo "HELLO"
?>
posted @ 2020-03-15 15:23  mousecode  阅读(537)  评论(0编辑  收藏  举报