指定每个虚拟主机的PHP ini文件,FastCGI的/ PHP-FPM配置 [英] Specify PHP ini file per vhost, with FastCGI/PHP-fpm configuration

查看:587
本文介绍了指定每个虚拟主机的PHP ini文件,FastCGI的/ PHP-FPM配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,去稍微疯狂试图弄清楚这一点。 (我看过数以百计的问题/答案,而谷歌的文章,但没有回答吧)

Okay, going slightly crazy trying to figure this out. (I have read hundreds of questions/answers, and google articles, but none have answered it)

我刚刚从使用 mod_php的改为使用PHP的FastCGI通过FPM和使用中的<一个描述的方法href=\"http://askubuntu.com/questions/378734/how-to-configure-apache-to-run-php-as-fastcgi-on-ubuntu-12-04-via-terminal\">this问题,纯粹是因为我是IM pression下,这是容易来指定使用这种设置单独的虚拟主机的php.ini文件。

I have just changed from using mod_php to using PHP through FastCGI and fpm, using the method described in this question, purely because I was under the impression it was 'easy' to specify php.ini files for individual vhosts using this set-up.

什么我出过拉我的头发,是如何可以指定一个自定义的PHP ini文件中的每个虚拟主机使用?

What I'm pulling my hair out over, is how can I specify a custom PHP ini file each vhost uses?

幸运的是,这只是在我的测试平台,到目前为止...但我希望做同样的我的生产服务器上,如果我都不能算出这个

Luckily, It's only on my test rig so far ... But I am hoping to do the same on my production server if I can ever figure this out

推荐答案

我想我可能是井后整个过程中,我采取了与池配置FPM,如@ChristianM提到的,因为我还没有找到一个完整的解释如何做到这一点。

I thought I may as-well post the whole process I took to configure fpm with pools, as @ChristianM mentioned, because I've not yet found a full explanation on how to do it.

这第一部分主要是一个AskUbuntu后的副本:
<一href=\"http://askubuntu.com/questions/378734/how-to-configure-apache-to-run-php-as-fastcgi-on-ubuntu-12-04-via-terminal/527227#comment905702_527227\">http://askubuntu.com/questions/378734/how-to-configure-apache-to-run-php-as-fastcgi-on-ubuntu-12-04-via-terminal/527227#comment905702_527227

The first part of this is mostly a copy of an AskUbuntu post: http://askubuntu.com/questions/378734/how-to-configure-apache-to-run-php-as-fastcgi-on-ubuntu-12-04-via-terminal/527227#comment905702_527227

最后一部分是如何配置池,并获得虚拟主机使用培训相关池设置

The last part is how to configure pools, and get the vhost to use the relevent pool settings

下面有云:

http://www.vps.net/blog/2013/04/08/apache-mpms-$p$pfork-worker-and-event/

sudo apt-get install apache2-mpm-worker

安装的FastCGI和PHP5-FPM:

Install fastcgi and php5-fpm:

sudo apt-get install libapache2-mod-fastcgi php5-fpm

现在让你需要的器官功能障碍综合征,并禁用那些您不:

Now enable mods you need, and disable those you don't:

sudo a2dismod php5 mpm_prefork
sudo a2enmod actions fastcgi alias mpm_worker

创建php5.fcgi文件,并给使用它的网络服务器的权限。

Create the php5.fcgi file and give the webserver permission to use it.

sudo touch /usr/lib/cgi-bin/php5.fcgi
sudo chown -R www-data:www-data /usr/lib/cgi-bin

创建PHP5-FPM一个全局配置

Create a global config for php5-fpm

sudo nano /etc/apache2/conf-available/php5-fpm.conf

粘贴在下面(我们将使用一个插座,而不是IP地址)

paste in the following (we'll use a socket instead of IP address)

<IfModule mod_fastcgi.c> 
  AddHandler php5.fcgi .php 
  Action php5.fcgi /php5.fcgi 
  Alias /php5.fcgi /usr/lib/cgi-bin/php5.fcgi 
  FastCgiExternalServer /usr/lib/cgi-bin/php5.fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization -idle-timeout 3600 
  <Directory /usr/lib/cgi-bin>
    Require all granted
  </Directory> 
</IfModule>

请注意:确保所有的configs遵循相同的新的要求所有授予'/'要求所有被拒绝'语法......否则,你就重启后感到痛苦......

Note: Ensure all configs follow the same new 'Require all granted'/'Require all denied' syntax ... Otherwise you'll feel the pain after restarting ...

启用PHP5-FPM的conf

Enable the php5-fpm conf

sudo a2enconf php5-fpm

重新启动Apache和FPM

Restart apache and fpm

sudo service apache2 restart && sudo service php5-fpm restart

这实质上设置为创建一个PHP的全球FastCGI配置,其采用了文件/etc/php5/fpm/php.ini文件。

This setup essentially creates a global fastcgi configuration for php, which uses the file /etc/php5/fpm/php.ini file.

如果您有多个虚拟主机,这将需要不同的PHP配置,继续下面的

If you have multiple vhosts, that are going to need different php configurations, continue with the example below

首先,/etc/php5/fpm/pool.d目录中,你会发现默认的www.conf文件。复制此,将其命名为一些培训相关:

First, within the /etc/php5/fpm/pool.d dir, you will find the default www.conf file. Copy this, naming it something relevent:

sudo cp /etc/php5/fpm/pool.d/www.conf /etc/php5/fpm/pool.d/domain2.conf

编辑这个文件,更改池名称:

Edit this file, changing the pool name:

[...]

[domain2]

[...]

和改变监听套接字的名字的东西培训相关:

And change name of the listen socket to something relevent:

[...]

listen = /var/run/php5-fpm-domain2.sock

[...]

然后复制/usr/lib/cgi-bin/php5.fcgi文件,再次将其命名为一些培训相关:

Then copy the /usr/lib/cgi-bin/php5.fcgi file, again naming it something relevent:

cp /usr/lib/cgi-bin/php5.fcgi /usr/lib/cgi-bin/php5-domain2.fcgi

现在你已经准备好到的mod_fastcgi模块添加到DOMAIN2虚拟主机。这几乎与上述相同的所描述的,但要注意对于别名,FastCgiServer'和'-socket'

Now you're ready to add the mod_fastcgi module to the domain2 vhost. It's almost the same as the one described above, but notice the changes for 'Alias','FastCgiServer' and '-socket'

<VirtualHost *:80>
   ServerName domain2.com

   [...]

   <IfModule mod_fastcgi.c>
     AddHandler php5.fcgi .php
     Action php5.fcgi /php5.fcgi
     Alias /php5.fcgi /usr/lib/cgi-bin/php5-domain2.fcgi
     FastCgiExternalServer /usr/lib/cgi-bin/php5-domain2.fcgi -socket /var/run/php5-fpm-domain2.sock -pass-header Authorization -idle-timeout 3600
    <Directory /usr/lib/cgi-bin>
      Require all granted
    </Directory>
  </IfModule>

  [...]

</VirtualHost>

重新启动Apache和FPM

Restart apache and fpm

sudo service apache2 restart && sudo service php5-fpm restart

现在测试的变化。

在您的新/etc/php5/fpm/pool.d/domain2.conf文件,添加一个PHP价值变动(我选择了session.name值):

In your new /etc/php5/fpm/pool.d/domain2.conf file, add a php value change (I've chosen the session.name value):

[...]

php_admin_value[session.name] = 'DOMAIN2'

[...]

现在重新启动之前FPM测试配置:

Now test the configuration before restarting fpm:

sudo php5-fpm -t

如果配置失败,但更重要的是会告诉你,如果你的配置是好的它会告诉你。然后你就可以继续前进,重新启动FPM:

It will tell you if the configuration fails, but more importantly will tell you if your configuration is fine. Then you can go ahead and restart fpm:

sudo service php5-fpm restart

最后,如果你想成为超级确保PHP价值已定,您的网站中创建info.php的,并且只需添加:

And finally, if you want to be super sure the php value has been set, create info.php within your site, and just add:

<?php
  phpinfo();
?>

这篇关于指定每个虚拟主机的PHP ini文件,FastCGI的/ PHP-FPM配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆