Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Apache虚拟主机上为Laravel项目设置文档根目录_Php_Laravel_Apache - Fatal编程技术网

Php 在Apache虚拟主机上为Laravel项目设置文档根目录

Php 在Apache虚拟主机上为Laravel项目设置文档根目录,php,laravel,apache,Php,Laravel,Apache,我继承了一个在Apache服务器上运行的php/Laravel应用程序,我没有访问权限。我的任务是让它在另一台Apache服务器上运行。我对php很在行,但对Laravel比较陌生,对Apache配置也非常陌生 我已经找到了如何在Apache上运行Laravel应用程序,而Apache正在Ubuntu虚拟机(VirtualBox)上运行。我可以通过访问Ubuntu虚拟机上的浏览器来访问Laravel应用程序。我还可以通过Internet访问浏览器中的Laravel应用程序。但是,如果我只是使用,

我继承了一个在Apache服务器上运行的php/Laravel应用程序,我没有访问权限。我的任务是让它在另一台Apache服务器上运行。我对php很在行,但对Laravel比较陌生,对Apache配置也非常陌生

我已经找到了如何在Apache上运行Laravel应用程序,而Apache正在Ubuntu虚拟机(VirtualBox)上运行。我可以通过访问Ubuntu虚拟机上的浏览器来访问Laravel应用程序。我还可以通过Internet访问浏览器中的Laravel应用程序。但是,如果我只是使用,那么我只会得到一个文件夹列表/var/www/appname

我尝试了对/etc/apache2/available sites/appname.conf文件的几次修改,但显然还没有完全正确。我还阅读了许多关于修改其他各种配置文件(包括php配置文件和Apache配置文件)的帖子。看起来这些其他的MOD(虽然它们可能是可行的)不应该是必要的

这是我当前的/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>

服务器管理员webmaster@localhost
ServerName appname.com
ServiceAlias www.appname.com
DocumentRoot/var/www/appname/public
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
任何建议都将不胜感激

  • 鲍勃

您需要允许在apache服务器和allowSymLinks中重写mod_。


服务器管理员webmaster@localhost
ServerName appname.com
ServiceAlias www.appname.com
DocumentRoot/var/www/appname/public
选项如下符号链接
重新启动发动机
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
在DocumentRoot目录中,我还允许多视图

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

选项如下符号链接多视图
重新启动发动机
您可能还需要这样做

sudoa2enmod重写

启用模块重写

编辑1:

在我的.conf文件中,我得到了带引号的文件,它们正在工作。 您是否启用了模块重写

除了一些选项外,我还有下一个配置的“/”文件夹

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

选项如下符号链接
允许超越所有
重新启动发动机
在这里,我将编写我的公共目录的完整代码

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

选项如下符号链接多视图
命令允许,拒绝
通融
重新启动发动机

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

按照步骤操作,一切都会很好,很简单

1)。
终端中键入以下命令

cd/etc/apache2/可用站点

2)。创建一个新的配置文件

sudo cp 000-default.conf appname.dev.conf

3.打开新的配置文件并粘贴以下代码

<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 yourmail@example.com
        ServerAlias appname.dev
        DocumentRoot /var/www/html/appname/public

        <Directory /var/www/html/appname/public>
           Options -Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            Require all granted
            <FilesMatch \.php$>
               #Change this "proxy:unix:/path/to/fpm.socket"
               #if using a Unix socket
               #SetHandler "proxy:fcgi://127.0.0.1:9000"
            </FilesMatch>
        </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

#ServerName指令设置请求方案、主机名和端口
#服务器使用来标识自身。这在创建时使用
#重定向URL。在虚拟主机的上下文中,服务器名
#指定必须在请求的主机:标头中显示的主机名
#匹配此虚拟主机。对于默认虚拟主机(此文件),此
#该值不是决定性的,因为它被用作最后的宿主。
#但是,必须为任何其他虚拟主机显式设置它。
#服务器名www.example.com
服务器管理员yourmail@example.com
ServerAlias appname.dev
DocumentRoot/var/www/html/appname/public
选项-索引+FollowSymLinks+多视图
允许超越所有
要求所有授权
#将此“代理:unix:/path/更改为/fpm.socket”
#如果使用Unix套接字
#SetHandler“代理:fcgi://127.0.0.1:9000"
#可用日志级别:trace8、…、trace1、调试、信息、通知、警告、,
#错误、暴击、警报、紧急情况。
#还可以为特定应用程序配置日志级别
#模块,例如。
#日志级别信息ssl:警告
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
#对于conf/available/中的大多数配置文件
#在全局级别启用或禁用,可以
#仅包含一个特定虚拟主机的行。例如
#以下行仅为此主机启用CGI配置
#在使用“A2F”全局禁用后。
#包括conf available/service-cgi-bin.conf
#vim:syntax=apachets=4sw=4sts=4srnoet
4)。
CTRL+x
,然后
按y
然后
按enter
并在终端中运行以下命令

sudo a2ensite appname.dev.conf

5)。键入以下命令并编辑/etc/hosts文件

sudo nano/etc/hosts

127.0.0.1 appname.dev

按CTRL x
然后
按Enter
并键入以下命令

sudo服务apache2重启


6)。现在您的应用程序将在
appname.dev
上成功执行。

您是否在主机文件中设置了虚拟主机?Thnaks。我在哪里可以找到“hosts”文件。您可以尝试
sudo gedit/etc/hosts
并将虚拟主机写入该文件,如下所示:
127.0.0.1 appname.com
这是我当前的主机文件。我需要为新应用添加一行吗?127.0.0.1 localhost 127.0.1.1 linuxstudio#以下行适用于支持IPv6的主机::1 ip6 localhost ip6 loopback fe00::0 ip6 localne
<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 yourmail@example.com
        ServerAlias appname.dev
        DocumentRoot /var/www/html/appname/public

        <Directory /var/www/html/appname/public>
           Options -Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            Require all granted
            <FilesMatch \.php$>
               #Change this "proxy:unix:/path/to/fpm.socket"
               #if using a Unix socket
               #SetHandler "proxy:fcgi://127.0.0.1:9000"
            </FilesMatch>
        </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