-
-
Save fanorama/f3d883ea347888727c9ab6a6e63b265f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # Script Name: laravel_apache_setup.sh | |
| # Purpose: Configures file permissions and symbolic links for Laravel applications running under Apache on Ubuntu. | |
| # | |
| # Usage: | |
| # This script must be executed with root privileges to ensure it can correctly set permissions and ownership | |
| # across necessary directories and manage symbolic links. It is intended for use on an Ubuntu server configured with Apache. | |
| # | |
| # Set the APP_PATH environment variable to the root directory of your Laravel application before running the script: | |
| # export APP_PATH=/var/www/careerhub | |
| # | |
| # Make the script executable if it isn't already: | |
| # chmod +x laravel_apache_setup.sh | |
| # | |
| # Run the script: | |
| # sudo ./laravel_apache_setup.sh | |
| # | |
| # Requirements: | |
| # - The user must have sudo privileges. | |
| # - The Laravel artisan CLI must be available. | |
| # - PHP should be installed and functional. | |
| # - Standard Laravel directory structure should be intact. | |
| # | |
| # Ensures: | |
| # - Correct permissions and ownership for storage and bootstrap/cache directories. | |
| # - Correctly recreated symbolic link from public/storage to storage/app/public. | |
| # | |
| # Exit Codes: | |
| # 0 - Success | |
| # 1 - Script not run as root or APP_PATH not set | |
| # Ensure the script is run as root | |
| if [[ $(id -u) -ne 0 ]]; then | |
| echo "Please run as root" | |
| exit 1 | |
| fi | |
| # Check if APP_PATH environment variable is set | |
| if [ -z "${APP_PATH}" ]; then | |
| echo "The APP_PATH environment variable is not set." | |
| echo "Please export APP_PATH with the path to your Laravel application. For example:" | |
| echo "export APP_PATH=/var/www/careerhub" | |
| exit 1 | |
| fi | |
| # Change to the application directory | |
| cd "${APP_PATH}" || exit | |
| # Set permissions and ownership | |
| echo "Setting permissions and ownership..." | |
| find storage bootstrap/cache -type d -exec chmod 755 {} \; | |
| find storage bootstrap/cache -type f -exec chmod 644 {} \; | |
| chown -R www-data:www-data storage bootstrap/cache | |
| # Recreate the symbolic link | |
| echo "Recreating the storage symlink..." | |
| if [ -L public/storage ]; then | |
| unlink public/storage | |
| fi | |
| php artisan storage:link | |
| echo "Setup completed successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment