Files
scripts/laravelpermissions
2025-12-18 14:43:56 +08:00

63 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Fix the directory and file pemission for Laravel-based projects.
# Rev 2019-07-31 By Ali
ME=$(whoami)
if [ $1 ] ; then
dir="/var/www/webapps/$1"
else
dir=$(pwd)
fi
if [ -f "$dir/.env" ] ; then
echo "Setting pemission for $dir...";
#sudo chown $ME:$ME ** -R
#permissionreset
# Laravel Env
sudo chmod 640 .env
# Delete cache directories
sudo rm -rf $dir/storage/framework/views/twig
# Create common dirs
mkdir -p $dir/storage/framework/cache
mkdir -p $dir/storage/framework/sessions
mkdir -p $dir/storage/framework/views/twig
mkdir -p $dir/storage/app
mkdir -p $dir/storage/logs
mkdir -p $dir/storage/reports
mkdir -p $dir/bootstrap/cache
# Bring them to GIT repo.
echo -e "**\n!.gitignore" > $dir/storage/framework/cache/.gitignore
echo -e "**\n!.gitignore" > $dir/storage/framework/sessions/.gitignore
echo -e "**\n!.gitignore" > $dir/storage/framework/views/twig.gitignore
echo -e "**\n!.gitignore" > $dir/storage/app/.gitignore
echo -e "**\n!.gitignore" > $dir/storage/logs/.gitignore
echo -e "**\n!.gitignore" > $dir/storage/reports/.gitignore
# Folder to be read/write by httpd
sudo find $dir/config -type d -exec chmod 750 {} \;
sudo find $dir/config -type f -exec chmod 640 {} \;
sudo find $dir/bootstrap/cache -type d -exec chmod 770 {} \;
sudo find $dir/bootstrap/cache -type f -exec chmod 660 {} \;
sudo find $dir/storage -type d -exec chmod 770 {} \;
sudo find $dir/storage -type f -exec chmod 660 {} \;
# To be writable by httpd.
sudo chgrp www-data -R $dir/bootstrap/cache
sudo chgrp www-data -R $dir/config
sudo chgrp www-data -R $dir/storage
# Laravel Env
sudo chmod 640 .env
sudo chgrp www-data .env
echo "Done!"
else
echo "It doesn't looks like a Laravel project!"
fi