Accessing my laravel project on remote networks fail with error "ERR_CONNECTION_REFUSED"

Updated: Feb 09, 2025

Accessing my laravel project on remote networks fail with error "ERR_CONNECTION_REFUSED"

When trying to access a Laravel project hosted on a remote server, you may encounter the error "ERR_CONNECTION_REFUSED" in your web browser. This error indicates that the connection to the server could not be established. There are several reasons why this error might occur, and we will discuss some common causes and solutions below.

  1. Firewall or Security Group Rules: The most common reason for this error is that the firewall or security group rules on the remote server are blocking the incoming traffic on the port that your Laravel application is listening on. By default, Laravel listens on port 80 for HTTP and port 443 for HTTPS. You can check the firewall rules by running the following command on the remote server:
sudo ufw status

If you are using a cloud provider like AWS, you can check the security group rules in the console. Make sure that the inbound rules allow traffic on the ports that your Laravel application is listening on.

  1. Apache or Nginx Configuration: Another reason for this error could be that the web server (Apache or Nginx) is not configured correctly to forward the traffic to your Laravel application. Check the web server configuration files to make sure that the Laravel project is correctly mapped to the virtual host or server block.

  2. Laravel Process Running: If your Laravel application is not running or is not started correctly, you may encounter the "ERR_CONNECTION_REFUSED" error. You can check the status of the Laravel process by running the following command on the remote server:

sudo systemctl status php-fpm

If the Laravel process is not running, you can start it by running:

sudo systemctl start php-fpm
  1. Database Connection: If your Laravel application is unable to connect to the database, it may throw an error that looks like "ERR_CONNECTION_REFUSED". Check the Laravel configuration file (.env) to make sure that the database credentials are correct. Also, make sure that the database server is running and is accessible from the remote server.

  2. Network Connectivity: If none of the above solutions work, it is possible that there is a network connectivity issue between your local machine and the remote server. You can try to ping the remote server to check if there is any network latency or packet loss. You can also try to access the Laravel application from a different network or using a VPN to see if that resolves the issue.

In summary, the "ERR_CONNECTION_REFUSED" error in Laravel can be caused by several reasons, including firewall rules, web server configuration, Laravel process status, database connection, and network connectivity. By following the steps above, you should be able to identify and resolve the issue.