Error creating directory on linux server using PHP Code - php

I have a group on linux named mygroup. and have a user named apache. apache is the member of mygroup.
i created a sample php file and uploaded on sever
<?php
$structure = '/my_repo/hello';
if (!mkdir($structure, 0, true)) {
die('Failed to create folders...');
}
?>
myrepo dir is at root level and is group is mygroup and owner is root. permissions are 764.
when i accessed my file on http://mydomain.com/sample.php
it gives me the following error
[warn] mod_fcgid: stderr: PHP Warning: dir(/my_repo/hello)
[<a href='function.dir'>function.dir</a>]: failed to open dir:
Permission denied in /var/www/clients/client1/web2/web/sample.php

problem resolved. there was permission issue on server. the code was uploaded through a different user, that was not having permission to myrepo directory.

Related

How to give permissions only to PHP to read a config directory outside the web root?

I am trying to hide my db conf connection file outside the web root directory of my web server. I want to put it outside and keep the permissions as restrective as possible, in order to permit only the web administrator and the PHP interpreter to read it.
The file has this permissions:
-rw------- 1 serveradmin serveradmin 150 mar 12 01:12 db-conf.php
But when a php script inside the web root calls it using require_once '/path/outside/webroot/to/db-conf.php'; I get the php permission denied error.
**Warning: require_once(/path/outside/webroot/to/db-conf.php): failed to open stream: Permission denied in /var/www/php-script.php on line x
Fatal error: require_once(): Failed opening required '' (include_path='.:') in /var/www/php-script.php on line x**
How can I resolve?
If you are running PHP through a webserver, i.e. apache, then PHP is running as the apache user, and whatever PHP can read, apache can read, so you have to give apache read permissions to this file. if its outside the website directory, then people won't be able to get to it through apache, but PHP will be able to find it.

Try to upload an image using php

I got this error log:
move_uploaded_file() enter code here [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpGmUpFW' to 'images/test#yahsoo.com.jpg' in enter code here[..]send.php on line 32
also error log
`include(user_agent.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home/[irelevent]/Craciun2013/index.php on line 63`
line32 states:
if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file)) {
Please help.
It seems php (either www-data, apache or whatever user runs it) doesn't have permission on your current path. Have you checked who's the folder owner and what permissions does it have?

how can I know what is the necessary permission for my new codeigniter project?

I just installed apache2 and php5 on my ubuntu computer, Ive done it before on debian but now I have a weird error.
when I try to reach a page with my framework in CodeIgniter I get this error
[error] [client 127.0.0.1] PHP Warning: require_once(/var/www/project/system/core/CodeIgniter.php): failed to open stream: Permission denied in /var/www/project/index.php on line 202, referer: localhost/
[error] [client 127.0.0.1] PHP Fatal error: require_once(): Failed opening required '/var/www/project/system/core/CodeIgniter.php' (include_path='.:/usr/share/php5-common') in /var/www/project/index.php on line 202, referer: localhost/
before that I have an error of not found on my include_path, so , I changed it on my php.ini and i changed it to :/usr/share/php5-common
Still... I have NO idea what is the error...
I changed permissions on my /var/www folder and its like user:user
on the line of index.php I have this:
require_once BASEPATH.'core/CodeIgniter.php';
Most probably your $config['base_url'] is wrong.
Make sure its properly identifies the localhost or IP you are using to access localhost.
I mean if you are accessing local server or remote server using http://[ipaddress] then you have to define baseurl like that only.
in your case may be **$config['base_url'] = http://127.0.0.1/codeigniter_project_name**
Similarly that applies to database config also.

Are there any hidden php right permission using imagejpeg() or in apache & php in general? Getting Unable to open Permission denied

I am getting Unable to open ... for writing: Permission denied when I try and resize an image. The code has worked fine for years but after a resent upgrade (I think ) It has stopped working. I have tried changing the permission on the folder to 777 and disabled selunix. Is there any thing that may have changed in my httpd.con file or php.ini file that will disabled a php script right?
The error message from Apache logs:
[Mon Jun 25 08:59:17 2012] [error] [client 127.0.0.1] PHP Warning: imagejpeg(): Unable to open './cache/150_112.5_be636f82ef8e7e22727c81980df16cd5.jpg' for writing: Permission denied in /var/www/html/resize_function.php on line 62, referer: http://jasonrmoore.info/list.php?dir=./
Nop, this is an unix permission issue.
Please check the permission of the permissions of ./cache folder and inner files.

PHP: move_uploaded_file(): Unable to move '/

I keep getting this error on a new server I just setup
[Wed Feb 16 22:46:51 2011] [error] [client 71.1.236.114] PHP Warning:
move_uploaded_file(upload/110216104651_00134_smooth_1440x900.jpg):
failed to open stream: Permission denied in /var/www/admin/_application/models/Roles.model on line 1757,
referer: http://nacc.biz/admin/admin/modifyarticle.php?roleid=4
[Wed Feb 16 22:46:51 2011] [error] [client 71.1.236.114] PHP Warning: move_uploaded_file():
Unable to move '/tmp/php6wlOg1' to 'upload/110216104651_00134_smooth_1440x900.jpg'
in /var/www/admin/_application/models/Roles.model on line 1757, referer:
http://nacc.biz/admin/admin/modifyarticle.php?roleid=4
[Wed Feb 16 22:46:51 2011] [error] [client 71.1.236.114] PHP Notice:
Upload Error: Error moving from temp dir in /var/www/admin/_application/models/Roles.model on line 1759,
referer: http://nacc.biz/admin/admin/modifyarticle.php?roleid=4
I added 777 and created a uploads dir, but the error persists. How do I find the path that needs to either be corrected or created?
Change owner of upload/ to www-data:www-data and also chmod to 755
Looks like it doesn't know where upload/ is. Make sure you have the full path in your statement. For example, if upload directory is actually located in /var/upload, then make sure that is in your statement, not just upload/.
Log into your ftp and confirm the following:
The folder exists, check for spellings
Check the properties of the folder and make sure the permissions have read+write 0666
Make sure the file is within your public html root, otherwise double check the owner of the file, and make sure PHP Has read / write access to it.
looking at the log:
Unable to move '/tmp/php6wlOg1' to 'upload/110216104651_00134_smooth_1440x900.jpg'
It seems to me that its looking in your root directory as upload/110216.... should be path.to/public_html/upload/110216....
If none of the above work, please post your line of code that has move_uploaded_file on.
It's trying to move the file to upload/ not uploads/, make sure the directory exists and is writable.
Provided, there are no spelling mismatches, give your upload directory (that directory ONLY) all user rights sudo chmod a+rwx /path/to/folder, that should fix the problem easily.
For a quick further read about permissions in Ubuntu, check here.

Categories