What will be my .htaccess code? I want to host my laravel project in godaddy server, my project path will be in public_html/coder.com ? In coder.com, i have to keep all my project files and folders. Any idea please someone help me.
You have to keep backend files outside of the public_html folder. The content of the Laravel public folder should be placed inside coder.com folder. That is, you index.php, .htaccess and the rest should be placed inside coder.com folder.
Then, you need to edit index.php to point to the correct locations of vendor and bootstrap folder.
If, say for example, you placed the Laravel backend files in a folder named laravel at the same level as public_html, it should be /../../laravel/vendor/autoload.php and /../../laravel/bootstrap/app.php.
You do not need to edit the content of the default .htaccess file.
But, shared hosting almost always gives you unforeseen troubles. If you do not have shell access, you might need to ask for technical help from GoDaddy team to fix symlink issues if required.
Normally, there will be no issues with folder permissions, if there is you need to make sure that storage and bootstrap/cache is writable. Never ever give 777 permissions; 755 for folder/directories and 644 for files will be good. For this also, since it's shared hosting, you might want to seek technical assistance from GoDaddy.
Related
I have a shared hosting with bluehost.com... can I just put my project on that.. like upload public files to public_html and others to root directory and backup MySQL DB and upload it to my shared hosting then edit my .env file... will this actually work with Laravel?
I searched most online resources and it requires ssh access to deploy, but the way I explained should not require that right?
I mean this way you don't have to go throw terminal access right?
I used to do that with WordPress when I want to set everything locally then upload it and edit URLs from the dashboard and stuff...
Yes it would work.
But you have to ensure one thing that, in your cpanel your domain point to the /public folder of laravel project.
Normally cPanel points the http requests to public_html folder, but laravel start from its public folder. You can achieve this by two way.
By pointing your server to straight to public folder
Copying the index.php to the public_html, in that case you have to edit index.php to run the laravel project properly. And I don't recommend this step. Step 1 is lot more easier.
I found the following part in Laravel's documentation.
"Laravel should always be served out of the root of the "web directory" configured for your web server. You should not attempt to serve a Laravel application out of a subdirectory of the "web directory". Attempting to do so could expose sensitive files present within your application."
Does it mean it should be always directly in root directory, not in subdirectories or the other way?
What if my server provider gives me root directory / and tells me to put my files into /www ?
Does it make it vulnerable then?
I disagree with the above answer of #Jean-Roch B. and agree with the comment of #Tpojka.
If the root of the "web directory" on your server is /var/www you should put Laravel in that folder
No. The root directory (DocumentRoot as defined by https://httpd.apache.org/docs/2.4/mod/core.html#documentroot) is aimed to allow the HTTP server to provide the client the files recursively under. Meaning that siblings and recursively parents directories can't be provided to the client.
What does it means? That if you put Laravel recursively under the root directory, you will have a security issue. For example, the config and environment files, your controllers, your migration files etc., would be provided to the client if this latter asks for them.
By saying the following:
Laravel should always be served out of the root of the "web directory" configured for your web server. You should not attempt to serve a Laravel application out of a subdirectory of the "web directory". Attempting to do so could expose sensitive files present within your application.
, Laravel docs are saying to NOT put the Laravel directory recursively under the document root. YOU ABSOLUTELY MUST PUT THE LARAVEL DIRECTORY RECURSIVELY ABOVE THE DOCUMENT ROOT.
The document root, with a Laravel site, must ONLY point to the directory app/public of the Laravel directory.
I will quote #Tpojka (see his comment to the OP's question), who is absolutely right:
Nothing outside public directory shouldn't be available to external access. Only public directory should be accessible by externals. Everything else is lot of work on securing application.
Also, quoting again #Jean-Roche B.:
Obviously it's not a good idea to put Laravel in /var/otherdirectory or /otherdirectory
, if like he was saying /var contains /var/www, I thin rather that Laravel could actually be put in /var, delete www, and make the root directory be the app/public directory (this is an example).
To end: the DocumentRoot can normally be configured in your Web Host configuration admin panel.
Laravel is not very clear on this.
But what I understand is:
If the root of the "web directory" on your server is /var/www you should put Laravel in that folder and not in /var/www/otherdirectory or /var/otherdirectory or /otherdirectory
Obviously it's not a good idea to put Laravel in /var/otherdirectory or /otherdirectory, but why they say only at the root of the "web directory" and not in /var/www/otherdirectory ? I think nobodies knows and Laravel can't explain it really.
The root directory on a linux server is /
The root of the "web directory"directory on a linux server can be whatever is in your web server configuration or whatever your provider gave you (if you can't manage the web server configuration), but most of the time it's in /var/www, /var/www/html or /var/www/domain.com
Also Laravel members seem to be saying that you can't use Laravel in a subdirectory website like https://example.com/website because (Laravel say) they don't support it and (Laravel say) it's not recommended, even if this website is served out of the root of the "web directory" which is /var/www in most cases.
(But why???)
See the discussion here: Discussion 34388
So I am assuming you are using a shared hosting server:
the way websites are hosted is using a web server (apache, nginx, ...etc) (if you are using godaddy or namecheap hosting they will have a webserver installed inside
) in these web servers you set a document root as in where should the server direct the requests.
Knowing this if your server says put the files in /www then its most likely that /www is the document root and its where you should put the files
Note: whatever server you use i would be 99.9% sure that you should not put the website files or the actual root of the server aka /
I am confused about the deployment of the laravel project in the live server.
I searched for this and found many solutions.
There are many processes to deploy laravel projects in a live server.
Someone suggesting to remove all files and folder from public folder
someone saying to change .htaccess etc.
What is the perfect way to deploy laravel projects in the live server?
If, I have to remove public folder then, why laravel included it?
If I have to copy .htaccess to root directory and need to change it.
Then why it is not used laravel as default. Would someone explain it to me, please?
I've been successful in deploying Laravel 4 applications on shared hosts by simply editing the paths here at /bootstrap/paths.php.
However, Laravel 5 does not have that file. How does Laravel 5 manage paths? I have access to the root directory with public_html. I can upload all the files to root and public directories, but confused where to look for the paths to be maintained?
Laravel 5 is smart enough to detect all it's path. I was missing some of the files during upload. :)
What I did was upload all the files as it is structured and the content of public folder was uploaded into the www directory, that's it!
You can play with creating new Application() in bootstrap/app.php. Its constructor takes argument which tells where is rest of the application related to public/index.php
Currently app.php has
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
Change the /../ to something else if rest of the application folders for example in ../laravel/ compared to index.html
If you have cPanel in your shared hosting you can try these easier methods before trying to move the Laravel's public folder:
Often you also have an SSH access when you have cPanel on shared hostings, so you can replace the www folder (i.e. the website document root) with a symbolic link to [app]/public, then deploy your Laravel app inside the [app] folder.
If you are deploying on a subdomain, e.g. [app].example.com, usually with cPanel you can choose the document root, then you can simply set it to [app]/public.
I think the two methods above are both easier and safer than moving the public folder. I would keep this as the last option.
Take a look here for some more info: http://blog.netgloo.com/2016/01/29/deploy-laravel-application-on-shared-hosting/
I currently have a basic cpanel hosting account. It has the setup:
/home/mysite/ --> my home directory
/home/mysite/www --> symlink to the next folder
/home/mysite/public_html --> where all my files live
Problem is, with the latest laravel installation I did, I have a website with structure:
/app/ --> appy stuff
/public/ ---> what needs to be exposed
My problem is, I dont want to chuck everything into /home/mysite as there are other folders in there too. Is there a way that I can make the html directory something like:
/home/mysite/public_html/public
This way if people open www.mysite.com, it hits the /public folder. And not the /public_html folder. Is there a way to do this on a basic cpanel hosting solution?
I know this isnt the exact answer you want - but this is how I do it.
You rename public to public_html and there is no need to change any server settings.
Then in your bootstrap/paths.php file change
'public' => __DIR__.'/../public',
to
'public' => __DIR__.'/../public_html',
Then just put the other folders where they need to be. Trying to muck around with cPanel settings, and leaving your Laravel app inside the public_html folder might lead to an issue down the track.