How to install Laravel 4 to a web host subfolder w

2019-01-03 03:59发布

I was wondering if any of you know of a way to install Laravel 4 in a web host SUBDIRECTORY / subfolder while not exposing the /app/ folder and other sensible files to the publicly accesible part of the host.

The idea is, I'd be able to access http://mydomain.com/mylaravel/ to be able to use Laravel, but at the same time I want to avoid anyone doing something like going to http://mydomain.com/app/ or http://mydomain.com/mylaravel/app/ and basically being able to see my config files and other code.

9条回答
smile是对你的礼貌
2楼-- · 2019-01-03 04:30

If you're using an apache server, the simplest way to do this is to host store your Laravel application outside of the www root (or in a protected folder in www root) then symlink the desired subfolder to point it the public folder in laravel

For example, I place my laravel installations in:

/usr/local/share/myLaravel

Then, in your public www folder, create a symlink as so:

ln -s /usr/local/share/myLaravel/public mylaravel

You'll need to make some adjustments to your installation, like putting your Rewrite Base to /mylaravel/ and make sure that your config files allow overrides in the base location, but this is simpler than modifying everything.

查看更多
Melony?
3楼-- · 2019-01-03 04:34

You can use an alias: no hankey-pankey with widespread directories on your system.

Specify in your httpd.conf or admin-panel:

/mylaravel/ /path/to/laravel/public

Furthermore, specify the URL in your Laravel's app.php

Line 29

'url' => 'http://yourdomain.com/mylaravel/',

Eventually set the RewriteBase in your /public/.htaccess

RewriteBase /mylaravel/

Works like a charm and keeps your directory structure clean and to the point!

查看更多
叼着烟拽天下
4楼-- · 2019-01-03 04:34

Make sure to check your permissions. I deployed through the following although I don't recommend it.

I used SSH and did something like:

rm -rf public_html/ // WARNING: READ NOTE AT THE BOTTOM BEFORE RUNNING

ln -s project_folder/public/ public_html  // where the format is ln -s target name

Afterwards, I would receive a message like "Whoops, looks like something went wrong" (or an error depending on your debug settings). To fix this, I just had to change my permissions to 755 for my folders. reference: http://kb.webhostface.com/laravel/fix-permission-denied-error-laravel

Overall, I'm going to go back and try the original way with changed permissions as I find this route to be less secure, and more reliant on my hosting customer service.

*****Note***** This command obviously removes your public_html (also sometimes called public or www) folder. You need to have a backup of all the files in it because you are deleting it. Also, you will need to be prepared to go through customer service to restore it. Many hosting services don't allow you to simply recreate the folder on your own.

查看更多
Ridiculous、
5楼-- · 2019-01-03 04:37

So I figured out how to do this. I'll explain with an example.

Suppose you a domain, http://domain.com. Here's an example of the structure you might be using:

domain.com/    (the root of your web hosting)
|-- yourlaravel4_base/
|-- [some other folders...]
|-- public_html/    (where your html files and such go)
|   |-- [some other folders...]
|   |-- yourlaravel4/

/public_html/ is the root of the publicly accessible part of your web hosting files. You want to create a subfolder in /public_html/ (in this case /public_html/yourlaravel4/). In this subfolder you will store all the contents of the Laravel 4 public/ folder.

Now, for the rest of the files. You have to go to the root of your web hosting files, that is, you wanna be at domain.com/ level, therefore being able to see public_html/ and some other folders. Then, we need to create a folder here, where Laravel 4's base files will be stored. In this case, it's domain.com/yourlaravel4_base/. Inside yourlaravel4_base/ we need to store every file and folder that exists in the base Laravel 4 directory. That would be app/, bootstrap/, vendor/, server.php, etc. Everything EXCEPT the /public/ folder, whose contents you already stored in public_html/yourlaravel4/.

Finally, we need to edit 2 files: Laravel's /bootstrap/paths.php and /public/index.php.


In the paths.php file, replace:

'app' => __DIR__.'/../app',

with:

'app' => __DIR__.'/../../yourlaravel4_base/app',

In the paths.php file, replace:

'public' => __DIR__.'/../public',

with:

'public' => __DIR__,

In the paths.php file, replace:

'base' => __DIR__.'/..',

with:

'base' => __DIR__.'/../../yourlaravel4_base',

In paths.php, replace:

'storage' => __DIR__.'/../app/storage',

with:

'storage' => __DIR__.'/../../yourlaravel4_base/app/storage',

In index.php, replace:

require __DIR__.'/../bootstrap/autoload.php';

with:

require __DIR__.'/../../yourlaravel4_base/bootstrap/autoload.php';

In index.php, replace:

$app = require_once __DIR__.'/../bootstrap/start.php';

with:

$app = require_once __DIR__.'/../../yourlaravel4_base/bootstrap/start.php';

Upload changes. Now you should be able to have Laravel 4 installed in a subfolder in your website without actually exposing the app/ folder and other sensitive files. :)

查看更多
走好不送
6楼-- · 2019-01-03 04:38

If you are trying to run Laravel 5.1 into a shared hosting space and all of the above answers seems to be a bit different from the actual Laravel files/folders or you are looking how to put your laravel 5/5.1 into a sub directory on your shared hosting space so you can access it like this:

http://mywebsite.com/mylaravel/

So this answer is for you, first of all make sure you meet

Laravel 5.1 requirements :

- PHP 5.5
- PHP extension Mcrypt
- PHP extension Mbstring
- PHP extension OpenSSL

here an easy two tutorials for you :

Link 1

Link 2

查看更多
冷血范
7楼-- · 2019-01-03 04:45

if you are using addondomain or subdomaind wizard in your panel ,wizard should ask you for document root . for example i want to addon droidman.com , wizard should suggest me with making droidman.com folder . in this step tell wizard to make droidman.com/public folder . then put your application in droidman.com folder . your host will look at public folder ;) . problem solved

查看更多
登录 后发表回答