简体   繁体   English

共享主机上的 Laravel - 子域

[英]Laravel on shared hosting - subdomain

I am trying to deploy my laravel application on a shared hosting.我正在尝试在共享主机上部署我的 Laravel 应用程序。 It should be deployed in www.subdomain.something.com它应该部署在 www.subdomain.something.com

My folder structure is:我的文件夹结构是:

    /laravel
       app/
       vendor/
       bootstrap/
       server.php
       artisan
       composer.json
       composer.lock
       phpunit.xml
   /public_html
       subdomain/
       index.php

My index.php have the following paths:我的 index.php 有以下路径:

require '/../../laravel/bootstrap/autoload.php';
$app = require_once '/../../laravel/bootstrap/start.php';

My paths.php我的路径.php

'app' => __DIR__.'/../../laravel/app',
'public' => __DIR__.'/../../public_html/subdomain',
'base' => __DIR__.'/../../laravel',
'storage' => __DIR__.'/../../laravel/app/storage',

Can anyone see what I am missing?谁能看到我错过了什么? I tried google, and found a bunch of step-by-step explanations but nothing seems to work - It results in a 500 internal server error.我试过谷歌,找到了一堆分步说明,但似乎没有任何效果 - 它导致 500 内部服务器错误。

Thanks for any feedback感谢您的任何反馈

Wesley卫斯理

Follow the first rule here .遵循这里的第一条规则。 If you use the first rule then everything should work fine.如果您使用第一条规则,那么一切都应该正常工作。 But somehow if you face 500 Internal Server Error then login to ur server public_html directory through ssh and give the following command.但是不知何故,如果您遇到500 Internal Server Error然后通过ssh登录到您的服务器public_html目录并给出以下命令。

sudo chmod 755 -R laravel

chmod -R o+w laravel/storage

Here laravel is your Laravel project directory.这里laravel是你的 Laravel 项目目录。

Make sure you have write permissions to app/storage/ and all the sub directories.确保您对app/storage/和所有子目录具有写入权限。 This sounds like the culprit but if not then see if you get any errors in the app/storage/logs dir.这听起来像是罪魁祸首,但如果不是,请查看app/storage/logs目录中是否有任何错误。 If not see if you can parse the server logs.如果没有,看看是否可以解析服务器日志。

I was having similar problem and found the solution.Maybe someone can get help with this,我遇到了类似的问题并找到了解决方案。也许有人可以得到帮助,

Install LARAVEL 5 Locally Same as Share Hosting Directory (Deploy L5 Share Hosting Solution) 在本地安装 LARAVEL 5 与共享托管目录相同(部署 L5 共享托管解决方案)

I tried to deploy my first Laravel 8 application on shared hosting on DreamHost, and did encounter some issues.我尝试在 DreamHost 上的共享主机上部署我的第一个 Laravel 8 应用程序,但确实遇到了一些问题。

  1. First I was not able to use composer.首先,我无法使用作曲家。 Composer 1 was available however, I was unable to upgrade it to Composer 2. ( Was getting errors) Composer 1 可用,但我无法将其升级到 Composer 2。(出现错误)
  2. Finally, I ended up uploading all files from my local system to the subdomain root folder (eg cota.mydomain.com)最后,我最终将本地系统中的所有文件上传到子域根文件夹(例如 cota.mydomain.com)
  3. When I tried cota.mydomain.com , I got 404 error.当我尝试cota.mydomain.com 时,出现 404 错误。
  4. When I changed url to cota.mydomain.com/public/index.php , the application started working.当我将 url 更改为cota.mydomain.com/public/index.php 时,应用程序开始工作。 However, all href links which were defined like href="/home" or href="/client/create" started giving 'not found' errors.但是,所有定义为 href="/home" 或href="/client/create" 的href 链接都开始出现“未找到”错误。 To fix this issue I had to use named routes in href, eg href=" {{ route('client.show',['id'=>$client->id]) }}" .为了解决这个问题,我不得不在 href 中使用命名路由,例如href=" {{ route('client.show',['id'=>$client->id]) }}" This solved the issue, however, the URL displayed included public/index.php, eg cota.mydomain.com/public/index.php/client/show/1 .这解决了问题,但是,显示的 URL 包含 public/index.php,例如cota.mydomain.com/public/index.php/client/show/1
  5. To further fix the problem, I changed the web folder (root folder) for my subdomain to include public, ie cota.mydomain.com/public为了进一步解决这个问题,我将子域的 web 文件夹(根文件夹)更改为包含 public,即 cota.mydomain.com/public
  6. Next I added an index.php in cota.mydomain.con with the following contents header("Location: http://www.cota.mydomain.com/public/index.php"); die();接下来,我在 cota.mydomain.con 中添加了一个 index.php,其中包含以下内容header("Location: http://www.cota.mydomain.com/public/index.php"); die(); header("Location: http://www.cota.mydomain.com/public/index.php"); die();
  7. This fixed all issues, including remving public and index.php from link URLs.这修复了所有问题,包括从链接 URL 中删除 public 和 index.php。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM