为什么我不能在服务器上部署的laravel项目上转到其他路线然后主页?

时间:2016-05-28 08:57:59

标签: apache laravel deployment

我刚刚将我的laravel项目部署到数字海洋。 mysql数据库已正确迁移和播种(在phpmyadmin中检查)。我现在可以浏览主页了。但是当我开始转到http://-ip-adress-/test之类的其他页面时,它会给我一个404 Not Not errorpage。通过一些论坛后,我认为它与我的apache配置和modrewrite规则有关。所以我将提供我编辑的所有文件来尝试解决这个问题:

我做了:

  • a2enmod rewrite
  • sudo chmod -R 755 bootstrap / cache
  • sudo chown -R www-data:storage
  • sudo chmod -R 755 storage
公共文件夹中的

.htacess文件:

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

    RewriteEngine On
    RewriteBase /var/www/gloops/public/
   # change above to your site i.e.,  RewriteBase /whatever/public/

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

apache2.conf文件:

ServerName localhost

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/gloops/public>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>
在etc / apache2 / sites-enabled中

000-default.conf:

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

1 个答案:

答案 0 :(得分:1)

AllowOverride设置为All并确保目录路径指向您的apache配置上的应用程序根目录而不是/var/www/gloops/public

<Directory /var/www/gloops>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

然后从您的应用程序根目录

键入以下命令
$ sudo chmod -R 0777 bootstrap/cache
$ sudo chmod -R 0777 storage
$ php artisan key:generate
$ php artisan cache:clear
$ php artisan optimize

我不认为0777是好的,您可以尝试0775,但对我而言0775无效。