How to set custom php.ini location in lighttpd? - php

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 ?

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

Related

puphpet install wordpress on ubuntu server

I am wondering if anyone has attempted to automate the deployment of wordpress and puphpet.
I am not to familiar with puphpet but I know it uses the hiera.yaml file along with the manifets and modules folder. I attempted something simple
I added this to config.yaml file and imported the wordpress module from vagrant press
wordpress:
install: '1'
It looks like I may need to add something to the main manifest.pp file that puphpet generates. If anyone has attempted something like this I would appreciate any advice. Or is it better to just use yeoman instead?
Update
I add this to the config.yaml file
wordpress:
install: '1'
Then in the manifest.pp file I added this at the bottom form (wordpress vagrant box) and it seems to work:
# Begin wordpess
if $wordpress_values == undef {
$wordpress_values = hiera('wordpress', false)
if hash_key_equals($wordpress_values, 'install', 1) {
# Download WordPress
exec {"download_wordpress":
command => "wget http://wordpress.org/latest.tar.gz",
cwd => "/tmp",
creates => "/tmp/latest.tar.gz",
path => ["/usr/bin", "/bin", "/usr/local/bin"],
unless => "test -f /var/www/index.php",
}
# Extract WordPress
exec {"extract_wordpress":
command => "tar xzf /tmp/latest.tar.gz",
cwd => "/tmp",
creates => "/tmp/wordpress",
path => ["/usr/bin", "/usr/local/bin", "/bin"],
require => Exec["download_wordpress"],
unless => "test -f /var/www/index.php",
}
# Install WordPress
exec {"install_wordpress":
command => "cp -r /tmp/wordpress/* /var/www/wordpress",
cwd => "/tmp",
path => ["/usr/bin", "/usr/local/bin", "/bin", "/usr/local/sbin", "/usr/sbin", "/sbin"],
require => Exec["extract_wordpress"],
unless => "test -f /home/www/index.php",
}
}
}
PuPHPet uses hiera but not in the traditional Puppet way. You still need to actually create the Puppet code that interacts with the hiera values.

How to populate SCRIPT_FILENAME and SCRIPT_PATH server vairables to php-cgi from the command line

I'm trying to run cron php script from command line. The server does not have PHP CLI but php-cgi exists. I tried to pass PHP directly to php-cgi but this does not work because two server environment variables are missed ($_SERVER['SCRIPT_FILENAME'] and $_SERVER['SCRIPT_PATH']). I tried to fill variables using following recommendation but these variables are not populated. What is missed in this answer? How to make php-cgi populate these server values? The question is not platform specific, but execution script looks like this currently
#!/bin/bash
export REDIRECT_STATUS=200
export GATEWAY_INTERFACE="CGI/1.1"
export SCRIPT_FILENAME=/usr/local/www/owncloud/cron.php
export REQUEST_METHOD="GET"
/usr/local/bin/php-cgi
Please note that I'm not asking for workaround, I already added helper php file which fill necessary values. But this is temporary solution because next software update could show another issue with php-cgi call
UPDATE
It seems the issue is not with php-cgi execution but with the SCRIPT_FILENAME and SCRIPT_PATH server variables only. So solution works in common cases when you do not need them. Also the issue might be version specific (it works with PHP version prior to 5.5) or platform specific
I searched SO with question to these specific server variables and found following statement here:
You are just juggling variables now. SCRIPT_FILENAME is a part of the
CGI spec. It will not be available if PATH_INFO is unavailable. As for
REQUEST_URI, it's apache's mod_rewrite specific. – LiraNuna
So exporting PATH_INFO variable also populates values from SCRIPT_FILENAME and SCRIPT_PATH environment variables. Please note that SCRIPT_FILENAME is needed still to point php-cgi to php input file. Below is the final script
#!/bin/bash
export REDIRECT_STATUS=200
export GATEWAY_INTERFACE="CGI/1.1"
export REQUEST_METHOD="GET"
export SCRIPT_FILENAME=/usr/local/www/owncloud/cron.php
export SCRIPT_PATH=cron.php
export PATH_INFO=$SCRIPT_FILENAME
/usr/local/bin/php-cgi
Here is what i tested. i used root account on my home PC. My IP is masked from the output. cannot post this much as comment so posting as answer.
The script
#!/bin/bash
export REDIRECT_STATUS=200
export GATEWAY_INTERFACE="CGI/1.1"
export SCRIPT_FILENAME=/root/t.php
export REQUEST_METHOD="GET"
/usr/bin/php-cgi
PHP file
<?php
print_r($_SERVER);
?>
Output I get
X-Powered-By: PHP/5.3.8
Content-type: text/html
Array
(
[HOSTNAME] => HomePC
[SELINUX_ROLE_REQUESTED] =>
[SHELL] => /bin/bash
[TERM] => xterm
[HISTSIZE] => 1000
[SSH_CLIENT] => xx.xx.xx.xx 58196 22
[SELINUX_USE_CURRENT_RANGE] =>
[SSH_TTY] => /dev/pts/3
[USER] => root
[LS_COLORS] => rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
[SCRIPT_FILENAME] => /root/t.php
[PATH] => /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[MAIL] => /var/spool/mail/root
[PWD] => /root
[LANG] => en_US.UTF-8
[REDIRECT_STATUS] => 200
[SELINUX_LEVEL_REQUESTED] =>
[HISTCONTROL] => ignoredups
[HOME] => /root
[SHLVL] => 2
[LOGNAME] => root
[SSH_CONNECTION] => xxx.xxx.xx.xxx 58196 192.168.1.2 22
[GATEWAY_INTERFACE] => CGI/1.1
[LESSOPEN] => ||/usr/bin/lesspipe.sh %s
[REQUEST_METHOD] => GET
[G_BROKEN_FILENAMES] => 1
[_] => /usr/bin/php-cgi
[PHP_SELF] =>
[REQUEST_TIME] => 1379952948
)

php custom C++ module works from command line, not on webserver

I made a custom PHP module with C++ and Swig. It works from the command line, but not with my webserver:
php index.php
php-cgi index.php
Both of those work fine.
I'm using lighttpd and php. I didn't configure these in any special way. I just installed them using sudo apt-get install.
Unfortunately if I make a webpage I get this:
Fatal error: Call to undefined function minikey_to_wif() in /var/www/index.php on line 6
Calling function_exists("minikey_to_wif") returns False too.
The phpinfo() does not show my module called minikey, and shows the same configuration path as the file I edited (/etc/php5/cgi/php.ini):
extension=/path/to/php-ext/minikey/minikey.so
I also tried copying it to where the other PHP extensions seem to be installed (/usr/lib/php5/20090626+lfs/) but that didn't work either.
I've been stopping, and starting lighttpd countless times. Each time, when I run ps aux | grep php, there are no results. I've also rebooted a few times to no effect. I have no idea what's up.
OK found the answer.
The extension relied on a library which was installed in a non-standard location. Normally I set LD_LIBRARY_PATH in ~/.bashrc. But when the web server ran the extension, it didn't have that environment variable.
Fix was to create a file in /etc/ld.so.conf.d/genjix.conf with /home/genjix/usr/lib and run ldconfig as root.
Try running phpinfo() using lighty. Make sure that its pointing to the correct php.ini.
If you think this is the problem you can launch php using the -c switch from inside lighttpd.conf with "bin-path" => "/path/to/php-cgi -c /path/to/php.ini":
e.g.
fastcgi.server = (
".php" => (
(
"bin-path" => "/path/to/php-cgi -c /path/to/php.ini",
"socket" => "/tmp/php.socket",
"max-procs" => 4,
"idle-timeout" => 30,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "1000"
)
)
)
)

PHP extension works from browser not from CMD

I'm still struggling integrate APC with EasyPHP for testing Doctrine + CI.
Installed APC
configured php.ini
see it in phpinfo()
Added this to my php.ini :
[APC]
apc.shm_segments=1
apc.optimization=0
apc.shm_size=128
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.enable_cli=1
created a test file test.php :
<?php
print_r(apc_sma_info());
?>
accessing with browser (getting result on screen) :
Array ( [num_seg] => 1 [seg_size] => 33554368 [avail_mem] => 33237360 [block_lists] => Array ( [0] => Array ( [0] => Array ( [size] => 33237336 [offset] => 317048 ) ) ) )
running from command prompt : D:\devl\EasyPHP-5.3.5.0\www>php test.php
Fatal error: Call to undefined function apc_sma_info() in D:\devl\EasyPHP-5.3.5.
0\www\test.php on line 2
any ideas why?
I do not know EasyPHP - but there are often different php.ini files for Apache and Cli...
Please check this first for your WAMP stack.
apache and CLI may have different php.ini files, so check which is the loaded php.ini in the cli environment.

PHP fastcgi returns 403 on Lighttpd server

I've been agonizing over this issue for the past day now. I've setup lighty on my server and it serves static files fine but keeps giving me 403 on php files.
I've gone through every tutorial, wiki and forum that I can find on the subject and nothing helped.
I've chown lighttpd:lighttpd the php files and chmod to 644 and 755. I really need some help here.
Here is a link to my *.conf files:
http://174.122.151.65/lighttpd/
BTW, I'm running on a centOS box.
Thanks.
It looks like you are missing the fastcgi.server section of your lighttpd.conf file
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/bin/php-cgi"
)
)
)
If that doesn't work, try:
sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php
Worked for me.

Categories