在Apache虚拟主机上为Laravel项目设置文档根目录 [英] Setting document root for Laravel project on Apache virtual host

查看:92
本文介绍了在Apache虚拟主机上为Laravel项目设置文档根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个在我无权访问的Apache服务器上运行的php/Laravel应用程序.我的任务是让它在另一台Apache服务器上运行.我对php相当满意,但对Laravel而言相对较新,对Apache配置而言则相对较新.

I inherited a php/Laravel app that was running on an Apache server that I don't have access to. My task is to get it running on another Apache server. I'm pretty good with php but relatively new to Laravel and very new to Apache configuration.

我已经弄清楚了如何使Laravel应用程序在运行于Ubuntu VM(VirtualBox)(VirtualBox)上的Apache上运行.我可以通过 http://本地主机.我还可以通过 http://appname.com/public 从Internet上的浏览器中访问Laravel应用.但是,如果我只使用 http://appname.com ,那么我只会得到/var/www的文件夹列表/appname.

I have figured out how to get the Laravel app running on Apache that is running on an Ubuntu VM (VirtualBox.) I can access the Laravel app in a browser on the Ubuntu VM via http://localhost. I can also access the Laravel app in a browser from the Internet via http://appname.com/public. However, if I just use http://appname.com, then I just get a folder listing of /var/www/appname.

我已经尝试对/etc/apache2/av​​ailable-sites/appname.conf文件进行了一些修改,但显然还没有完全正确.我还阅读了许多有关修改其他各种配置文件(包括php配置文件和Apache配置文件)的文章.似乎这些其他mod(虽然它们可能是可行的)不是必需的.

I have tried several modifications to the /etc/apache2/available-sites/appname.conf file but haven't quite got it right yet, apparently. I have also read a number of posts around the nets about making modifications to various other config files including php config files and Apache config files. It seems like these other mods (while they may be workable) shouldn't be necessary.

这是我当前的/etc/apache2/av​​ailable-sites/appname.conf

Here is my current /etc/apache2/available-sites/appname.conf

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName appname.com
        ServiceAlias www.appname.com
        DocumentRoot /var/www/appname/public

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

任何建议都值得赞赏.

  • 鲍勃

推荐答案

您需要在Apache服务器中允许mod_rewrite和allowSymLinks. 来源

You need to allow the mod_rewrite in the apache server and allowSymLinks. Source

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName appname.com
    ServiceAlias www.appname.com
    DocumentRoot /var/www/appname/public

    <Directory "/var/www/appname/public">
            Options FollowSymLinks
            ReWriteEngine On
    </Directory>

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

在DocumentRoot目录中,我还将允许多视图

in the DocumentRoot Directory i would also allow MultiViews

<Directory "/var/www/appname/public">
        Options FollowSymLinks MultiViews
        ReWriteEngine On
</Directory>

您可能还需要做

sudo a2enmod重写

sudo a2enmod rewrite

启用模块重写.

在我的.conf文件中,我用引号引起了它们,并且它们正在工作. 您是否启用了模式重写?

In my .conf files i got them with the quotes and they are working. Did you enable the modudle rewrite?

除了一些选项,我还有一个带有下一个配置的"/"文件夹.

Besides some options i also have the "/" folder with the next config.

<Directory "/">
    Options FollowSymLinks
    AllowOverride All
    ReWriteEngine On
</Directory>

在这里,我将写我的公共目录的完整代码

and here i'll write my full code of public directory

<Directory "/var/www/appname/public">
        Options FollowSymLinks MultiViews
        Order Allow,Deny
        Allow from all
        ReWriteEngine On
</Directory>

在删除您不喜欢使用的选项之后,尝试一下并查看它是否有效.

Try it and see if it works, after delete the options that you don't like to use.

这篇关于在Apache虚拟主机上为Laravel项目设置文档根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆