How To Configure Laravel API To Port 8000 With Apache2?

- 1 answer

I am new to apache2 and DigitalOccean. I have a Laravel project API. I installed php mysql and apache2 on DigitalOcean server. I want to access the API with IP address and Port number 8000 (Like (Port 8000 enabled in firewall). But when I browse the link, it shows This site can’t be reached.

This site cannot be reached

But without port number it shows the directory

enter image description here

But I want with IP address and Port number like this: enter image description here

Current DocumentRoot(/etc/apache2/sites-available/000-default.conf)

<VirtualHost *:80>

    ServerAdmin [email protected]
    DocumentRoot /var/www/crm-api

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


Try this

Create a configuration file on the server name by sudo nano /etc/apache2/sites-available/ and add the following contents

<VirtualHost *:8000>
        ServerAdmin [email protected]
        DocumentRoot /var/www/crm-api/public

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory /var/www/crm-api>
                AllowOverride All


Run the following command

sudo a2dissite 000-default.conf
sudo a2ensite
sudo a2enmod rewrite
sudo service apache2 restart

Add the following in the hosts file /etc/hosts

And also add your port in ports configuration/etc/apache2/ports.conf

Listen 8000

Don't forget to restart the apache2 sudo service apache2 restart