Last active
November 25, 2023 23:53
-
-
Save adrianorsouza/ad87d282408a5f926fb0b4f892bd9ad4 to your computer and use it in GitHub Desktop.
Laravel storage path permissions. This script makes storage path writable for both users, the admin and PHP Webserver user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# DEFINE PROPER WRITABLE PERMISSIONS FOR LARAVEL PROJECT. | |
# Run this script in a fresh Laravel install. | |
# | |
# @author Adriano Rosa (https://adrianorosa.com) | |
# @created: 2015-02-15 00:59:19 | |
# @updated: 2021-01-28 14:19:16 | |
# @updated: 2023-11-25 20:53:36 | |
# | |
# Make storage and bootstrap dirs writable for both users: | |
# - the admin ($USER) | |
# - PHP Webserver user (www-data) | |
# | |
# @install Place this file within the `scripts` folder within your project. | |
# @usage bash /root/path/scripts/laravel_path_permissions.sh | |
# @link {https://gist.github.com/adrianorsouza/ad87d282408a5f926fb0b4f892bd9ad4} | |
# =========================================================== | |
# Make storage and bootstrap dir writable for both users | |
# =========================================================== | |
set -e | |
set -x | |
# DETERMINE THE PROJECT BASE PATH ASSUMING THIS SCRIPT WAS | |
# STORED WITHIN THE /project_root_directory/scripts | |
BASE_PATH="$(dirname -- $(cd -P -- "$(dirname -- "$0")" && pwd -P))" | |
LOG_FILE="$BASE_PATH/storage/logs/laravel.log" | |
if [ ! -f ${LOG_FILE} ]; then | |
echo "CREATING LOG FILE: storage/logs/laravel.log " | |
touch ${LOG_FILE} | |
echo "SETTING LOG FILE PERMISSIONS:" | |
sudo chmod 665 ${LOG_FILE} | |
sudo chown $USER:www-data ${LOG_FILE} | |
echo "SETTING LOG FILE PERMISSIONS OK!" | |
else | |
echo "LOG_FILE ALREADY SETUP!" | |
fi | |
if [[ ! -d $BASE_PATH/vendor && -d $BASE_PATH/bootstrap && -d $BASE_PATH/storage ]]; then | |
echo "DEFINE THE WRITABLE AND EXECUTABLE PERMISSION FOR THE WEBSERVER OWNER AND GROUP ..." | |
sudo chmod 775 $BASE_PATH/bootstrap/cache | |
sudo chmod 775 $BASE_PATH/storage/framework/cache | |
sudo chmod 775 $BASE_PATH/storage/framework/cache/data | |
sudo chmod 775 $BASE_PATH/storage/framework/sessions | |
sudo chmod 775 $BASE_PATH/storage/framework/views | |
sudo chmod 775 $BASE_PATH/storage/logs | |
echo "CHANGE THE PERMISSIONS GROUP FOR THE WEBSERVER USER ..." | |
sudo chgrp www-data $BASE_PATH/bootstrap/cache | |
sudo chgrp www-data $BASE_PATH/storage/framework/cache | |
sudo chgrp www-data $BASE_PATH/storage/framework/cache/data | |
sudo chgrp www-data $BASE_PATH/storage/framework/sessions | |
sudo chgrp www-data $BASE_PATH/storage/framework/views | |
sudo chgrp www-data $BASE_PATH/storage/logs | |
echo "PERMISSIONS DONE!" | |
else | |
echo "PERMISSIONS ALREADY SETUP!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment