简体   繁体   中英

Laravel virtual server routing doesn't work

I have installed newest Laravel on my Apache2. I run in Terminal

php artisan serve --port=8080

And It works. I have sub-pages and everything I need. But I want to have access without run this command.

I have next mylaravel.com.conf file in /etc/apache2/sites-available

<VirtualHost *:80>
    ServerName mylaravel.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/mylaravel/public

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

My Laravel files is of course in /var/www/mylaravel . In this configuration mylaravel.com works, but when I try for simple mylaravel.com/auth/register Apache return

在此输入图像描述

When I used php artisan [...] this works fine. How can I fix it?

I had this same problem a while ago. From here :

If you don't have AllowOverride set to All, your Laravel .htaccess file (/public/.htaccess) won't be able to enable mod_rewrite, and your routes won't work.

Try adding the following to your <VirtualHost> block:

<Directory "/var/www/mylaravel/public">
    Options All
    AllowOverride All
    Allow from all
</Directory>

So all up you'd have:

<VirtualHost *:80>
    ServerName mylaravel.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/mylaravel/public

    <Directory "/var/www/mylaravel/public">
        Options All
        AllowOverride All
        Allow from all
    </Directory>

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

I found something. I added Sadurnias code and run in Terminal

sudo a2enmod rewrite sudo service apache2 restart

Of course I changed chmod of /var/www to 755.

It's working fine, only when I run mylaravel.com/css FireFox doesn't end this request, but others is fine.

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