Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

On my Ubuntu server I have Apache and PHP, when I run a php file containing this code:

  echo 'error';
  echo 'ok';

I get "ERROR":

First I tried sudo chmod -R 775 /data , then sudo chmod -R 777 /dir or change the owner or group to my Apache user (www-data).

But what ever I do I get the same result again and again. So I looked on LOG!

[Sat Aug 2013] [error] [client] PHP Warning: 
failed to open stream: No such file or directory in
/var/www/myfiles/folder/test.php on line 2
share|improve this question

closed as off-topic by psusi, Thomas W., KasiyA, Eric Carvalho, Jan Nov 20 '14 at 9:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This describes a problem that can't be reproduced that seemingly went away on its own or was only relevant to a very specific period of time. It's off-topic as it's unlikely to help future readers." – psusi, Thomas W., KasiyA, Eric Carvalho, Jan
If this question can be reworded to fit the rules in the help center, please edit the question.

I didn't read the whole question yet but here is a quick warning: NEVER set permissions 777 on anything in reach of a web server!! – guntbert Aug 4 '13 at 18:04

2 Answers 2

There is definitly a problem with the destination folder path.

Your above error message says, it wants to put the contents to a file in the directory "/var/www/myfiles/folder/data/new_rewrite/"

You should double check:

  • Is the directory "/var/www/myfiles/folder/data/new_rewrite/" really present.
  • check the user permission of user directory /new_rewrite
share|improve this answer
check the user permission of user directory /new_rewrite -Where do I find the user permission I guess I changed the owner and the group to www-data. That's all. – Rohit Aug 5 '13 at 14:27

As the others, I see problem in the folder path, this folder does not exist. You should create folders before a file is written there.

Second, you will face the ownership problem. It is not a good idea to give 777 priviledges to something. After that even guest can execute something and this is not secure.

Better way is to think, which user is running the php script. Standard configuration is that www-data user is running apache/php on LAMP, therefore you should change ownership of the destination folders to the www-data:www-data (user:group). Then the folder would be accessible even with 644 rights.

use mkdir, chown and chmod commands to reach the desired folder path and access rights.

Added1: As I see you already tried this, i see there a bug. You did use chmod -R 775 /data but you had to use chmod -R 775 /var/www/myfiles/folder/data/, which is completely different folder. If you type / on the start of your path, you are on the root folder. Doublecheck the real user rights on the desired folder.

Added2: You can try this Q/A and follow it. ( try different folders. Unfortunatelly we do not know anything about your PHP configuration. So therefore it is possible that your user:group the PHP is running under is different.

share|improve this answer
/var/www/myfiles/folder/data/ - the path is real and existed. data or new_rewrite owner and group is already www-data. And I did that and checked but no luck. – Rohit Aug 5 '13 at 14:25
are you able to write at least some data to the folder from php? If yes, it would be better to search error in the php code. – Dee Aug 5 '13 at 15:10
That php code is perfectly working in cPanel host or anywhere else. I tested it. And not even need to change the group or anything. – Rohit Aug 6 '13 at 9:11
What I guess is www-data access directory is not the root.. If www-data user defaults directory is /etc/apache2 or something like that! Is not in the hell my PHP can access /var/www - In this case what to do? – Rohit Aug 7 '13 at 17:20
@Rohit, follow the Added2 remark, this will create directory with ownership of the user:group under which the PHP script is working. Of course, you have to write inside of your home www directory, whenever it is. This depends on your configuration. – Dee Aug 8 '13 at 12:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.