Squidward
Squidward

Reputation: 131

How to set custom php.ini location in lighttpd?

By default my php.ini is located at /etc/php.ini and I want to move it to /tmp/ab/etc/php.ini. In /etc/lighttpd/lighttpd.conf I've tried to set the following configuration:

#### CGI module
cgi.assign = ( ".pl"  => "/usr/bin/perl", ".cgi" => "/usr/bin/perl", ".py"  => "/usr/bin/python", "cgi-bin/luci" => "", ".php"  => "/usr/bin/php-cgi -c /tmp/ab/etc/php.ini", "sms_gateway" => "/bin/bash", "cgi-bin/check" => "/bin/sh", "cgi-bin/remove" => "/bin/sh", "cgi-bin/date" => "/bin/sh" )

Please take a look at this part: ".php" => "/usr/bin/php-cgi -c /tmp/ab/etc/php.ini"

But after I do that and restart lighttpd and I try to check the location of php.ini with:

<?php
phpinfo();
?>

I get 500 - Internal Server Error on my browser. How can I do this ?

Upvotes: 2

Views: 2320

Answers (1)

gstrauss
gstrauss

Reputation: 2369

One solution is to create a wrapper script /tmp/ab/bin/my-php-cgi and put that in lighttpd.conf cgi.assign = ( ".php" => "/tmp/ab/bin/my-php-cgi" )

#!/bin/sh
exec /usr/bin/php-cgi -c /tmp/ab/etc/php.ini

Depending on the PHP version you are using you might also look into having lighttpd.conf setenv.add-environment = ( "PHPRC" => "/tmp/ab/etc/php.ini" ) See also How to change the path to php.ini in PHP CLI version

Upvotes: 2

Related Questions