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

marekbrze's avatar

Exposing app on specific port on Laravel Forge?

Hi all,

I got hobby shared server where I can expose my apps on specific ports -> for example xxx.xxx.xx.xx:10123. Is it possible to setup Laravel Forge server to expose app only on selected ports?

0 likes
1 reply
LaryAI's avatar
Level 58

Certainly! To expose your Laravel application on a specific port using Laravel Forge, you can follow these steps:

  1. SSH into your server: First, you need to SSH into your server where your Laravel application is hosted.

    ssh forge@your-server-ip
    
  2. Edit the Nginx configuration: Navigate to the Nginx configuration file for your site. This is typically located in /etc/nginx/sites-available/your-site.

    sudo nano /etc/nginx/sites-available/your-site
    
  3. Modify the listen directive: In the Nginx configuration file, you will find a server block. Modify the listen directive to specify the port you want to expose. For example, if you want to expose your app on port 10123, you would change it to:

    server {
        listen 10123;
        server_name your-domain.com;
    
        # Other configurations...
    }
    
  4. Restart Nginx: After saving the changes to the Nginx configuration file, you need to restart Nginx to apply the changes.

    sudo systemctl restart nginx
    
  5. Ensure firewall rules: Make sure that your server's firewall allows traffic on the specified port. You can use ufw (Uncomplicated Firewall) to allow traffic on port 10123.

    sudo ufw allow 10123
    sudo ufw reload
    
  6. Access your application: Now, you should be able to access your Laravel application via http://your-server-ip:10123.

Here is a summary of the steps in code format:

# SSH into your server
ssh forge@your-server-ip

# Edit the Nginx configuration
sudo nano /etc/nginx/sites-available/your-site

# Modify the listen directive in the Nginx configuration file
# Example:
# server {
#     listen 10123;
#     server_name your-domain.com;
#     
#     # Other configurations...
# }

# Restart Nginx to apply changes
sudo systemctl restart nginx

# Ensure firewall rules allow traffic on the specified port
sudo ufw allow 10123
sudo ufw reload

By following these steps, you can configure your Laravel application to be exposed on a specific port using Laravel Forge.

Please or to participate in this conversation.