Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

enadabuzaid's avatar

all websites I installed via herd give me 502 Bad Gateway error

I installed Herd and Laravel 11 the first time it was running and everything was okay with Example 11.test but when returned installed another project with MySQL showed me something related permission I clicked on deny then no website worked gave me 502 Bad Gateway

0 likes
1 reply
LaryAI's avatar
Level 58

It sounds like you're encountering a 502 Bad Gateway error after installing a new project with MySQL and encountering a permissions issue. This error typically indicates that the gateway or proxy server received an invalid response from the upstream server.

Here's a step-by-step solution to troubleshoot and resolve the issue:

  1. Check the Web Server Logs Start by checking the logs of your web server (Nginx or Apache). These logs often provide details that can help you understand the cause of the 502 error.

    For Nginx, you might find the logs at /var/log/nginx/error.log. For Apache, they might be at /var/log/apache2/error.log.

    # For Nginx
    sudo tail -f /var/log/nginx/error.log
    
    # For Apache
    sudo tail -f /var/log/apache2/error.log
    
  2. Check the PHP-FPM Service If you're using PHP-FPM, ensure that it's running and listening on the correct socket or port. You can check its status with:

    sudo systemctl status php-fpm
    

    If it's not running, try to start it:

    sudo systemctl start php-fpm
    
  3. File Permissions Since you mentioned a permissions issue, make sure that the web server user (often www-data for Nginx and Apache) has the correct permissions to access the files in your Laravel project.

    You can set the correct permissions using the following commands:

    sudo chown -R www-data:www-data /path/to/your/laravel/project
    sudo find /path/to/your/laravel/project -type f -exec chmod 644 {} \;
    sudo find /path/to/your/laravel/project -type d -exec chmod 755 {} \;
    
  4. Check the Configuration Files Verify that your web server's configuration files are set up correctly for your Laravel project. This includes checking the server block or virtual host configuration for Nginx or Apache, respectively.

    For Nginx, you might have a configuration file at /etc/nginx/sites-available/your-site that you need to review.

    For Apache, the configuration might be at /etc/apache2/sites-available/your-site.conf.

  5. Database Connection Since the issue occurred after installing a project with MySQL, ensure that your .env file in the Laravel project has the correct database credentials.

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=your_database
    DB_USERNAME=your_username
    DB_PASSWORD=your_password
    
  6. Clear Laravel Caches Sometimes, clearing the Laravel caches can resolve unexpected issues. Run the following commands from the root of your Laravel project:

    php artisan config:clear
    php artisan cache:clear
    php artisan route:clear
    php artisan view:clear
    
  7. Restart Services After making changes, restart your web server and PHP-FPM services to ensure all configurations are reloaded.

    # For Nginx
    sudo systemctl restart nginx
    
    # For Apache
    sudo systemctl restart apache2
    
    # For PHP-FPM
    sudo systemctl restart php-fpm
    

If after following these steps you're still facing the issue, please provide more specific error messages from your logs, and we can further diagnose the problem.

Please or to participate in this conversation.