PHP doesnt have permission to change file name - php

I want to change file name in subdirectory under /usr/local/MyFolder/overlay.png to overlay2.png with php, but php raises Permission below Error:
( [type] => 2 [message] => rename(/usr/local/MyFolder/content/overlay.png,/usr/local/MyFolder/overlay2.png): Permission denied [file] => /var/www/html/2.php [line] => 6 )
How to solve it?

RUn the following command from Terminal:
You can get to the terminal by Pressing Ctrl+alt+T on your keyboard
Run the following code:
sudo chmod 777 "/usr/local/MyFolder/"
sudo chmod 777 "/usr/local/MyFolder/content/"
Now your script should have permissions to access those folders
Mind you, doing these gives permission to everyone and every programs to access and modify things in the folders above

Related

Permission in CakePHP Using EC2 Instance

I have new instance in AWS. I have make var/www directory using PuTTy. I have upload all file to var/www/html directory. When i open IP Public Instance in Web Browser there are :
Warning: _cake_core_ cache was unable to write 'cake_dev_id' to File
cache in /var/www/html/lib/Cake/Cache/Cache.php on line 322
Warning: /var/www/html/app/tmp/cache/persistent/ is not writable in
/var/www/html/lib/Cake/Cache/Engine/FileEngine.php on line 384
Then i changed permission:
sudo chmod -R 777 /var/www/html/lib
sudo chmod -R 777 /var/www/html/app
But when i changed the permission there are an error:
Error: Cannot use 'string' as class name as it is reserved File:
/var/www/html/lib/Cake/Utility/String.php Line: 24
It clearly saying error is in the class name. You are using String.php and String is a reserve keyword.
Try Changing the name of String.php to something else and try again.
You need to add permission in your tem and logs folder
if you don't have those folder you need to create those folder
you may use
cd /var/www/html/app
mkdir -m 777 tmp
Here is the Official Doc

Permission Issues

Having an issue with unlink() even when executing a script as root.
Getting this error:
Warning: unlink(/var/www/html/services/training/add.php): Permission denied in /var/www/html/sites/services/functions.php on line 228
The owner of the file is root and the file permissions are 775 so it should work.
Are there any further steps I can take to troubleshoot this? Not sure where to go from here...
Open your terminal .. I guess you are an ubuntu user
so just do this
sudo chmod 777 -R /var/www/html/services/
By Default your access is limited . So you have to extend your access using this chmod command :) .. that's it :)

Laravel: "Failed to open stream' in storage/views

I had my Laravel 3 application running on a different server. I wrapped it up and sent it to my new server. Unpacked it, and while I am trying to display the Laravel application on the new server, I receive this error:
Unhandled Exception Message:
file_put_contents(/var/www/customer_area/storage/views/13f378cf44cd9253eb03394b5a7fd914):
failed to open stream: Permission denied
Location:
/var/www/customer_area/laravel/blade.php on line 63
I have already read through this question several times where others have solved a similar problem by changing permissions on 'storage/directories' to '775'. I even changed permissions on the entire 'var/www' directory to '777', and I still have the error.
Something that I noticed is that there is no '13f378cf44cd9253eb03394b5a7fd914' in the storage/views folder. There are five other files in the folder, but not that one.
Assuming you are running apache on linux, look into recursive chgrp www-data and chown www-data on the folders
Just modify file/folder permissions
Assuming you are in root folder, run one of these commands
chmod -R 0777 storage // for L3
chmod -R 0777 app/storage // for L4

fopen() fails to open stream: permission denied, yet permissions should be valid

So, I have this error:
Warning: fopen(/path/to/test-in.txt) [function.fopen]: failed to open stream: Permission denied
Performing ls -l in the directory where test-in.txt is produces the following output:
-rw-r--r-- 1 $USER $USER 1921 Sep 6 20:09 test-in.txt
-rw-r--r-- 1 $USER $USER 0 Sep 6 20:08 test-out.txt
In order to get past this, I decided to perform the following:
chgrp -R www-data /path/to/php/webroot
And then did:
chmod g+rw /path/to/php/webroot
Yet, I still get this error when I run my php5 script to open the file. Why is this happening? I've tried this using LAMP as well as cherokee through CGI, so it can't be this.
Is there a solution of some sort?
Edit
I'll also add that I'm just developing via localhost right now.
Update - PHP fopen() line
$fullpath = $this->fileRoot . $this->fileInData['fileName'];
$file_ptr = fopen( $fullpath, 'r+' );
I should also mention I'd like to stick with Cherokee if possible. What's this deal about setting file permissions for Apache/Cherokee?
Check if the user that PHP runs under have "X" permission on every directory of the file path.
It will need it to access the file
If your file is: /path/to/test-in.txt
You should have X permission on:
/path
/path/to
and read permission on /path/to/test-in.txt
Another reason of this error may be that the directory of file does not exist.
I just add php code before fopen:
if(!file_exists(dirname($file)))
mkdir(dirname($file));
This help me out.

Why is my folder not being visible to the web? or upload-able?

For some odd reason I can no longer access my images in my image folder or any of its contents https://ksc105.kscserver.com/images/list.png or https://ksc105.kscserver.com/images/bold.png. I orginally could not upload files to images and attempted to use chmod a=rw /var/www/images but that did not help. I also upgrade php5 to the latest ubuntu build. What can I do to fix this issue, and what can I do to fix my upload issue?
The current images do not display becuase I get a 403 error:
Forbidden
You don't have permission to access /images/bold.png on this server.
Apache Server at [..].com Port 443
Upload gives me:
warning: move_uploaded_file(/[..].png): failed to open stream: Permission denied in [..]/images.php on line 37
Warning: move_uploaded_file(): Unable to move '/var/tmp/[...].png' to '/var/www/images/nzoom.png' in [..]/images.php on line 37
The [..] is just me taking out useless variables.
PHP 5 on Apache 2 on Ubuntu 9.
I suspect you've messed up the permissions on the directory. You probably want to do:
# chmod 757 /var/www/images
# chmod 644 /var/www/images/*.*
to allow the nobody/apache webserver user to access them
This is a permissions related probably most certainly. I suggest you chmod your:
files to 0644 (or 0666 if Apache is not running as the same [FTP] user)
directories to 0755 (or 0777 if Apache is not running as the same [FTP] user)
This way they will always be executable and you have further write permissions from within your scripts.

Categories