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

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"
)
)
)
)

Related

Different $_SERVER output when running from command line or system()

If have these very simple scripts:
foo.php:
<?php
system("php -c /etc/php7/cli/php.ini /some-path/exec.php");
?>
exec.php:
<?php
print_r($_SERVER);
?>
Running exec.php from command line I get the expected output for $_SERVER:
...
[LESSKEY] => /etc/lesskey.bin
[NNTPSERVER] => news
[MANPATH] => /usr/share/man:/usr/local/man:/usr/local/share/man
[XDG_SESSION_ID] => 2
[HOSTNAME] => AAEB-DEV203LD
[XKEYSYMDB] => /usr/X11R6/lib/X11/XKeysymDB
[HOST] => AAEB-DEV203LD
[TERM] => linux
[SHELL] => /bin/bash
...
When exec.php is executed by the system function in the foo.php script called in a browser tab then the output for $_SERVER is totally different and it looks more or less exactly like the Environment section from phpinfo():
...
[APACHE_CONF_INCLUDE_FILES] =>
[mpm_found] => true
[APACHE_CONF_INCLUDE_DIRS] =>
[SYSCONFIG_FILE] => /etc/sysconfig/apache2
[APACHE_START_TIMEOUT] => 2
[HTTPD_MODULE_IDS] => actions_module alias_module ...
[APACHE_SERVERNAME] =>
...
What is the problem:
In the $_SERVER output - running via system() function - there is missing lot of information which we need.
I didn't find anything in the Internet which can give me a hint why the output differs so much.
OS: SLES 12.3
PHP: 7.2.10
Apache: 2.4 MPM
My question:
Why does the output differ so much when running under command line and system() within the Apache session and can I get the same output for the system() function when calling exec.php from the command line with php -c /etc/php7/cli/php.ini /some-path/exec.php?
Good. I could sort it out how it works, it wasn't clear to me.
Running php from command line PHP sets into $_SERVER all exported environment variables. Therefore $_SERVER has the entry HOSTNAME.
Running exec() from a script which is executed in a browser tab PHP sets $_SERVER with the content of Environment section as displayed by phpinfo().
When I want to have set the entry HOSTNAME in $_SERVER I have to call putenv("HOSTNAME=value"); before exec().

cannot get lighttpd configured to PHP 7

Apart from logging to the wrong file (the error log defined for that vhost defined last),
lighty does not let me use PHP 7. What am I missing?
cgi.fix_pathinfo is enabled in /etc/php/7.0/fpm/php.ini.
How can I make sure you're using the FastCGI-enabled version? What else should I look for?
version info (shrinked to the necessary)
> lsb_release -a
Description: Ubuntu 16.04.1 LTS
Codename: xenial
> lighttpd -v
lighttpd/1.4.35 (ssl) - a light and fast webserver
Build-Date: Apr 18 2016 15:36:10
> php -v
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
> php-cgi -v
PHP 5.6.23-1+deprecated+dontuse+deb.sury.org~trusty+1 (cgi-fcgi)
> php-fpm7.0 -v
PHP 7.0.8-0ubuntu0.16.04.3 (fpm-fcgi)
lighty config file excerpt
> head -41 /etc/lighttpd/lighttpd.conf | tail -9
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "1000"
),
"broken-scriptfilename" => "enable"
)))
tryouts
If I change the socket to an invalid path, restarting lighttpd works fine; but the server is unreachable. (bind failed for: (invalid path) in the error log); so this seems like the correct config file.
Modifying /etc/lighttpd/conf-available/15-fastcgi-php.conf in the same way has no effect at all.
Changing the socket to "/var/run/php/php7.0-fpm.sock" has no effect either (php_info() still says PHP 5.6 after restarting lighty).
After changing bin-path to /usr/sbin/php-fpm7.0 , I still get no error when restarting lighttpd, but the web server is unreachable.
error log excerpt
> tail /var/log/lighttpd/error.log
(no output)
> tail /var/log/lighttpd/somevhost/error.log
2016-10-10 16:48:02: (log.c.164) server started
2016-10-10 16:48:02: (mod_fastcgi.c.1112) the fastcgi-backend /usr/sbin/php-fpm7-0 failed to start:
2016-10-10 16:48:02: (mod_fastcgi.c.1116) child exited with status 2 /usr/sbin/php-fpm7-0
2016-10-10 16:48:02: (mod_fastcgi.c.1119) If you're trying to run your app as a FastCGI backend, make sure you're using the FastCGI-enabled version.
If this is PHP on Gentoo, add 'fastcgi' to the USE flags.
2016-10-10 16:48:02: (mod_fastcgi.c.1406) [ERROR]: spawning fcgi failed.
2016-10-10 16:48:02: (server.c.1022) Configuration of plugins failed. Going down.
update
I just uninstalled php5 hoping this would resolve the issues; but that didnĀ“t help either. Instead, I seem to have no way to get php5 back.
Tried a search engine?
https://www.google.com/?gws_rd=ssl#q=lighttpd+ubuntu+php+7
The first hit:
https://www.howtoforge.com/tutorial/installing-lighttpd-with-php7-php-fpm-and-mysql-on-ubuntu-16.04-lts/
suggests
## Start an FastCGI server for php (needs the php7.0-cgi package)
fastcgi.server += ( ".php" =>
((
"socket" => "/var/run/php/php7.0-fpm.sock",
"broken-scriptfilename" => "enable"
))
)
to go along with php.ini cgi.fix_pathinfo=1
You can follow the instructions on the page above to have Ubuntu run php7.0-fpm as a service, or you can configure lighttpd to start up the fastcgi.server backend by setting "bin-path" in the fastcgi.server definition, but do not do both.

How to get php readline() to default to Vim mode?

This is on CentOS 7.2, PHP version 5.6.20. According to readline_info():
<?php
print_r(readline_info());
gives
Array
(
[line_buffer] =>
[point] => 0
[end] => 0
[library_version] => EditLine wrapper
[readline_name] =>
[attempted_completion_over] => 0
)
OK, so readline() is using EditLine. I created a ~/.editrc file with:
bind -v
The permission is 664. I then tried:
<?php
$line = readline('Enter: ');
But it doesn't seem to read the file, and it's not in Vim mode. Doing an Alt-X followed by a manual command of "bind -v" puts it in Vim mode, so I know it has Vim mode.
I read somewhere else that I might need to manually set the path in an environment variable. So tried setting the full path:
$ export EDITRC=/home/work/.editrc
Still nothing. I've also seen that "export EL_EDITOR=vi" is supposed to work, but still doesn't work.
Does anyone have any way to make this work? I really need Vim mode to work.

php cannot load pecl http extension

I have installed pecl_http on a PLESK server (which seems to be successful) but for some reason, the http extension will not load into PHP.
var_dump(extension_loaded("http"));
gives me bool(false).
pecl info pecl_http gives me a lot of info and if I run php -me http is also listed.
php -i | grep "http_request" gives me:
http_request => N/A => 0 => 0
http_request_datashare => GLOBAL => 1 => 0
http_request_pool => N/A => 0 => 0
and if I run pecl run-tests -p pecl_http I get a lot of FAILs
and I am also getting
Fatal error: Call to undefined function http_get()
http.so is located inside /usr/lib/php/modules/ which is also defined as the extension dir in php.ini - all other extensions loads fine.
What have I missed?
What happens if change
enable_dl = Off
to
enable_dl = On
in php.ini and run
php -r "dl('http.so');"
?

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