HostGator 共享计划上的 Laravel 设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22897883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel setup on HostGator shared plan
提问by user1380281
I'm trying to setup Laravel on a HostGator shared plan. I've followed these instructions:
我正在尝试在 HostGator 共享计划上设置 Laravel。我已按照以下说明操作:
http://laravel.io/forum/02-13-2014-how-to-install-laravel-on-a-hostgator-shared-server
http://laravel.io/forum/02-13-2014-how-to-install-laravel-on-a-hostgator-shared-server
I created and uploaded the .bashrc and .bash_profile files as instructed, then I run:
我按照说明创建并上传了 .bashrc 和 .bash_profile 文件,然后运行:
source ~/.bashrc
source ~/.bashrc
in the terminal, but then when I run php -v
I get
在终端中,但是当我跑步时,php -v
我得到
No such file or directoryphp
没有这样的文件或目录php
I also tried uploading an htaccess file with AddHandler application/x-httpd-php55 .php to the root directory. When I run phpinfo()
now, it shows php version 5.5.10, but php -v (before I run the source command) still shows version 5.2.17.
我还尝试将带有 AddHandler application/x-httpd-php55 .php 的 htaccess 文件上传到根目录。当我phpinfo()
现在运行时,它显示 php 版本 5.5.10,但 php -v(在我运行 source 命令之前)仍然显示版本 5.2.17。
Any idea what I'm doing wrong?
知道我做错了什么吗?
回答by user1380281
I was finally able to get Laravel installed with some help from this:
我终于能够在一些帮助下安装 Laravel:
http://shincoding.com/laravel/installing-configuring-laravel-shared-hosting/
http://shincoding.com/laravel/installing-configuring-laravel-shared-hosting/
回答by lalo
STEP 1 Copy your files
步骤 1 复制您的文件
Copy your app in a non-publicfolder, example:
将您的应用复制到非公共文件夹中,例如:
/home/foo/myapp
Move your public folder to a publicfolder, example:
移动公用文件夹到一个公共文件夹,例如:
/home/foo/public_html/public
Open your public/index.php file and change paths to reference your laravel non-public code, example:
打开您的 public/index.php 文件并更改路径以引用您的 Laravel 非公开代码,例如:
require __DIR__.'/../../../myapp/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../../myapp/bootstrap/app.php';
STEP 2 Change php version in Cpanel
STEP 2 在 Cpanel 中更改 php 版本
For laravel 5.2 you need at least php 5.5
对于 Laravel 5.2,您至少需要 php 5.5
https://laravel.com/docs/5.2/installation#server-requirements
https://laravel.com/docs/5.2/installation#server-requirements
this will add some lines in your .htaccess, for example, this will enable php7:
这将在您的 .htaccess 中添加一些行,例如,这将启用 php7:
# Use PHP70 as default
AddHandler application/x-httpd-php70 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php70/lib
</IfModule>
STEP 3 Make artisan work
STEP 3 制作工匠作品
php command line may not work, run this command to check php version:
php 命令行可能不工作,运行此命令检查 php 版本:
php -v
if it doesn't give you the correct version you may run your commands directly with php 5.6 binary, like this:
如果它没有为您提供正确的版本,您可以直接使用 php 5.6 二进制文件运行您的命令,如下所示:
/opt/php56/bin/php artisan
STEP 4 clear caches
STEP 4 清除缓存
Sometimes you need to clear your cache, there's two ways:
有时您需要清除缓存,有两种方法:
With artisan:
与工匠:
/opt/php56/bin/php artisan optimize
Manually:
手动:
Delete this two files
删除这两个文件
- bootstrap/cache/compiled.php
- bootstrap/cache/services.json
- 引导程序/缓存/compiled.php
- 引导程序/缓存/services.json
How to use SSL
如何使用 SSL
Hostgator shared servers have a shared SSL certificate
Hostgator 共享服务器具有共享 SSL 证书
To use the shared SSL certificate you must access your public folder by the root of your server and your username like this:
要使用共享 SSL 证书,您必须通过服务器的根目录和您的用户名访问您的公共文件夹,如下所示:
https://gator1234.hostgator.com/~username
https://gator1234.hostgator.com/~用户名
So for example, if you put your application in a folder called myapp it will become:
例如,如果您将应用程序放在名为 myapp 的文件夹中,它将变成:
https://gator1234.hostgator.com/~username/myapp
https://gator1234.hostgator.com/~username/myapp
this will mess the routes file, so you have to add this lines to your .htaccess
这会弄乱路由文件,因此您必须将此行添加到您的 .htaccess
RewriteEngine On
RewriteBase /~username/myapp
回答by Tushar
I recently wrote an article on how I was able to host my laravel 5.5 on a shared host. (Hostgator) https://www.5balloons.info/hosting-laravel-5-5-project-on-shared-hosting-hostgator/
我最近写了一篇关于如何在共享主机上托管 Laravel 5.5 的文章。(Hostgator) https://www.5balloons.info/hosting-laravel-5-5-project-on-shared-hosting-hostgator/
回答by yardpenalty.com
So there is one simple step that seems to get overlooked with most of the issues of setting up a subdomain to host a Laravel App using HostGator's Shared Hosting plan.
因此,在使用 HostGator 的共享托管计划设置子域以托管 Laravel 应用程序的大多数问题中,有一个简单的步骤似乎被忽略了。
HostGator Shared Server Hosting Plan
HostGator 共享服务器托管计划
Scenario:
设想:
Domain:https://yardpenalty.comis pointing to the home/username/public_html
folder which has a WordPress installation.
域:https ://yardpenalty.com指向home/username/public_html
安装了 WordPress的文件夹。
Subdomain:https://games.yardpenalty.comis pointing to the home/username/games/public
folder which has a Laravel App installation.
子域:https :home/username/games/public
//games.yardpenalty.com指向安装了 Laravel 应用程序的文件夹。
Problem:
问题:
We want the Laravel App to be accessed at the Subdomain's root level...
我们希望在子域的根级别访问 Laravel 应用程序...
URIat https://games.yardpenalty.com
URI在https://games.yardpenalty.com
NOTat https://games.yardpenalty.com/public.
不是在https://games.yardpenalty.com/public。
Solution:
解决方案:
Step 1:
第1步:
Under our HostGator Shared Server Hosting Plan we can access the tools we need using cPanel.
在我们的 HostGator 共享服务器托管计划下,我们可以使用 cPanel 访问我们需要的工具。
Step 2:
第2步:
In our cPanel we go-to Domains->Subdomainsand we enter a name for our Subdomain
(in this instance its called games
).
在我们的 cPanel 中,我们转到Domains->Subdomains并输入我们的名称Subdomain
(在本例中称为games
)。
Step 3:
第 3 步:
Then we select a Domain
from the dropdown list and in this scenario it is yardpenalty.comwhich is pointing to my public_html
folder.
然后我们Domain
从下拉列表中选择一个,在这个场景中它 是指向我的文件夹的yardpenalty.compublic_html
。
Step 4:
第四步:
Finally, under the Document Root /
(a.k.a. home/user
) we point it to the /games/public
folder!
最后,在Document Root /
(又名home/user
)下,我们将其指向/games/public
文件夹!
It should look something like the second listing from your cPanel:
它应该类似于您的 cPanel 中的第二个列表: