Reputation: 25
please, I am trying to host Laravel 5 on a shared hosting.
When I access www.example.com/my_app_name, the page loaded correctly. However, subfolders return 404 error. e.g. www.example.com/my_app_name/any_sub_folder or www.example.com/my_app_name/auth/login all return a 404 error.
shared_hosting_root
|--other_folders (not accessible via web domain)
|--applications (not accessible via web domain)
|--my_app_name
|--app
|--GoPublic.php <--I created this
|--bootstrap
|--config
|--database
|--public <--copied content to public_html
|--assets
|--index.php
|--resources
|--storage
|--tests
|--vendor
|--public_html
|--my_app_name
|--assets
|--index.php <-- I pointed here
I created a new file: shared_hosting_root\applications\my_app_name\app\GoPublic.php
<?php namespace App;
class GoPublic extends \Illuminate\Foundation\Application
{
/**
* Get the path to the public / web directory.
*
* @return string
*/
public function publicPath()
{
return $this->basePath.DIRECTORY_SEPARATOR.'../../public_html/my_app_name';
}
}
I edited bootstrap\app.php like so:
<?php
/* -- remove/comment this original code
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
-- until here */
/* -- add this new code -- */
$app = new App\GoPublic(
realpath(__DIR__.'/../')
);
I edited public\index.php like so: I changed this:
require __DIR__.'/../bootstrap/autoload.php';
to
require __DIR__.'/../../applications/my_app_name/bootstrap/autoload.php';
and also changed this:
$app = require_once __DIR__.'/../bootstrap/app.php';
to
$app = require_once __DIR__.'/../../applications/my_app_name/bootstrap/app.php';
I then copied the content inside applications\my_app_name\public into public_html\my_app_name.
I followed the steps highlighted in this tutorial: http://blog.kongnir.com/2015/09/25/setting-up-laravel-5-on-shared-hosting-server/
The problem again:
I can access www.example.com/my_app_name.
But I get a 404 error on www.example.com/my_app_name/any_sub_folder or even a login redirect www.example.com/myapp_name/auth/login
What am I doing wrong? Help, please. Thank you.
Update www.example.com/my_app_name/sub_folder returns 500 internal server error My .htaccess file in public_html directory:
# Do not change this line.
RewriteEngine on
# Change example.com to your domain name
# RewriteCond %{HTTP_HOST} ^(www.)?schoolsmart.com.ng$
# Change your_app_name to the subfolder name
# RewriteCond %{REQUEST_URI} !^/wbs/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change your_app_name to the subfolder name
# Change example.com to your domain name
# RewriteRule ^(.*)$ /wbs/$1
# RewriteCond %{HTTP_HOST} ^(www.)?schoolsmart.com.ng$
# RewriteRule ^(/)?$ wbs/index.php [L]
RewriteCond %{REQUEST_URI} !^wbs
RewriteRule ^(.*)$ wbs/$1 [L]
Upvotes: 0
Views: 417
Reputation: 49
For me chmoding the bootstrap, storage and yajra folder which is under vendor directory to 775, as suggested in the official laravel documentation, did the trick.
Upvotes: 0