PHP difference between terminal and browser - php

There is Neo4J installed on my Ubuntu and I'm running a test code. It's perfectly working when the code runs on terminal such as:
root#ekin-Inspiron-1090:/var/www# php neo.php
home: demolished
name: Arthur Dent
But when it comes to run on browser like localhost/neo.php, it gives fatal error and stops working.
Warning: require(phar://neo4jphp.phar): failed to open stream: operation failed in /var/www/neo.php on line 4 Fatal error: require(): Failed opening required 'phar://neo4jphp.phar' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/neo.php on line 4
I don't think it's really something with Neo4J or its PHP driver. What should be the reason?
edit: by the way, there are two php.ini files; i think one for apache and one for command line. I checked both of them and phar extension paths are the same. Also there are no include_path settings in both of them.

It's an authorization error. Apache runs under its own user, so you need to give apache user to access www folder.

Related

php-fpm - enabling it causes Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0

I am running into an error while attempting to enable php-fpm so that I can have multiple versions of php running on several different domains on one Apache Ubuntu 20 server.
I initially followed these directions: https://www.digitalocean.com/community/tutorials/how-to-run-multiple-php-versions-on-one-server-using-apache-and-php-fpm-on-ubuntu-18-04
But it didn't seem to use php-fpm as seen by phpinfo(); Instead, it was still running php (the regular one).
Then I found these instructions: https://techexpert.tips/apache/apache-php-fpm-installation-ubuntu-linux/
This seemed to work (in theory) by disabling regular php.
But now even phpinfo(); doesn't work, which is in a file called 'info.php'. It contains contains only:
<?php
phpinfo();
?>
I get:
"
Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required '/home/traini61/public_html/guacamole.org/wordfence-waf.php' (include_path='.:/usr/share/php') in Unknown on line 0
"
I don't understand the error. I tried disabling the 'wordfence' plugin referenced in the error then tried again but it failed in exactly the same way. I've had to run the 2nd set of directions backwards to restore the website.
Also, is there a simpler commandline program that can provide a text-GUI to more easily administer which versions of PHP are assigned to a specific domain in an apache multi-domain configuration?

PHP Error "Unknown: failed to open stream... in Unknown on line 0..." when editing php files

I get a strange php error:
2022-03-14 10:52:19: (mod_fastcgi.c.421) FastCGI-stderr: PHP message:
PHP Warning: Unknown: failed to open stream:
No such file or directory in Unknown on line 0
PHP message: PHP Fatal error: Unknown: Failed opening required
'var/www/vhosts/webdev/sites/test/hello.php'
(include_path='.') in Unknown on line 0
Long explanation:
I create a file hello.php in my webroot, having the content:
<?php echo("hello"); ?>
I run this file in a browser, all is fine, it shows "hello"
Now I edit this file so the content now is:
<?php echo("hello"); echo("world"); ?>
I run this edited file in a browser => The error is shown
I reload the page (F5 or ctrl-R) => all is working fine now
In other words:
Whenever I edit a php file and try to run it in a browser, I get this error message. After reloading the page it works!
That is the real strange thing, after reloading everything is working fine!!!
My config
a local raspberry pi running raspbian
webserver: lighttpd (standard install from repo)
php7.3-fpm (standard install from repo)
all file permissions in my web dev folder are 775, all files are www-data:www-data owned
NO selinux running (like in other answers suggested)
the php.ini is pretty much untouched, some options:
auto_prepend_file =
auto_append_file =
include_path = "."
there are no other hidden config files in the folder
With html files there are no problems. So it must be a php-fpm problem.
I am out of ideas now. It might be a very easy fix, but I am not a Pro.
Any ideas how to fix this?
In the error log, the path doesn't start with a slash "/"
var/www/vhosts/webdev/sites/test/hello.php
which indicates a misconfiguration in lighttpd/fastcgi configuration
Fixing the path should make everything work correctly.

PHP Installed in IIS, but showing error while running codeigniter

I have installed PHP and MySQL on IIS Server. It's giving this error.
Warning: include(D:***\application\views\errors\html\error_php.php): Failed to open stream: No such file or directory in D:\CANONICA\system\core\Exceptions.php on line 268
Warning: include(): Failed opening 'D:***\application\views\errors\html\error_php.php' for inclusion (include_path='.;C:\php\pear') in D:\CANONICA\system\core\Exceptions.php on line 268
Tried enabling all extensions also.
Installed PHP version 8.0
Database Getting connected and getting inserted also, but the above warnings are showing at the top of the page.
Tried with the empty controller, then also showing the same. anybody of you knows this to sort out?
If setting the permission in IIS publisher, then it will work.
When we are setting the domain inside IIS, grant all required permissions. then this error will not show.

Calling php with python subprocess.call generates php permissions errors

Trying to run php tests with python script.
Using codeception framework, which is successfully works when i'm executing it manually in terminal. But it generates permission issues when i'm trying to call it with subprocess.call like that
subprocess.call(['vendor/bin/codecept', 'run'])
Errors like
PHP Warning: require_once(/root/opt/testing/vendor/bin/autoload.php): failed to open stream: Permission denied in /root/opt/testing/vendor/bin/codecept on line 7
PHP Fatal error: require_once(): Failed opening required '/root/opt/testing/vendor/bin/autoload.php' (include_path='.:/usr/share/php') in /root/opt/testing/vendor/bin/codecept on line 7
Can't find the reason why. Changed all permissions to chmod a+x but still no results.
Looks like it definitely something with python.

Pear Packages not working

I've been trying to use a few PEAR packages for a few hours now to no avail. PEAR itself is functioning, and I believe I set all of the configuration variables correctly, but when I try to run any of my packages from the command line, I get PHP errors telling me the required file wasn't found. For example, with phpdoc:
$ phpdoc
PHP Warning: require(PhpDocumentor/phpDocumentor/phpdoc.inc): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/pear/bin/phpdoc on line 40
Warning: require(PhpDocumentor/phpDocumentor/phpdoc.inc): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/pear/bin/phpdoc on line 40
PHP Fatal error: require(): Failed opening required 'PhpDocumentor/phpDocumentor/phpdoc.inc' (include_path='.:/Applications/MAMP/bin/php5.2/lib/php') in /Applications/MAMP/htdocs/pear/bin/phpdoc on line 40
Fatal error: require(): Failed opening required 'PhpDocumentor/phpDocumentor/phpdoc.inc' (include_path='.:/Applications/MAMP/bin/php5.2/lib/php') in /Applications/MAMP/htdocs/pear/bin/phpdoc on line 40
I tried manually editing the files, inserting the absolute path to the files, but when I correct one require error a new one just comes up.
This is my pear.conf:
#PEAR_Config 0.9
a:15:{s:10:"__channels";a:2:{s:12:"pecl.php.net";a:0:{}s:5:"__uri";a:0:{}}s:15:"preferred_state";s:6:"stable";s:8:"temp_dir";s:35:"/Applications/MAMP/htdocs/pear/temp";s:7:"bin_dir";s:34:"/Applications/MAMP/htdocs/pear/bin";s:7:"php_dir";s:35:"/Applications/MAMP/htdocs/pear/PEAR";s:7:"doc_dir";s:40:"/Applications/MAMP/htdocs/pear/PEAR/docs";s:8:"data_dir";s:40:"/Applications/MAMP/htdocs/pear/PEAR/data";s:8:"test_dir";s:41:"/Applications/MAMP/htdocs/pear/PEAR/tests";s:9:"cache_dir";s:41:"/Applications/MAMP/htdocs/pear/PEAR/cache";s:9:"cache_ttl";i:300;s:12:"download_dir";s:44:"/Applications/MAMP/htdocs/pear/temp/download";s:10:"http_proxy";s:0:"";s:7:"ext_dir";s:74:"/Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20050922";s:7:"php_bin";s:37:"/Applications/MAMP/bin/php5.2/bin/php";s:10:"sig_keydir";s:39:"/Applications/MAMP/conf/php5.2/pearkeys";}
I'm using MAMP PRO v1.9.5 on Mac OS 10.7.5 with PHP v5.2.17. Also, I installed the packages with the PEAR web interface package manager. If any further information is required, please let me know and I'll post it.
Make sure that the include path contains the folder where PEAR installs php class files. Check your include_path ini setting. It should look like:
include_path=".:PEAR_CLASSES_PATH"
where PEAR_CLASSES_PATH is the pear class path

Categories