简体   繁体   中英

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 admin@laravel.test

    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.

在此处输入图像描述

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.

Make sure your rewrite mod is enabled.

or simply run this in terminal

$ sudo a2enmod rewrite

$ sudo systemctl reload apache2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM