Place this file within the `scripts` folder within your project.
usage
bash /root/path/scripts/laravel_path_permissions.sh
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 $USER $BASE_PATH/storage/framework/views
sudo chgrp www-data $BASE_PATH/storage/logs
echo "PERMISSIONS DONE!"
else
echo "PERMISSIONS ALREADY SETUP!"
fi