如何在 nginx 上安装 PHP 扩展?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8858598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install PHP extensions on nginx?
提问by samwell
I recently discovered NginX, and decided to try it out on my server. I have NginX running and able to serve PHP and HTML files. But now I want to try to install drupal. When trying to install it and check the requirements, I am stopped by one requirement.
我最近发现了 NginX,并决定在我的服务器上试用它。我有 NginX 运行并且能够提供 PHP 和 HTML 文件。但是现在我想尝试安装drupal。在尝试安装它并检查要求时,我被一项要求阻止了。
PHP extensions Disabled
Drupal requires you to enable the PHP extensions in the following list (see the system requirements page for more information):
gd
禁用 PHP 扩展
Drupal 要求您启用以下列表中的 PHP 扩展(有关更多信息,请参阅系统要求页面):
广东
I have tried to install gd by doing apt-get install php5-gd
, and it says it is already installed. So I created a phpinfo()
file, and checked to see if gd was enabled and I wasn't able to find it. Does this have to do with NginX or PHP? What do I do to fix this?
我尝试通过执行 安装 gd apt-get install php5-gd
,它说它已经安装了。所以我创建了一个phpinfo()
文件,并检查是否启用了 gd 并且我无法找到它。这与 NginX 或 PHP 有关系吗?我该怎么做才能解决这个问题?
回答by Xeoncross
Since you are using Nginx - that must mean you are running PHP with PHP-FPM.
由于您使用的是 Nginx - 这一定意味着您正在使用 PHP-FPM 运行 PHP。
After you install stuff you need to:
安装东西后,您需要:
sudo /etc/init.d/php-fpm restart
or
或者
service php5-fpm restart
in newer ubuntu versions
在较新的 ubuntu 版本中
so that PHP will pickup the new extensions.
这样 PHP 就会选择新的扩展。
回答by augusto
If your web server setup is in order, only install the php gd extension and restart php scripting interpreter and web server.
如果您的 web 服务器设置正常,只需安装 php gd 扩展并重新启动 php 脚本解释器和 web 服务器。
sudo apt-get install php5-gd
sudo /etc/init.d/php-fastcgi stop
sudo /etc/init.d/php-fastcgi start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start
Here's a great LEMP tutorial http://library.linode.com/web-servers/nginx/php-fastcgi/ubuntu-10.04-lucid
这是一个很棒的 LEMP 教程http://library.linode.com/web-servers/nginx/php-fastcgi/ubuntu-10.04-lucid
回答by Dominic Woodman
For future me if I forget this.
如果我忘记了这一点,对于未来的我。
If you've been messing around with /etc/php/fpm
then you may have accidentally lost the symlink to conf.d
which means the gd and PDO load files won't be booted with FPM.
如果您一直在搞乱,/etc/php/fpm
那么您可能不小心丢失了符号链接,conf.d
这意味着 gd 和 PDO 加载文件将无法使用 FPM 启动。
This will be an issue if you're just using the basic config that comes with PHP5-FPM. If you have a custom config you may included the files in a different place.
如果您只是使用 PHP5-FPM 附带的基本配置,这将是一个问题。如果您有自定义配置,您可以将文件包含在不同的位置。
Solution: Recreate the sym-link.
解决方案:重新创建符号链接。
cd /etc/php5/fpm
sudo ln -s /etc/php5/conf.d /etc/php5/fpm/conf.d
回答by Jacob Fike
PHP extensions have only to do with PHP. Your choice of webserver (apache, nginx, etc) do not affect them. Most likely you just need to enable the gd extension. If you are on Ubuntu, check /etc/php5/conf.d folder and add a gd.ini with the following line:
PHP 扩展只与 PHP 相关。您选择的网络服务器(apache、nginx 等)不会影响它们。很可能您只需要启用 gd 扩展。如果您使用的是 Ubuntu,请检查 /etc/php5/conf.d 文件夹并使用以下行添加 gd.ini:
extension=gd.so
回答by Keeprock
I encountered the same problem with making sudo apt-get install php5-gd
to work. Console output suggested to do sudo apt-get update
. Just basic updating on all your packages.
我在sudo apt-get install php5-gd
上班时遇到了同样的问题。控制台输出建议做sudo apt-get update
。只是对所有软件包进行基本更新。
After updating, I run sudo apt-get instal php5-gd
and it did all heavy lifting for me, including restarting php5-fpm and correctly installing everything in between.
更新后,我运行sudo apt-get instal php5-gd
它并为我完成了所有繁重的工作,包括重新启动 php5-fpm 并正确安装它们之间的所有内容。
回答by Lee Void
if you are using centos 7 and you can't find /etc/init.d/php-fpm, you may try systemctl restart php-fpm
, that worked for me.
如果您使用的是 centos 7 并且找不到 /etc/init.d/php-fpm,您可以尝试systemctl restart php-fpm
,这对我有用。