Reputation: 750
I am trying to create a file outside of the public_html in php:
fopen("/home/sites/foo.org/backup-ticketing/asu.sql";w)
However I am getting this error message. I am sure I should be able to do it somehow I just can't figure it out. Permission of the folder is 711
.
[Wed Aug 01 14:33:54 2012] [error] [client 84.3.2.16] PHP Warning: fopen(/home/sites/foo.org/backup-ticketing/asu.sql) [function.fopen]: failed to open stream: Operation not permitted in /home/sites/foo.org/public_html/back/asu.php on line 4
Could you please advise me what is the right way to do please?
Thank you for the many advices now I have an additional info:
php.ini is the problem in public_html however I would like to keep it as it is but /back/ folder should be able to do so.
here is my settings:
file_uploads = Off
upload_tmp_dir = /var/php_tmp
upload_max_filesize = 0M
allow_url_fopen = Off
allow_url_include = Off
safe_mode = Off
display_errors = off
magic_quotes_gpc = off
magic_quotes_runtime = off
max_file_uploads=0
disable_functions=passthru,exec,phpinfo
open_basedir = /home/sites/foo.org/public_html/
Upvotes: 4
Views: 2484
Reputation: 750
After a research I found the obvious answer: open_basedir = none in php.ini I though someone would find useful.
Thanks for all the answers and I have learned a lot from them.
Upvotes: 0
Reputation: 1057
It seems as PHP's Safe mode
or open_basedir are enabled preventing you from what you want to do - so it's simply not allowed and therefore not possible.
You could check if you are allowed to write to some other directory outside of your public directory, often ../tmp
or ../temp
are there and writable.
You might be able to find out what paths are allowed by open_basedir with
echo ini_get('open_basedir');
Another way around your problem: Put your files in a subdirectory of your public directory and secure it with .htaccess (User/Password, deny all IPs but your ow etc.)
EDIT:
Allow access only from certain IPs: Create a file and name it .htaccess with the content below
order deny,allow
deny from all
allow from 888.888.888.888
Upvotes: 5
Reputation: 917
You could try a shell_exec.
there you could exec a script with a different user than the webserver user
http://php.net/manual/de/function.shell-exec.php
Upvotes: 0