Php error (ambigious) [duplicate] - php

I edited the apache httpd.conf file recently for the mod_rewrite to work. I don't know if this problem originated from that or not, but i'm getting this problem from that day.
This is what I see on the frontend when I run the software -
Server error The website encountered
an error while retrieving
http://localhost/prestashop/. It may
be down for maintenance or configured
incorrectly.
There is no specific file that triggers this. But I saw that usually small programs that consists of 4-5 php files, runs fine, but softwares with a lot of files(like PrestaShop) don't.
I checked the logs and this is what I found.
[Wed Mar 16 19:33:39 2011] [error] [client ::1] PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
[Wed Mar 16 19:33:39 2011] [error] [client ::1] PHP Fatal error: Unknown: Failed opening required '/var/www/html/yomig/index.php' (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0
[Wed Mar 16 19:33:39 2011] [error] [client ::1] File does not exist: /var/www/html/favicon.ico
[Wed Mar 16 19:33:41 2011] [error] [client ::1] PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
[Wed Mar 16 19:33:41 2011] [error] [client ::1] PHP Fatal error: Unknown: Failed opening required '/var/www/html/yomig/index.php' (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0

Experienced the same error, for me it was caused because on my Mac I have changed the DocumentRoot to my users Sites directory.
To fix it, I ran the recursive command to ensure that the Apache service has read permissions.
sudo chmod -R 755 ~/Sites

If you are running Fedora, make sure SELinux is not interfering.You fix this with this command:
sudo /sbin/restorecon -R /var/www/
More info here: linuxquestions.org/questions/linux-server-73/

I had the same error and my problem was the file permissions were incorrect.
chmod 755 index.php
worked for me.

It is a SELinux blocking issue, Linux prevented httpd access. Here is the solution:
# restorecon '/var/www/html/wiki/index.php'
# restorecon -R '/var/www/html/wiki/index.php'
# /sbin/restorecon '/var/www/html/wiki/index.php'

Here some guide how to fix it. Go to :
cd /var/www
sudo chown www-data:www-data * -R
sudo usermod -a -G www-data username
Change userneme with your username. I hope it help.

I got this problem when insert wrong file address into .htaccess
php_value auto_prepend_file "/home/user/wrong/address/config.php"
So if you use auto_prepend_file check your file path. It called from .htaccess so PHP can't determine error file and line.

In my mind true way is:
# add READ permission to all directories and files under your DocumentRoot
sudo chmod +r /path/to/DocumentRoot/ -R
# add EXECUTE permission to all DIRECTORIES under your DocumentRoot
find /path/to/DocumentRoot/ -type d -exec chmod +x {} \;

I just came across of this same problem and in my case it was caused by selinux. Disabling it solved the issue. And no, I don't need selinux on my workstation, thank you.

It happened to me today with /home/user/public_html/index.php and the solution was to do chmod o+x /home/user as this directory has to have the X as otherwise the apache server can't list files (i.e. do ls)

This also happens (and is particularly confounding) if you forgot that you created a Windows symlink to a different directory, and that other directory doesn't have appropriate permissions.

Just quote for above answer of user1992554
This one worked perfectly for me in Linux Mint, to get rid of Warning: failed to open stream: Permission denied
cd /var/www
sudo chown www-data:www-data * -R
sudo usermod -a -G www-data username

In Fedora 25, it turned out to be an SE Linux issue, and the notification gave this solution which worked for me.
setsebool -P httpd_read_user_content 1

In my case the group _www that apache uses was missing in the folder's access list, so first I had to add the missing group, like so:
sudo chown -R _www ~/path-to-folder
Change _www to whatever user or group that apache is running as.
Find out apache's user/group using apachectl -S
The output is huge, but look at the very end something like:
User: name="_www"
Group: name="_www"

This isn't a direct answer to the question, but I had the same problem. I installed VSFTPD on my Ubuntu Server VPS. I could upload files, but every file I uploaded didn't have execution permissions (all files had rights "600"). These posts explain explain exactly what you have to do to configure your VSFTPD to set default rights on your files:
Default File Permissions Apache /var/www/
vsFTPd default uploaded file permissions on Ubuntu not working

Once, this happens to me as well. and when I googled the matter, I got to know that this happens when the permissions on the file is wrongfully set to 000 (which means that no one can read, write, or execute that file). Then I just changed my file permission privilege into Read & Write and it's worked for me.
To change file permission settings on mac: Right click on the particular file and click on Get info from dropdown menu and refer to the sharing and permissions panel and change privilege settings into Read & Write
More: http://www.itoctopus.com/warning-unknown-failed-to-open-stream-permission-denied-in-unknown-on-line-0-error-in-joomla

Check dos and unix file format. This problem is seen on linux platforms if dos file format is used. Use doc2unix command like below and then retry it should work
dos2unix *.php
This solution for below problem
Wed Nov 12 07:50:19 2014] [error] [client IP1] PHP Warning: Unknown: failed to
open stream: Permission denied in Unknown on line 0
[Wed Nov 12 07:50:19 2014] [error] [client IP1] PHP Fatal error: Unknown: Failed
opening required '/var/www/html/index.php' (include_path='.:/usr/share/pear:
/usr/share/php') in Unknown on line 0

Go to folder htdocs
cd htdocs
Execute
chmod -R 755 sites
No need to sudo !

Except the permissions, the problem can be open_basedir. If you are using it (and I suggest to use it) then check the settings at the VirtualHost :
php_admin_value open_basedir <YOUR ROOT>

Related

file_put_contents doesn't work when accessed in browser

I use php5.6 and Apache2.4.6 in centOS7.5
I put a php file in /var/www/html
like this :
<?php
echo (__DIR__ . "/test.text");
file_put_contents(__DIR__ . "/test.text","test text");
when I access this file through web browser(google chrome), file_put_contents do not function.
but,when I execute this file in console, file_put_contents do function. it make test.text file.
Is this problem due to server setting? or some php function doesn't work in access by a browser?
this is httpd/error_log
[Tue Oct 30 13:35:13.191011 2018] [:error] [pid 15037] [client XX.XXX.XX.XXX:29220] PHP Warning:
file_put_contents(/var/www/html/test.text): failed to open stream: Permission denied in /var/www/html/fpc2.php on line 3
but, this file's permission is 777.
Right. So it is a permissions problem. You need to make sure that the "user" that runs the php code has permission to write into the directory. I don't know to which user to give the permission, but it may be "web". Try:
sudo chgrp -R web /var/www/html
then
sudo chmod -R g+w *

CakePHP permission problems

Hello anybody can help with that problem on old cake app:
[Wed Sep 26 18:58:29.454771 2018] [core:crit] [pid 28046:tid 140483665811200] (13)Permission denied: [client 170.231.113.140:34906] AH00529: /home/vtecnet/public_html/admin/app/webroot/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/home/vtecnet/public_html/admin/app/webroot/' is executable
In fact the error message is giving you all the information:
[…] ensure [.htaccess] is readable and that '/home/vtecnet/public_html/admin/app/webroot/' is executable
I don’t know which version of CakePHP an old cake app is, since you’re not telling us, but looking at file permissions and chmod should point you in the right direction.
WordPress has a nice article on permissions: https://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Installation-Preparation.html#permissions
Something like this could help you out, if you have shell access to the server:
# set the ownership to the webserver user (i. e. www-data)
chown -R <insert_webserver_user_here> /home/vtecnet/public_html/admin/
# set permissions recursively
chmod -R 755 /home/vtecnet/public_html/admin/

PHP5 apache not working from another directory

I'm kinda novice on setting up a PHP environment (Apache), but nothing to do about it.
I have a VPS, which has Ubuntu 12.04 LTS.
My issue is that I receive following error:
[Wed Nov 13 16:43:31 2013] [error] [client 127.0.0.1] PHP Fatal error:
Unknown: Failed opening required '/root/blog/index.php'
(include_path='.:/usr/share/php:/usr/share/pear') in Unknown on line 0
index.php contains following code:
<?php
print phpinfo();
?>
It is WORKING IF it is located under "/var/www/" directory.
But I wanted to change the location of the script to "/root/blog".
I have re-configured the "000-default" configuration file under "sites-enabled" folder in apache2 folder. So it shouldn't be a problem.
I've tried assigning different permissions (chmod 777) to "/root/blog" folder (both: recursively and traditionally), but no avail.
I've checked the user and user group for the "/var/www" folder and files, and they are:
root/root - root user and root group. So, that should not be an issue.
What should I do about it ?
Can someone help me ?
P.S AFAIK, apache version: 2.2, PHP: 5.3.10 (installed today, using apt-get install php5 apache2)
I imagine the problem comes from the Apache user not having permission to read/execute files under the /root directory, since after all, that's the root user's home directory.
I really recommend you don't serve your website from /root but if you really want to try executing this command:
chown -R nobody /root/blog
(I'm assuming nobody is your Apache's user)
Out of curiosity, why run the website from /root? /var/www is the standard location for website files and if it works when the files are under this directory why not stick to it?

No PHP processing (Ubuntu/Apache2)

EDIT
[Sun Sep 01 18:37:40 2013] [error] [client MY IP ADDRESS] PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
[Sun Sep 01 18:37:40 2013] [error] [client MY IP ADDRESS] PHP Fatal error: Unknown: Failed opening required '/var/www/test2.php' (include_path='.:/usr/share/php:/usr/share/pe$
This is the error that I have in my Apache2 error.log
I have set up an EC2 instance (Ubuntu 12.x)
I have performed all updates, installed apache2, php5 & libapache2-mod-php5
The webserver is working fine for .html, I made a test page and tried this, it worked fine.
When I tried to add PHP to my html file though, there is no processing of the php. For example:
<?php
echo "My first PHP script!";
?>
or (including html)
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
If I were to write some text in the html portion, that would be displayed perfectly.
It is worth noting that there are no errors coming up, I just get a blank screen or only the html elements.
I am really confused as to what could have gone wrong here. I played around with a different instance around a month ago, followed the same install and php was working fine then, didn't edit any config files to get it up and running.
I can provide logs and things if requested but i'm not sure which logs would be best to provide. I would rather not set up a fresh instance as I have spent a few hours on this one sorting permissions, users, FTP etc.
Thanks in advance
All of your files should be set to use 644 permissions and your directories should be set to use 755. Also the user should be set properly as well to www-data or else the recommended permissions may not work.
find /var/www -type d | sudo xargs chmod 755
find /var/www -type f | sudo xargs chmod 644
sudo chown -R www-data /var/www
Somewhere in you httpd.conf file there should be an instruction to pass php files to mod_php. For example:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

PHP unable to create a directory with mkdir

I have a previously working PHP script that is able to create a directory with mkdir:
$webfolder = "/var/www/html/images/user";
mkdir($webfolder, 0770);
I made some changes to the permission setting of the folder /var/www/html/images which is now:
drwxrwx---. myself apache system_u:object_r:httpd_sys_content_t:s0 images
I think previously this folder was owned by apache. But since apache has the full privileges of read, write and execute as a user group, I wonder why it can't create a folder within. Using the mkdir produces a false boolean value.
Is the problem due to directory ownership or is there some other reasons? Note that I am using PHP version 5.4.
Error Log added:
[Mon Dec 17 11:12:34 2012] [error] [client 127.0.0.1] PHP Warning:
mkdir(): Permission denied in /var/www/html/upload on line 33,
referer: https://mywebsite.com/referer
The answer is staring right in front of me, but I miss it due to my unfamiliarity with SELinux.
The SELinux context type should be set as httpd_sys_content_rw_t instead of httpd_sys_content_t so that the folder is both readable and writable for apache. Changing the context recursively is done with the following command:
# chcon -R -t httpd_sys_content_rw_t /var/www/html/images
Good grief. Hope it helps others who come across this.
On CentOS7 VM, with PHP5.4.16/Apache 2.4.6/mariadb 5.5.44, the smarty template directory was not writable to generate compiled templates files and was giving the below error (in /var/log/httpd/error_log):
[Thu Mar 31 12:36:08.201383 2016] [:error] [pid 13094] [client 192.168.212.65:52204] PHP Fatal error: Smarty error: unable to write to $compile_dir '/var/www/html/app1/templates_c'. Be sure $compile_dir is writable by the web server user. in /var/www/html/app1/libs/smarty/Smarty.class.php on line 1093
hence the PHP application was displaying blank screen.
chmod 777 templates_c did not work either; but as per the suggestion by #Question Overflow, permission on web root on this VM did solve the problem.
I had to execute:
[root#appserver html]# chcon -R -t httpd_sys_content_rw_t /var/www/html
of course, the templates_c & cache should be owned by apache user:
drwxr-xr-x. 2 apache apache 6 Mar 31 12:56 templates_c
drwxr-xr-x. 2 apache apache 6 Mar 31 12:56 cache
After spending more than half a day, came across this.
Thanks

Categories