Jwags
Jwags

Reputation: 502

Centos 7 Apache How to allow custom php.ini files

I have a VPS running Apache and CentOS 7. I am trying to use a custom php.ini file in my website directory, /var/www/my-website.com/public_html/php.ini, but my website wont load it. If I do a phpinfo() page it says that, Loaded Configuration File = /etc/php.ini. Is there a configuration setting I have to change to allow for custom php.ini files to be loaded?

I guess what my goal is that if there is a php.ini file in a web directory it will override "/etc/php.ini" and use the custom one, in this case, "/var/www/my-website.com/public_html/php.ini"

Upvotes: 2

Views: 6686

Answers (1)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

It's not 100% working solution, but try to go the following steps:

  • Copy generic php.ini file to your /var/www/my-website.com folder:

    cp /etc/php.ini /var/www/my-website.com/
    
  • Edit your custom php.ini file as you want and save it

  • Locate apache configuration file httpd.conf and find VirtualHost section that relates to your local domain my-website.com

  • Add PHPINIDir directive to the above section:

    <VirtualHost *:80>
     DocumentRoot /var/www/my-website.com/public_html
     ServerName www.my-website.com
     ServerAlias my-website.com
     PHPINIDir /var/www/my-website.com 
     ErrorLog /etc/var/www/my-website.com/error.log
     CustomLog /var/www/my-website.com/requests.log
    </VirtualHost> 
    
  • Restart Apache web-server and check results:

    /etc/init.d/httpd restart
    

Upvotes: 2

Related Questions