Question

How Can I Access My Laravel App Via A Web Browser?

Posted June 9, 2021 193 views
ApacheLaravel

I have created a droplet and installed Laravel on it as well as services that are needed for Laravel such as Apache. I can ping my droplet but receive “This site can’t be reached” when attempting to access my website through a web browser.

How can I access my Laravel app via a web browser?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi @curtiscolly,

You’ll need to create an Apache configuration file for your domain name. In order for Apache to serve your Laravel App’ content, it’s necessary to create a virtual host file with the correct directives. Instead of modifying the default configuration file located at /etc/apache2/sites-available/000-default.conf directly, let’s make a new one at /etc/apache2/sites-available/your_domain.conf:

sudo nano /etc/apache2/sites-available/your_domain.conf

Paste in the following configuration block, which is similar to the default, but updated for our new directory and domain name:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName your_domain
    ServerAlias www.your_domain
    DocumentRoot /path/to/your/website/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Notice that you need to update the DocumentRoot to your directory and ServerAdmin to an email that the your_domain site administrator can access. There are also two very important directives: ServerName, which establishes the base domain that should match for this virtual host definition, and ServerAlias, which defines further names that should match as if they were the base name.

Save and close the file when you are finished.

Let’s enable the file with the a2ensite tool:

sudo a2ensite your_domain.conf

Disable the default site defined in 000-default.conf:

sudo a2dissite 000-default.conf

Next, let’s test for configuration errors:

sudo apache2ctl configtest

You should see the following output:

Output
Syntax OK

Restart Apache to implement your changes:

sudo systemctl restart apache2

Regards,
KFSys