How to Access Laravel Application running using php artisan serve in a Virtual Server from a Host Machine

Posted on

Introduction

The content of this article is primarily focus on accessing Laravel-based application running in a virtual server. The virtual server is available as part of the running VirtualBox application. In order to run the Laravel-based application in a virtual server running in a VirtualBox application, just read the article in this link. That article has a title of ‘How to Access Laravel Application running in a Virtual Server from a Host Machine’. After successfully running the Laravel-based application, just do the following step to access it from a host machine.

Steps for Accessing Laravel Application in a Virtual Server from a Host Machine

So, the steps for accessing the Laravel-based application exist as follows :

  1. First of all, access the VirtualBox Application as in the following image :

    How to Access Laravel Application running using php artisan serve in a Virtual Server from a Host Machine
  2. After that, just run the virtual server.

  3. Soon after the virtual server is successfully running, just access it. Actually the sequences or the steps is actually similar with the article in this link. It is an article with the title of ‘How to Run a Laravel-based Application using php artisan serve in a virtual server’.

  4. But on the step for running the ‘php artisan serve’, there is an additional parameter for allowing Laravel-based application for remote access. Just add the additional parameter -host with the value of ‘0.0.0.0’ as follows :

    [root@10 perpustakaan]# php artisan serve --host=0.0.0.0
    Starting Laravel development server: http://0.0.0.0:8000
    [Sat Mar 20 21:12:37 2021] PHP 7.4.16 Development Server (http://0.0.0.0:8000) started
    [Sat Mar 20 21:12:41 2021] 10.0.2.2:28654 Accepted
    [Sat Mar 20 21:12:42 2021] 10.0.2.2:28654 Closing
    [Sat Mar 20 21:14:03 2021] 127.0.0.1:53790 Accepted
    [Sat Mar 20 21:14:03 2021] 127.0.0.1:53790 Closing
    
  5. But that step is not enough. Read the article with the title of ‘How to Access Laravel Application running in a Virtual Server from a Host Machine’ in this link to learn how to access the application from the host machine. The main point is to add a port forwarding from the host machine to the virtual server or the guest machine. After adding the port forwarding rule, just access it via web browser. For an example, the host machine which is acting as a port to receive incoming connection is port 9000. So, accessing the service will be using the address of ‘http://localhost:9000’. The following is the appearance of the image :

    How to Access Laravel Application running using php artisan serve in a Virtual Server from a Host Machine

Leave a Reply