One PHP installation with multiple php.ini files [

2019-09-01 05:05发布

问题:

This question already has an answer here:

  • How do I include a php.ini file in another php.ini file? 7 answers

I am trying to configure php installation to use multiple php.ini Is this it feasible?

Thanks,

回答1:

TL;DR Add PHPIniDir to Apache conf file and ensure that folder contains a version of php.ini suited to your requirements.

A little more information would be required to ensure a full answer, but I'll make an assumption and take it that you're working with a LAMP server, and require making a custom PHP.ini for each server hosted under Apache (vhost). If so, it's a simple procedure for having one (Apache) server host multiple vhosts and each vhost having it's own php.ini file.

  1. Create your new vhost, with it's own folder (assuming /var/www/vhostA)
  2. Create the html folder (housing the document root) in /var/www/vhostA/html
  3. Copy your existing php.ini file (typically /etc/php5/apache2/php.ini) to /var/www/vhostA/php.ini
  4. Edit the php.ini (as per 3) as you require it for vhostA's purposes
  5. Edit the vhost configuration file and add PHPIniDir /var/www/vhostA
  6. Restart Apache

An example Apache vhost configuration file would (therefore) read something like this:

<VirtualHost 1.2.3.4:80>
    DocumentRoot /var/www/vhostA/html
    <Directory "/var/www/vhostA/html">
        Options -Indexes
    </Directory>
    PHPINIDir /var/www/web1
    ErrorLog ${APACHE_LOG_DIR}/vmhostA-error.log
    CustomLog ${APACHE_LOG_DIR}/vmhostA-access.log combined
</VirtualHost>