I am using https://laravel.com/docs/5.4/envoy as a deployment tool.
In the Envoy.blade.php, I have command that requires sudo access for example:-
chmod 777 -R storage/
chmod 777 -R bootstrap/cache
These commands fails with an error saying operation not permitted. How can we resolve this?
To run those commands as sudo try the following:
echo "{{ $password }}" | sudo -S chmod 777 -R storage/
echo "{{ $password }}" | sudo -S chmod 777 -R bootstrap/cache
Obviously you'll need to pass the sudo password into the envoy run command.
envoy run mytask --password=mypass
Tested on Ubuntu server 16.04 & 17.04
I changed the following configuration on the server
sudo visudo
and add
username ALL=(ALL) NOPASSWD: ALL
All commands can now be executed without entering a password
You can also specify individual commands
username ALL=(username) NOPASSWD:/etc/init.d/apache2 reload
Related
I'm setting up laradock (Setup for Multiple Projects) following the official documentation from the Laradock in my local machine.
After installation I installed the laravel through workspace container bash. I did configured the config file for the app in nginx/sites/ directory and in /etc/hosts file.
While visiting the development url I'm getting the following error message:
The stream or file "/var/www/laravel-api/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied
This worked for me:
chown -R www-data:www-data "project foldername"
If you are still facing the issue even after changing the permission and owner of file, just check for the OS of you Linux server.
Login to your server
$ ssh user#server-ip
check your OS running on linux server
$ cat /etc/os-release
//output
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
If it is CentOS, you need to disable Security-Enhanced Linux (SELinux) if enabled.
Check for SELinux status
$ sestatus
If it is enabled, then
$ setenforce Permissive
Or
$ sudo setenforce 0
Have a good day!
you have to enter the workspace first by typing "docker-compose exec workspace bash"(without quotes)
To give a write permission to a single file,
chmod -R 777 /var/www/laravel-api/storage/logs/laravel.log
or
chmod -R 777 /var/www/laravel-api/storage/logs
or
sudo chmod -R 777 /var/www/laravel-api/storage/logs/laravel.log
when the same error appears but different folders or files, do the same thing only change the folder name
example :
chmod -R 777 /var/www/laravel-api/storage/logs
chmod -R 777 /var/www/laravel-api/storage/framework/views
chmod -R 777 /var/www/laravel-api/storage/framework/sessions
If you aren't running your application as root on your web server, then it wont have write access based on the permissions you've provided.
Checked from workspace container bash. storage/logs/ directory has drwxr-xr-x 2 root root 4096 Aug 1 07:37 logs
The error is complaining about permission denial for opening in append mode - it doesn't have permission to write to the file, only root does.
What you need to do is make your web server group the owner of the storage directory:
chown -R www-data:www-data /var/www/laravel-api/storage/
The www-data can be switched out for whatever group your web server is associated with.
To avoid completely repeating an amazing and complete answer, I recommend you give this answer a read:
How to set up file permissions for Laravel?
Give group write access to /storage/logs/
sudo chmod g+w storage/logs
You need to run the following command. It works for me:
step 1:
sudo chmod -R +rwX .
step 2:
sudo chown -R $(whoami) .
Why does sudo chmod <file> inside my shell script not work? The permissions stay as they were.
#!/bin/bash
sudo chmod 757 Folder
Remove the sudo from the file. Just write
chmod 757 folder
And give your script file +x permission. It will work.
In sudo visudo add this line to disable the request password when you write the sudo command:
www-data ALL=(ALL:ALL) NOPASSWD:ALL
Launch the script with the exec function and put sudo inside this with user root only. Now there's no need to enter a password.
exec("sudo -u root -S ./create_folders.sh)
I am trying to chown a directory via an NPM script. The script looks like the following:
chown -R 755 www-data root#XXX.XXX.XXX.XX:/var/www/test.com
But the message I get back is: chown: www-data: No such file or directory even though this exists. Any ideas much appreciated.
chown operates locally, not on remote servers. In your example, chown is attempting to operate on ./www-data and ./root#XXX.XXX.XXX.XX:/var/www/test.com, which don't exist in the directory of wherever you were when you executed the command.
You will need to execute chown as a command through ssh:
ssh root#XXX.XXX.XXX.XX chmod -R 755 /var/www/test.com/
Fixed this with following script.
ssh root#XXX.XXX.XXX.XX chmod -R 755 /var/www/test.com/
(I needed to login to the server first).
I have a new instance and everything was going fine, I have the site installed and transferred over my database and uploaded most my wordpress file to the server.
But towards the end of my upload, files stopped being uploaded and I keep getting the message
***Error: Directory /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: no such file or directory
Command: cd "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017"
Response: New directory is: "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017"
Command: mkdir "01"
Error: mkdir /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: permission denied
Command: mkdir "/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01"
Error: mkdir /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/01: permission denied***
I've tried changing the permissions to 755 or 644 but get this error
***Status: Setting permissions of '/opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/07' to '644'
Command: chmod 644 "07"
Error: set attrs for /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads/2017/07: permission denied***
Video file transfer: https://www.screencast.com/t/d8BbFnxkp
Video permission fail: https://www.screencast.com/t/2XBr6zwqd
I'm just puzzled why the other transfers worked
Thanks for your help.
I found this solution that appears to work.
sudo chown -R bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
sudo chmod -R 775 /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
Then, you can try to upload and check if it works. If it doesn't, you can try doing this instead:
sudo chown -R daemon:daemon /opt/bitnami/apps/wordpress/htdocs/wp-content/uploads
In my case I had this problem while publishing my application from JetBrains Rider to Ubuntu server via SFTP. As there is no way to use sudo, the easy solution was to set publish folder ownership for user, specified in ssh connection for SFTP.
sudo chown -R username:username /var/www/your-app-publish-folder
Or, if you are already logged in under this user on server:
sudo chown -R $USER:$USER /var/www/your-app-publish-folder
I am getting this issue for sessions even when I have given 777 and required user and group to the folders in storage.
ErrorException in Filesystem.php line 81: file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec): failed to open stream: Permission denied
How can I get rid of this issue?
at HandleExceptions->handleError('2',
'file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec):
failed to open stream: Permission denied',
'/var/www/html/business/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php',
'81', array('path' =>
'/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec',
'contents' =>
'a:5:{s:6:"_token";s:40:"Dyi8ML8zxaQJOEiVvqBpqk3noLDJTkIdqiC67qs9";s:9:"_previous";a:1:{s:3:"url";s:29:"http://XXXXX:8333";}s:22:"PHPDEBUGBAR_STACK_DATA";a:0:{}s:9:"_sf2_meta";a:3:{s:1:"u";i:1470895812;s:1:"c";i:1470895812;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}',
'lock' => true))
I had a problem like that and doing the following solved it for me
chmod -R gu+w storage
chmod -R guo+w storage
php artisan cache:clear
Got it from the answer here
if you try
chmod -R gu+w storage
chmod -R guo+w storage
php artisan cache:clear
and it still doesn't work.
you have two ways:
Disable your SELinux (i really don't recommend this way, unless you are on training or learning)
Configuring SELinux Policies for Apache Web Servers
i want to break down every steps for confirguring selinux policies
assumption: you've already installed all database like mysql, postgresql, or others. you've installed web server
install semanage with command "yum provides /usr/sbin/semanage"
install policycoreutils-python with command "yum install -y policycoreutils-python"
create policies:
a. sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html/webapp(/.*)?"
b. sudo semanage fcontext -a -t httpd_log_t "/var/www/html/webapp/logs(/.*)?"
c. sudo semanage fcontext -a -t httpd_cache_t "/var/www/html/webapp/cache(/.*)?"
Allowing ReadWrite Access:
a. sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/webapp/storage(/.*)?"
ACCESS YOUR WEBAPP
b. restorecon -Rv /var/www/html/webapp
Giving 777 to the folder session works for me.
chown -R www-data:www-data project_folder
sudo service apache2 reload
chmod -R gu+w storage
chmod -R guo+w storage
php artisan cache:clear
This worked for me for my laravel 8 application.
First run this command in your Laravel app folder
sudo composer update
After that run the following in order
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
sudo chmod -R 775 storage
sudo chmod -R 775 bootstrap/cache
run the following command
docker-compose exec <your webserver container name> sh OR bash(if it uses bash)
then
ls -l /var/www/storage/framework/views/ | grep 7369b96b4 (this number is part of the file name you are trying to see it permission) you will see something like this -rw-r--r--
the run
chmod 777 var/www/storage/framework/views/7369b96b436adb2109e56fbb8ed7ba805568c985.php(the full file name)
reload the page
Goto project root folder and run the following command
sudo chmod -R 777 storage/* bootstrap/cache/*
Go to the session folder and make the permission like 755. It's worked for me.