How to make higher than "public_html" folder work for cpanel installation? - laravel

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.

Related

Laravel "public" folder on a cloud server: is it safe to leave it in public_html?

we recently contracted a cloud server (NOT shared hosting). We are going to proceed to install Laravel in it. I would like to know if it is safe to leave the content of the "public" folder inside "public_html" and move the rest of the app one level up or if it is necessary to also move the public folder outside of public_html (this last option is complicated to set due to restrictions of the server). Thanks in advance!
It is completly fine to upload a Laravel project like that, in my experience the folder structure i used was...
| public_html
| index.php
| ... etc
| laravel-app
| app
| migrations
| ... etc
While my public_html/index.php file had this config.
require __DIR__ . '/../../laravel-app/vendor/autoload.php';
$app = require_once __DIR__ . '/../laravel-app/bootstrap/app.php';
With this structure your are not compromising user information by not setting any info in the public folder.
What is more, by doing this you take away from git structure all the files in public folder, so any hand made change made to the files won't affect your git repo.
Of course, when you modify any of the files (js, css, index, etc) you need to manually move them.
I made a video not so long ago (it is in spanish) but the goal is to load a Laravel project to cPanel, the point is that i made a script that moved the /public files to /public_html with every git push to master, maybe you can do something similar.
Video: https://www.youtube.com/watch?v=a5cyTpQMqi0
if in the files in the public folder are not stored confidential info such as passwords and usernames related to any component of your website it can be fine

Laravel, Using a cPanel shared hosting if possible?

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.

Hosting Laravel 5.7 project in Godaddy server

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.

transferring joomla from subdomain to main domain

i have my my website like abc.com/dev now i want to transfer it to abc.com,
what minimal changes should i do to make it work .
My website is in joomla is there way that i just move folder to main folder and add db setting.
Please guide i am new to joomla
Just Drag and drop your folders from your subdomain folder to root folder through FTP.
Then only changes you need to do is in your 'configuration.php' file located at the root folder. If your DB is not changed then do not change any of its setting. Just change the path of 'LOGS and TMP' folders in config file to the root path that are :
$log_path, $tmp_path
And I hope your site will work perfectly as it was working before.

How to Deploy Laravel 5 on shared cPanel hosting

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/

Resources