Saroj Shrestha
Saroj Shrestha

Reputation: 2875

Virtual hosts not working properly in ubuntu LAMP stack

I have created virtual hosts in the following ways:

  1. Created laravel.test.conf as
 - cd /etc/apache2/sites-available
 - sudo nano laravel.test.conf
  1. And then updated laravel.test.conf as
<VirtualHost *:80>

    ServerName laravel.test
    ServerAlias www.laravel.test
    ServerAdmin [email protected]

    DocumentRoot /var/www/laravel/public
    <Directory /var/www/laravel/public/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

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

</VirtualHost>
  1. Run command: sudo a2ensite laravel.test

  2. Permission provided:

sudo chown -R www-data: /var/www/laravel
sudo chown -R $USER:$USER /var/www/laravel
sudo chmod -R 755 /var/www
  1. Added sitename on etc/hosts
127.0.0.1 laravel.test www.laravel.test
  1. Reloaded apache sudo systemctl reload apache2

  2. Run configtest sudo apachectl configtest and received Syntax Ok

  3. Restarted apache server sudo systemctl restart apache2

Now, when I hit larave.test it loads the site successfully, but when ever I tried to hit any other route then it returns 404 error as shown in image.

enter image description here

This app is the freshly installed laravel one with laravel breeze so I am pretty much confident that there is a valide route. On top of that, if it was laravel, error, it would have been log it on app level and there would be different UI for 404 pages.

I have checked error log on laravel/storage/logs as well as apache2 logs on var/log/apache2/error.log but both of these logs file are empty.

Upvotes: 3

Views: 2432

Answers (1)

Muhammad Hashir Anwaar
Muhammad Hashir Anwaar

Reputation: 614

Make sure your rewrite mod is enabled.

or simply run this in terminal

$ sudo a2enmod rewrite

$ sudo systemctl reload apache2

Upvotes: 6

Related Questions