编辑。
问题已经在这里得到了答案:https :
//serverfault.com/questions/889334/cant-get-nginx-to-run-php-on-ubuntu-16-04-server
我正在设置一个运行 nginx 的服务器,我试图让它运行 php 脚本。
显然,关于如何让 nginx 运行 php 的最伟大的文章是这篇:https : //www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in- ubuntu-16-04
随着其他方向的老化,以下讨论就此结束。
在 nginx 上启用 PHP 的最简单方法是什么?
我按照数字海洋网站上的指示走,但没有任何变化,我仍然无法运行 php。
我对此非常迷茫,任何帮助将不胜感激。
这是输出sudo service nginx status:
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2017-12-17 13:46:33 GMT; 55min ago
Process: 19056 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 19091 ExecReload=/usr/sbin/nginx -g daemon on; …Run Code Online (Sandbox Code Playgroud) 我刚刚在 Ubuntu 18.04 服务器上安装了 LAMP,但我无法让 PHP fastcgi 工作。这是我的设置:
我的 fpm PHP 文件:/etc/php/7.2/fpm/pool.d/sites.mydomain.conf
[sites.mydomain]
...
user = sites
group = sites
...
listen = /run/php/php7.2-fpm.sites.mydomain.sock
...
listen.owner = www-data
listen.group = www-data
Run Code Online (Sandbox Code Playgroud)
然后
sudo service php7.2-fpm reload
sudo service php7.2-fpm restart
Run Code Online (Sandbox Code Playgroud)
我的虚拟主机文件:etc/apache2/sites-available/sites.mydomain.conf
ServerName sites.mydomain
ServerAdmin webmaster@localhost
DocumentRoot /srv/www/sites/html
<IfModule mod_fastcgi.c>
AddHandler php7-fcgi-sites .php
Action php7-fcgi-sites /php7-fcgi-sites
Alias /php7-fcgi-sites /usr/lib/cgi-bin/php7-fcgi-sites
FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi-sites -idle-timeout 60 -socket /var/run/php/php7.2-fpm.sites.mydomain.sock -pass-header Authorization
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
<Directory /srv/www/sites/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride …Run Code Online (Sandbox Code Playgroud) 通过调整来自这个 askubuntu 线程、这个 HowtoForge 文档和这个 Digital Ocean 教程的说明,我已经设法让 FastCGI 在 Ubuntu 16.04 上与 Apache 2.4 一起工作。
所有这些消息来源都说要创建 /etc/apache2/conf-available/php7.0-fpm.conf并告诉您要放入什么。但是安装后php-fpm,我已经有了那个文件,内容如下:
# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php7.c>
# Enable http authorization headers
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
</FilesMatch>
<FilesMatch ".+\.phps$">
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in …Run Code Online (Sandbox Code Playgroud)