This question already has answers here:
PHP mkdir: Permission denied problem
(15 answers)
Closed 6 years ago.
I'm trying to create directory on my local apache server with php.
I tried
<?php mkdir("folder"); ?>
and
<?php exec("sudo mkdir folder"); ?>
When I try to execute them in browser nothing happens.
But I can execute them from terminal by using sudo. (I also modified sudoers file so it won't prompt for password in second code)
When I don't use sudo I get this error
PHP Warning: mkdir(): Permission denied in /var/www/html/mscr/add.php on line 2
I've also tried this and this .
So I can execute almost everything but directory operations in browser.
I want to be able to create, delete and edit directories in browser.
Thank you!
Sounds like Apache doesn't have permission to create the folder. Either give Apache ownership of the folder (where you're trying to create a new one)
sudo chown www-data /var/www/html/mscr
or set the folder permissions to 777
sudo chmod 777 /var/www/html/mscr
Warning this will make everything within the mscr folder executable. To get around this most CMS will create a subfolder which is set to 777 so something like /var/www/html/mscr/uploads
<?php mkdir("folder", 777, true); ?>
Related
This question already has answers here:
Laravel 5.0 Permission on ubuntu
(2 answers)
Closed 6 years ago.
I am using Laravel 5 and whenever i pull from git on my production server, which is azure vps, i have to give permission to my proejct directory, so that apache user can access it. Otherwise it says, permission denied exception. so i have to run following line in terminal every time whenever i pull new code,
sudo chown -R www-data:www-data projectDirectory
So after above command everything works fine.
But the worst thing is whenever Laravel creates new files for log, same issue happens, which gives me following exception:
Symfony\Component\Debug\Exception\FatalErrorException: Exception
'Symfony\Component\Debug\Exception\FatalErrorException' with message
'Uncaught exception 'UnexpectedValueException' with message 'The
stream or file " /storage/logs/laravel-2016-03-17.log
Can anyone tell me how i can get rid of this critical issue. Thanks
Try adding www-data to your project group:
useradd -G <your-project-group> www-data
If larval writes to the logs directory with 'rwx' perms on the group, you will be fine. If the group by default doesn't have write permission on logs, which may be the case, then you will need to make the logs directory open (which #SRK hinted at) DO NOT, however run chmod 755 on your entire web app. You will be exposing configuration parameters (database access) to the outside world.
Check with it will work. you have give permission to this folder to create temporary files
sudo chmod -R 755 /storage/
I'm trying to execute a php script but i'm having this kind of errors:
Warning: file_put_contents(/sys/class/gpio/export): failed to open stream: Permission denied in /home/pi/php-gpio/src/PhpGpio/Gpio.php on line 99
Warning: file_put_contents(/sys/class/gpio/gpio17/direction): failed to open stream: Permission denied in /home/pi/php-gpio/src/PhpGpio/Gpio.php on line 103
I've tried to set up the permission in the $ sudo visudo like this:
www-data ALL=NOPASSWD: path/to/my/script
or
www-data ALL=NOPASSWD: ALL
but is not working, i'm able to execute this script only with sudo form the command line!
Thanks in advance!
If you using in your computer, you must change the default directory permission:
$ sudo chmod -R +w /sys/class/gpio/export
else if you run code in a server, in server panel and in section files (e.g. CPanel) change permission and add write right.
Another way is running exec() command:
<?php
exec('chmod -R +w /sys/class/gpio/export');
?>
However, php should have exec right and running with root!
I recently published a project that allows PHP to obtain and interact with a real Bash shell (as root if requested), it solves the limitations of exec() and shell_exec(). Get it here: https://github.com/merlinthemagic/MTS
After downloading you would simply use the following code:
$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1 = $shell->exeCmd('/sys/class/gpio/export');
$return2 = $shell->exeCmd('/sys/class/gpio/gpio17/direction');
//the return will be a string containing the return of the command
echo $return1;
echo $return2;
In terms of security it is far better than running apache as root, or the wide open sudo permissions in your question. But letting PHP anywhere near root is always tricky.
The project i built achieves a root bash shell in one of 2 ways:
1) You allow apache the right to sudo python.
OR
2) You pass root credentials to the object every time you need a shell with root setup.
Pick your poison. :) Read the documentation.
I've read all the relevant topics and went trough the anwers,
but my program is still not workint properly.
I get the following error message:
Warning: mkdir(): Permission denied in /var/www/printing/uploader_temp.php on line 28
Where line 28 looks like this:
mkdir("upload", 0777, true);
The current user who is logged in is called "server".
The owner of both var/www/ and var/www/printing is "server". (without " of course)
The attribute of var/www/ptinting is -777.
I modified the following rows in /etc/apache2/envvars to look like this:
export APACHE_RUN_USER=server
export APACHE_RUN_GROUP=server
and restarted apache server.
I can create folders manually on server or using FTP.
Does anyone have an idea what I did wrong?
Where else should I set permissions?
The OS is Ubuntu.
Thank you for your answers.
Did you tried to give permissions to apache user? I had this problem on my web application and I solved it in two commands:
chown -R www-data:www-data /path/to/webserver/www
chmod -R g+rw /path/to/webserver/www
Hope this helps for you too.
Try to have a look to AppArmor:
https://wiki.ubuntu.com/AppArmor
Try to create a file or a directory in the /tmp/, can you?
$handle = fopen('/Applications/XAMPP/xamppfiles/htdocs/test/file.txt', 'w');
I tried doing the above and every time I try it, the following statement appeared on my browser:
Warning:fopen(/Applications/XAMPP/xamppfiles/htdocs/test/file.txt)
[function.fopen]: failed to open stream: Permission denied in
/Applications/XAMPP/xamppfiles/htdocs/test/index.php on line 26.
I tried looking through answered questions with the same type of questions but most of the things I tried did not work. For example, writing the full directory...
Maybe, you have no premissions to acces the file. One of the answet, is that, you must change CHMOD to e.g. 777. You can co it with your ftp explorer or with PHP.
chmod("/somedir/somefile", 777);
By default when XAMPP is installed, the htdocs folder does not have any read permissions. You can change the permissions through the terminal like this.
cd /Application/XAMPP/xamppfiles/htdocs/test/
sudo chmod 0664 file.txt
Alternatively, you can recursively set all the permission level of all files and folders
cd /Application/XAMPP/xamppfiles/
sudo chmod -R 0664 htdocs/
You could chmod to 777, but that is risky security. What I'm guessing you really want is change ownership of the file. You can do this using chown. PHP usually runs as user www-data, so you'd run a command something like this.
sudo chown www-data:root path/to/file.ext
If you're file permission on the file was something normal like 664, that'd give PHP the 6 permission (Read and Write) instead of the 4 (just Read).
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