Skip to content

Instantly share code, notes, and snippets.

@NeftaliYagua
Last active June 19, 2024 07:03
Show Gist options
  • Save NeftaliYagua/825b6ce483b92a296caa0f37e4ff040a to your computer and use it in GitHub Desktop.
Save NeftaliYagua/825b6ce483b92a296caa0f37e4ff040a to your computer and use it in GitHub Desktop.

Laravel Permissions Fix Script

A simple bash shell script to update Laravel files and folders group permission with SELinux

TO RUN (after logging in to your server using SSH):

1. Navigate to laravel directory

cd /var/www/laravel

2. Run the script to set permission:

curl -1sLf 'https://gist.githubusercontent.com/NeftaliYagua/825b6ce483b92a296caa0f37e4ff040a/raw/laravel-permissions-fix.sh' | sh

3. Run the script to set SELinux:

curl -1sLf 'https://gist.githubusercontent.com/NeftaliYagua/825b6ce483b92a296caa0f37e4ff040a/raw/laravel-selinux-fix.sh' | sh
export APACHE_USER=$(ps -ef | grep -E '(httpd|apache2|apache)' | grep -v `whoami` | grep -v root | head -n1 | awk '{print $1}')
mkdir ./storage/app/livewire-tmp
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chgrp -R $APACHE_USER ./storage ./bootstrap/cache
chmod -R ug+rw ./bootstrap/cache ./storage
restorecon -Rv .
chcon -R -t httpd_sys_rw_content_t bootstrap/cache
chcon -R -t httpd_sys_rw_content_t storage
chcon -R -t httpd_log_t storage/logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment