在Coding中部署Laravel项目演示
2018-05-28
后端
JellyBool
发表于 1周前- index.php (必须,这是你开启Coding项目演示的前提)
- Procfile (如果你想使用诸如Nginx等服务,这个文件必须)
- nginx_app.conf (自定义服务的相关的配置项)
include('/path/to/public/index.php');
将上面的/path/to/public/index.php改为你对应的目录 然后在Procfile中增加下面一行定于内容: web: vendor/bin/heroku-php-nginx -C nginx_app.conf上面这一行的意思是: 我:“我要使用Nginx” Coding:“好的,那你的配置在哪呢?” 我:“就是后面的 nginx_app.conf” Coding:“OK,我会去找这个文件” 所以最后,我们需要在nginx_app.conf中加入我们自己的配置:
location / {# try to serve file directly, fallback to rewritetry_files$uri@rewriteapp; }location@rewriteapp {# rewrite all to index.phprewrite ^(.*)$ /index.php/$1last; }location~ ^/(app|app_dev|config).php(/|$) {fastcgi_pass heroku-fcgi;fastcgi_split_path_info ^(.+.php)(/.*)$;include fastcgi_params;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param HTTPS off; }上面这一段代码中,我们需要注意的是在location @rewriteapp这一段,这个意思就是,我需要重写到index.php,到这里,我们的Nginx服务器就配好了。 2.第二步我们来配置我们的数据库Mysql,根据官方文档的说明: 演示平台服务的连接信息可以通过在应用内读取并解析 VCAP_SERVICES 环境变量获取 所以我们该怎么获取这个变量呢,我们可以直接修改config/database.php,为其加上一点内容:
$db_config = [];if($_ENV["VCAP_SERVICES"]){$mysql_config = json_decode($_ENV["VCAP_SERVICES"])->mysql[0]->credentials;$db_config["host"] = $mysql_config->hostname;$db_config["port"] = $mysql_config->port;$db_config["user"] = $mysql_config->username;$db_config["password"]= $mysql_config->password;$db_config["database"] = $mysql_config->name; }else{$db_config["host"] = 'localhost';$db_config["port"] = 3306;$db_config["user"] = 'root';$db_config["password"]= '';$db_config["database"] = 'test'; }当然你也可以写到其他地方去然后再在config/database.php中include进来,但是为了方便,我就直接写在前面了,还有就是,在这个文件中,我们不要忘了修改下面的内容:
'mysql' => ['driver' => 'mysql','host' => $db_config["host"],'database' => $db_config["database"],'username' => $db_config["user"],'password' => $db_config["password"],'charset' => 'utf8','collation' => 'utf8_unicode_ci','prefix' => '','strict' => false, ],没错,就是将数据库的链接直接交给Coding的VCAP_SERVICES这个环境变量了。写到这里,我们的代码部分就OK了,Easy enough… 3.在Coding上实际操作--在上面的步骤都搞定之后,我们将整个代码库push到Coding上,如果你没有走错步骤的话,你会看到类似下面这个样子的:


1: 填入master2:选择PHP 3:点击一键部署(等两分钟左右就好了) 4:选择服务管理进入到这个界面(蓝色的框框中的域名我们是可以自定义的,我们等下会说到这点):





- 修改我们的项目访问域名(起一个你喜欢的名字)
- 点击确定
- 点击重启
