laravel 5.6和apache给出404的URL

时间:2018-08-19 13:08:29

标签: laravel apache apache2.4

我在Ubuntu 16.04LTS上有apache2服务器,现在当我访问本地主机时,我在/ var / www / html中有一个名为book_donation的Laravel 5.6项目。 >

  

未找到

     

在此上找不到所请求的URL / book_donation / public / login   服务器。位于127.0.0.1端口80的Apache / 2.4.18(Ubuntu)服务器

这是.htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

这是我的/etc/apache2/site-available/000-default.conf:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    <Directory "/var/www/html">
         AllowOverride all
         Require all granted
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

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

我的php版本是7.1,apache版本是2.4.18,如何解决呢?

2 个答案:

答案 0 :(得分:0)

docs中所述,您应将Web服务器的文档/ Web根目录配置为公共目录。

创建一个新文件/etc/apache2/site-available/book_donation.test.conf

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName book_donation.test
    ServerAlias www.book_donation.test
    DocumentRoot /var/www/html/book_donation/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

编辑您的/etc/hosts文件并添加以下内容:

127.0.1.1   book_donation.test

然后运行:

sudo a2ensite book_donation.test.conf
sudo service apache2 restart

然后,您应该可以访问book_donation.test并查看您的网站。

答案 1 :(得分:0)

我面临着同样的问题,任何新路线均无法正常工作,并给出了404错误。还要检查php artisan route:list,其中新的路由详细信息可以正确显示,但仍然无法正常工作。我也尝试按照以下命令使其工作

php工匠观点:清晰 PHP的工匠配置:清除 php artisan cache:clear

这是我的项目详细信息

我的DocumentRoot是/ var / www / html / project / public。当在web.php中添加新路由时,它不起作用并给出404错误,但根路由运行正常。意味着任何新路线都在起作用。所以我做了以下更改,它开始起作用。

在/etc/apache2/sites-available/project.conf中进行了更改

<目录/ var / www / html / project / public>

**Allowoverride All**

并通过运行 sudo a2enmod rewrite

启用url重写 通过运行 sudo systemctl restart apache2

来重启apache服务器。