Laravel 5 directory structure on shared hosting - php

I am new to Laravel and started learning v5 few months back. I have created a sample application and want to deploy it over production (Shared hosting).
The easiest way for me is to put all content including app, vendor, config, tests etc folders directly to public_html but I don't want to do this. I want to keep laravel specific things outside the public_html and put only content from public folder to this directory.
What are the options available to do this?
Also, can I share same laravel installation for multiple applications?

on public/index.php add after
$app = require_once __DIR__.'/../bootstrap/app.php';
this:
$app->bind('path.public', function() {
return __DIR__;
});
Now You can change public directory to public_html

Keep your code outside of the public_html and create a symbolic link from public_html to the public directory in your laravel directory.

Related

How to prevent Laravel application folders from being indexed by search engines

I tried to key my site's domain into the google search engine and was shocked to realize that the application folders that shouldn't be public have been indexed. Folders and files are like composer.json, a vendor directory, storage directory, resources directory among others.
How I set up:
The application is in the public_html directory, the index.php is the entry point and is in the root directory(public_html)
The other Laravel application directories remain as they are(the default Laravel 7 directory structure)
The application is in the public_html directory, the index.php is the entry point and is in the root directory(public_html) The other Laravel application directories remain as they are(the default Laravel 7 directory structure)
In a default Laravel installation, there is no index.php in the project directory, only a server.php. If you did any change here, please revert them since it would cause a major security issue.
The only Laravel directory that should be publicly accessible is public.
You are using Apache, it means that the DocumentRoot should be set to /path/to/your/project/public (where public is the Laravel public directory).
This way, every files and directories (app, resources...) above this one will not be accessible.
you should move all your project files to root then copy your files from public to public_html then point topublic_html in Laravel:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
public function register()
{
$this->app->bind('path.public', function() {
return base_path().'/public_http';
});
}
Also you can see: How to change public folder to public_html in laravel 5

How to deploy lumen framework on shared hosting (subdomain)

I have project on localhost and I Need someone can help me to deploy lumen framework to hosting, i have been search in google for deploy lumen but i just found deploy laravel, maybe laravel and lumen is the same framework but i don't know how to deploy the lumen framework to my shared hosting in subdomain.
I have be been upload to :
/home/usernamecpanel/lumen
and public folder i put to my subdomain like
/home/usernamecpanel/public_html/subdomain/index.php
/home/usernamecpanel/public_html/subdomain/.htaccess
but i just got error 500.
oh, before i run i have been edit index.php to directing to lumenproject :
$app = require __DIR__.'/../../lumen/bootstrap/app.php';
I really confuse and i have been search in few day but cannot found the solution, i think someone can help me.
thank you.
Thanks for reviewing my edit
How to Fix it?
Zipping your Lumen Project
Go to your shared hosting file manager
I assume your shared hosting file manager have this directory structure like /home/username/public_html.
Create a folder outside public_html or htdocs, the folder name is up to you, example "myfolder" the structure looks like /home/username/myfolder
Upload your project to the new folder you have been created and unzip.
After unzip, inside the "myfolder" there is a folder named "public", move the contents inside to
For Main Domain
/home/username/public_html
For Subdomain or Subfolder
/home/username/public_html/sub
After moving those files, edit the index.php inside /home/username/public_html or /home/username/public_html/sub
Inside the file you see this code
$app = require __DIR__.'/../bootstrap/app.php';
change the code to
For Main Domain
$app = require __DIR__.'/../myfolder/bootstrap/app.php';
For Sub Domain/Subfolder
$app = require __DIR__.'/../../myfolder/bootstrap/app.php';
Don't forget to edit the APP_URL in .env file inside "myfolder"
Example the APP_URL .env file
APP_URL=http://yourdomain.com or http://sub.yourdomain.com or http://yourdomain.com/sub
I not got any answer from stackoverflow, and doesn't one onswer my question in stackoverflow, so i try hard find own solution with manual upload my lumen application in my shared hosting.
just put your lumen application in outside public_html and put your index.php file to subdomain and edit index.php set route to your subdomain.
if anyone have problem like me and read this question, you can ask from this question, i will help you if i got notice from this page.
You will need to move it with FileZilla to a subfolder inside /var/www/html/foldername and set configuration to the directory, but I wouldn't recommend you to set up a Micro Service in Shared host.

How to upload the laravel 5.2.42 project to cPannel?

please guide me how to upload the Laravel project to my cPanel I am very much confused.
you should add all the folders of laravel inside of public_html folder, and you need to move index.php and .htaccess file to the public_html directory from public directory. Now make changes index.php like this.
require DIR.'/bootstrap/autoload.php';
$app = require_once DIR.'/bootstrap/start.php';
That may work for you.
If you check your laravel project, there is a public folder inside it.
By default, your domain is pointed at the root level or on public_html. On you cPanel Domain settings, make sure your domain is pointed your Laravel application public folder.

Change .htaccess file in laravel 4

I have a problem when upload laravel project on my shared hosting. On that hosting I have two addon domains with separate folders in document root. But when I put laravel project in document root and move everything from public folder in root to remove that "/public" from url, I cant access to my addon domains. I'm getting 500 Internal service error. When I remove .htaccess file I can access to my other domains, but I can't access to my Laravel project. How can I change default laravel .htaccess file?
Well, you should not move everything from public folder, this is a very important part of your Laravel application, it was built this way to separate your application source code from the public files anyone can access, if you make your application root also your public folder, anyone will be able to access any php files from your application, and this is so unsafe...
What you need to do is to point your document root to /serverRoot/applicationRoot/public.
If you really cannot do that, I'm afraid you'll have to edit index.php and try to change thos two lines:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
to
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
And see if it works for you.
EDIT
Laravel's default .htaccess file is there just for rewriting your URLs, so you dont see aindex.php` on them. Basically it does 2 things:
1) If you access your site using http://www.site.com/, internally it will point to http://www.site.com/index.php.
2) When you access your site using http://www.site.com/index.php it hides the index.php part.
This is kind of recursive, because the first step leads to the second one.
Now you have to think and see how this is conflicting with your other domains, because the files you are serving in those domains matters and since we are not aware of what they are, helping more is kind of difficult.

Install a Laravel 4 Application in the Public directory of a site?

Is there anyway possible to install a Laravel PHP application into the same directory?
What I mean is as I see it, you have to install the whole Laravel application 1 directory under the the main Public directory.
I know that you can change the Public directory to anything in the settings but the server my client has, they really need for everything to live in 1 directory.
Current Folder Structure....
app/
bootstrap/
vendor/
public/
artison
server.php
If this was all dropped into a Public directory on the server, then you would have to access the application/website at the domain www.domain.com/public/
I am hoping there is a way to put all these files/folders into a public or www htdocs type folder and still access the application at the root.
I know the main reason to keep the PHP files out of the Public accessible folder is for security but in my clients situation this is not possible the way there server is configured.
Surely there is a way to do this?
Try putting contents of public in same directory as other folders, and then edit your index.php previously in public to look something like this
require __DIR__./bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
I haven't tried this. Just came to my mind right now
Anyway, I'm doing this by keeping app, boootstrap, vendor in / of my hosting, and contents of public are in my public_html. It works fine, and I guess it could be a security plus.

Categories