!!!郑重阐明!!!:虚拟主机通常无奈绑定运行目录到子目录,因而部署时会呈现太多的安全隐患,配置比拟繁琐,咱们强烈不举荐!此办法只给技术爱好者作为测试参考,不再提供额定技术支持。

!!!重要的事!!!:在虚拟主机配置环境下,因为网站的所有数据都被裸露在浏览器拜访门路下,因而要控制系统的系统文件不被拜访到,当您配置好之后,至多要测试一下门路不能间接被用户下载,否则零碎将会受到严重威胁。

http://www.example.com/.env
http://www.example.com/storag...
!!!其余阐明!!!:应用中遇到问题可间接百度/Google搜寻 虚拟主机部署Laravel 关键词自行解决。

应用虚拟主机装置前,请先下载环境的检测程序进行空间自荐,不满足要求的虚拟主机将不能装置。

环境检测脚本:https://modstart.com/env_chec...(opens new window)
如果您的虚拟主机根目录能够绑定到 <网站目录>/public 目录,请绑定到 <网站目录>/public 目录,随后执行 /install.php 装置向导。

如果您的虚拟主机根目录不反对绑定到 <网站目录>/public,须要依照如下配置:

配置 Nginx 或 Apache 服务器,请将网站的根目录配置到 <网站目录>,其中 Nginx 和 Apache 配置须要参考如下所示;
Nginx参考配置

server {    listen       80;    server_name  www.example.com;    charset utf-8;    index index.php index.html;    root /var/www/html/www.example.com;    autoindex off;    location ^~ /.git {        deny all;    }    location ^~ /.env {        deny all;    }    location ^~ /storage/ {        deny all;    }    location / {        try_files /public$uri /public$uri/ /public/index.php?$query_string;    }    location ~ \.php$ {        fastcgi_pass   127.0.0.1:9000;        fastcgi_index  index.php;        fastcgi_param  PHP_VALUE  "open_basedir=/var/www/html/www.example.com/:/tmp/:/var/tmp/";        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        include fastcgi_params;    }}

Apache参考配置

httpd配置

<VirtualHost *:80>  ServerName www.example.com  DocumentRoot d:/wwwroot/example.com</VirtualHost>

在网站零碎根目录减少 .htaccess 文件

<IfModule mod_rewrite.c>    RewriteEngine on    RewriteCond %{REQUEST_URI} !^public    RewriteRule ^(.*)$ public/$1 [L]</IfModule>

IIS参考配置

web.config 配置

<?xml version="1.0" encoding="UTF-8"?><configuration>  <system.webServer>    <directoryBrowse enabled="false" />    <rewrite>      <rules>        <rule name="Imported Rule 3" stopProcessing="true">          <match url="^(.*)$" ignoreCase="false" />          <conditions>            <add input="{APPL_PHYSICAL_PATH}public/{R:1}" matchType="IsFile" ignoreCase="false" negate="true" />          </conditions>          <action type="Rewrite" url="/public/index.php" />        </rule>        <rule name="Imported Rule 1" stopProcessing="true">          <match url="^(.*)$" ignoreCase="false" />          <action type="Rewrite" url="/public/{R:1}" />        </rule>      </rules>    </rewrite>  </system.webServer></configuration>

一些已知非凡环境配置阐明

阿里云虚拟主机
须要开启PHP5.5版本;
因为阿里云禁用了putenv函数,这个函数尤为重要,所以须要打一个函数补丁,在程序最开始(public/index.php)的地位嵌入PHP代码,putenv 函数被禁用补丁代码如下

function env($key, $defaultValue = null){    static $envFileConfig = null;    if (null === $envFileConfig) {        $envFileConfig = [];        $envFile = file_get_contents(__DIR__ . '/.env');        foreach (explode("\n", $envFile) as $line) {            $line = trim($line);            if (empty($line) || strpos($line, '#') === 0) {                continue;            }            list($k, $v) = explode('=', $line);            $envFileConfig[trim($key)] = trim($value);        }    }    if (array_key_exists($key, $envFileConfig)) {        return $envFileConfig[$key];    }    return $defaultValue;}