Ad

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 http://139.59.28.165:8000) (Port 8000 enabled in firewall). But when I browse the link http://139.59.28.165:8000, 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

</VirtualHost>

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

Answer

Try this

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

<VirtualHost *:8000>
        ServerName 139.59.28.165: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
        </Directory>

</VirtualHost>

Run the following command

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

Add the following in the hosts file /etc/hosts

127.0.0.1 139.59.28.165

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

Ad
source: stackoverflow.com
Ad