I am trying to upload my Laravel project onto my web server, but my past two attempts have been unsuccessful. I believe I am not uploading the files to the right location.
This is my web server's structure ->
Am I correct to say that I need to upload ALL of my laravel files into public_html?
This is my Laravel project's directory :
EDIT : I have now added all the files onto the root folder, and public into public_html, however none of my routes seem to work. (They work perfectly on localhost). Everything throws a 404
No, but you have a couple of options:
The easiest is to upload all the files you have into that directory you're in (i.e. the cPanel user home directory), and put the contents of public into public_html. That way your directory structure will be something like this (slightly messy but it works):
/
.composer/
.cpanel/
...
app/ <- your laravel app directory
etc/
bootstrap/ <- your laravel bootstrap directory
mail/
public_html/ <- your laravel public directory
vendor/
artisan <- your project's root files
You may also need to edit bootstrap/paths.php to point at the correct public directory.
The other solution, if you don't like having all these files in that 'root' directory would be to put them in their own directory (maybe 'laravel') that's still in the root directory and then edit the paths to work correctly. You'll still need to put the contents of public in public_html, though, and this time edit your public_html/index.php to correctly bootstrap the application. Your folder structure will be a lot tidier this way (though there could be some headaches with paths due to messing with the framework's designed structure more):
/
.composer/
.cpanel/
...
etc/
laravel/ <- a directory containing all your project files except public
app/
bootstrap/
vendor/
artisan
mail/
public_html/ <- your laravel public directory
I believe - your Laravel files/folders should not be placed in root directory.
e.g. If your domain is pointed to public_html directory then all content should placed in that directory. How ? let me tell you
Copy all files and folders ( including public folder ) in public_html
Copy all content of public folder and paste it in document root ( i.e. public_html )
Remove the public folder
Open your bootstrap/paths.php and then changed 'public' => __DIR__.'/../public', into 'public' => __DIR__.'/..',
and finally in index.php,
Change
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
into
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
Your Laravel application should work now.
If you are trying to host your Laravel app on a shared hosting, this may help you.
Hosting Laravel on shared hosting #1
Hosting Laravel on shared hosting #2
If you want PHP 5.4 add this line to your .htaccess file or call your hosting provider.
AddType application/x-httpd-php54 .php
In Laravel 5.x there is no paths.php
so you should edit public/index.php and change this lines in order to to pint to your bootstrap directory:
require __DIR__.’/../bootstrap/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/app.php’;
for more information you can read this article.
Had this problem too and found out that the easiest way is to point your domain to the public folder and leave everything else the way they are.
PLEASE ENSURE TO USE THE RIGHT VERSION OF PHP. Save yourself some stress :)
All of your Laravel files should be in one location.
Laravel is exposing its public folder to server. That folder represents some kind of front-controller to whole application. Depending on you server configuration, you have to point your server path to that folder. As I can see there is www site on your picture. www is default root directory on Unix/Linux machines.
It is best to take a look inside you server configuration and search for root directory location. As you can see, Laravel has already file called .htaccess, with some ready Apache configuration.
Related
Had this working but just updated my website on the server and it seems to have made all my uploaded files head to my public folder in my project rather than the public_html. Any idea on which file i must have uploaded and the fix?
You said you had it working before.
Was that on the same server...live?
If so, then could that be a server issue and not necessarily laravel issue?
Maybe you should ask your host for help and clarifications about what changed?
If you are convinced it was about what you changed...then care to show us?
Ideally if the server is cpanel, you will want to upload all your laravel files into your home's directly...then all your /public folder content into public_html
It will look like this:
.cpanel/
app/
etc/
bootstrap/
mail/
public_html/
content from your laravel /public directory
vendor/
...etc
You also need to go into your /public_html and edit the index.php content:
require __DIR__.’/../vendor/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/app.php’;
And make sure it points to the correct location of your bootstrap folder..if you follow the structure above, then its ok.
Lastly, confirm that your PHP is indeed >= PHP7.0
With help from this answer: https://stackoverflow.com/a/50261573/3475551
I managed to get laravel to save uploaded files to my servers public directory instead of app/public.
Edit app/Providers/AppServiceProvider.php like this:
public function register()
{
$this->app->bind('path.public', function() {
return realpath(base_path().'/../../public_html');
});
}
Hope this helps.
I have two modules one is a Laravel Extension and Second one is custom module(just some html,css,js file).
I have created Two folders as its project requirement.
Let say Folder1(basic bootstrap home page) and Folder2(complete laravel Application).
Website Root
Folder1
--index.html
--css
--js
Folder2
--app
--config
--database
--other laravel foldes
How can configure routes so that from index.php I can call some
controller of laravel with is in Folder2.
And From some view of laravel redirect to index.php in Folder1
I know its not perfect way to do that but its requiremnt of client and we cann't change that.
Thanks in Advance.
You can try to use Puli and add your module Folder1 as a resource.
They have a twig extension too so using it in a Laravel should be pretty seamless
Do following steps make sure you have backup.
1.Put all content folder public folde to root folder so that laravel can understand this is your root.
2.Edit index.php and provide file path to them
require __DIR__.'folder2/bootstrap/autoload.php';
$app = require_once __DIR__.'folder2/bootstrap/app.php';
3.Now laravel routing is working here. so all your laravel routs are now filne.
4.Now for all html files in folder1 you can make a .htaccess rules or make a general rule in root folder.
Redirect 301 /home /folder1/home.html.
5.Now when you access site.com/home it will redirected to folder1 and when you access site.com/laravelHome it will go to folder2.
Hope this will help you.
I'm having trouble installing/moving laravel to web server, i downloaded and set laravel on my local linux server but when i moved it to web server ,it shows a blank page.
I uploaded the public folder contents to public_html and other contents outside the public, also i changed the public DIR from paths.php on bootstrap folder as follow: 'public' => __DIR__.'/../public_html/' so what is the exact problem? Please help me with this issue. Is composer a problem? or what?
1) Create a new directory called ‘laravel4′ adjacent to ‘public_html’ so that your remote file structure now looks like this:
[.htpasswds]
[etc]
[laravel4]
[mail]
[public_ftp]
[public_html] etc etc varies depending on server
2) Upload the contents of your local ‘public’ directory to the remote directory ‘public_html’. Note: Be sure not to copy the whole ‘public’ directory, JUST it’s contents.
3) Upload everything else within your local Laravel project to the new remote ‘laravel4′ directory. Check: Now when you view the ‘laravel4′ folder over FTP/SSH/Whatever, you should see all your ‘app’ & ‘bootstrap’ directories along with all the other files and directories, but NOT ‘public’.
4) Edit the remote file ‘public_html/index.php’ and make the following change:
//from:
require __DIR__.'/../bootstrap/autoload.php';
//and
$app = require_once __DIR__.'/../bootstrap/start.php';
//to:
require __DIR__.'/../laravel4/bootstrap/autoload.php';
//and
$app = require_once __DIR__.'/../laravel4/bootstrap/start.php';
5) Edit the remote file ‘laravel4/bootstrap/paths.php’ and make the following change:
//from:
'public' => __DIR__.'/../public',
//to:
'public' => __DIR__.'/../../public_html',
6) That should be it. In my case, that was enough to restructure everything. Routes are working with the default .htaccess file. If you have problems, let me know, or ask on the ever-helpful
Reference: http://myquickfix.co.uk/2013/08/hosting-laravel-4-on-cpanel-type-hosting-public_html/
I'm about to deploy laravel 4 on a shared web host into a subdomain and I'm a bit confused about what to do. I got it working on a hostpapa account but wasnt happy with the configuration and switched providers for the testing environment.
I've created the following folders:
domain/private/myApps/golfmanager
I've placed in here all the files and folders except the public folder
I've then placed the contents of the public folder into this folder:
domain/subdomains/golfmanager/httpddocs
I'm not sure what to do now! I understand I need to change the paths in bootstrap/path.php
Can someone provide some pointers of what needs to be changed for this folder set up. Don't want to break it!!
Thanks
This is super easy on shared hosting.
Step 1: Understanding your folder structure. The layout of your shared hosting should generally look something like this:
/
username
home
public_html
subdomain-name
laravel-files (optional)
...other folders etc
As you hopefully know, all your public files for your site will be in your public_html folder.
Note: sometimes a subdomain will be inside the public_html folder. That is okay but I recommend creating your subdomain folder above the root for a little bit of extra security. You can do that easily in cPanel but changing the path to the subdomain when you are creating it.
Step 2: Upload your Laravel files above the root (above public_html) or in a subfolder if you want it to be cleaner.
For a small project I generally upload the files into the "home" folder above. But for cleaner structure you may want to create a folder inside that "home" folder called "laravel-files".
What follows is how to do it in an "laravel-files" folder. If you upload them to "home" instead then all you need to do is get rid of all references to "/laravel-files" below.
Step 3: edit your public/index.php and your bootstrap/paths.php files:
In paths.php
change
'app' => __DIR__.'/../app',
to:
'app' => __DIR__.'/../laravel-files/app',
change:
'public' => __DIR__.'/../public',
to:
'public' => __DIR__,
change:
'base' => __DIR__.'/..',
to:
'base' => __DIR__.'/../laravel-files',
change:
'storage' => __DIR__.'/../app/storage',
to:
'storage' => __DIR__.'/../laravel-files/app/storage',
In index.php
change:
require __DIR__.'/../bootstrap/autoload.php';
to:
require __DIR__.'/../laravel-files/bootstrap/autoload.php';
change:
$app = require_once __DIR__.'/../bootstrap/start.php';
to:
$app = require_once __DIR__.'/../laravel-files/bootstrap/start.php';
Now what you'll need to do is, as I said upload your laravel project to your "laravel files" folder.
The only thing you wont upload there is the contents of your laravel "public" folder, which should instead be uploaded to your "subdomain-name" folder (this includes your index.php and all your css js files etc).
Hope this helps!
Please note my answer is based on this question: How to install Laravel 4 to a web host subfolder without publicly exposing /app/ folder? but tailored for your situation.
I'm not sure this is the way to go, because, since your folders are completely different, it's doable but you probably will need to create symlinks for this to work this way.
Laravel is supposed to have the folder hiearchy you see in your application and you should have
domain/subdomains/golfmanager/httpddocs/app
domain/subdomains/golfmanager/httpddocs/bootstrap
domain/subdomains/golfmanager/httpddocs/public
domain/subdomains/golfmanager/httpddocs/vendor
So, what I think you can do it to put everything on
domain/subdomains/golfmanager/httpddocs
And ask your domain administrator to set the document root of your application to
domain/subdomains/golfmanager/httpddocs/public
This way, when you point your browser to
http://golfmanager.yourdomain.com
It will access this index file:
domain/subdomains/golfmanager/httpddocs/public/index.php
This is how Laravel is supposed to work.
Josh answer was very helpful, but it did not work or did not matched my case.
I will tailor my solution like his one, so everyone could follow easily:
Step 1: My chosen folder structure:
/
home
username
public_html
subdomain-name
laravel-files
...other folders etc
Note: my subdomain is inside the public_html folder.
Step 2: Uploaded my Laravel files above the root (above/out of public_html) in a subfolder: laravel-files (//home/username/laravel-files)
Step 3: edit your public/index.php and your bootstrap/paths.php files:
In paths.php
Don't change:
'app' => __DIR__.'/../app',
to:
'app' => __DIR__.'/../../laravel-files/app',
because it's useless - it will evaluate to the following path:
"/home/username/laravel-files/bootstrap/../../laravel-files/app"
so the default is enough to just get out of bootstrap and enter app.
Instead, change:
'public' => __DIR__.'/../public',
to:
'public' => __DIR__.'/../../public_html/subdomain-name',
Also, don't change:
'base' => DIR.'/..',
'storage' => DIR.'/../app/storage',
In index.php
change:
require __DIR__.'/../bootstrap/autoload.php';
to:
require __DIR__.'/../../laravel-files/bootstrap/autoload.php';
and change:
$app = require_once __DIR__.'/../bootstrap/start.php';
to:
$app = require_once __DIR__.'/../../laravel-files/bootstrap/start.php';
Upload your laravel project to the "laravel-files" folder, except the public folder.
Content of "public" folder, should instead be uploaded to the "subdomain-name" folder.
I'm trying to install an application made with codeIgniter in a subfolder, so that I can access it using : http://www.domain.com/my_subfolder/
At the root, there's a Wordpress application.
I edited the .htaccess of the Wordpress install to let the request go to the folder /my_subfolder/
It's working fine, the only problem I get is that CodeIgniter is unable to dynamically load the classes in the "libraries" directory. So everything in the CI application works fine until it tries to use an object declared in the "libraries" subfolder, then I get a : Unable to load the requested class: my_class
It doesn't seems that there's a parameter in the "config" folder to change that... any idea?
What you need is to edit your CodeIgniter config.php in System > application > config.
and then edit config.php and set the property:
$config['base_url'] = "http://www.domain.com/my_subfolder/"
Well it seems that the config param base_url should be updated. Also, I used a library with the "MY_" prefix, and I should'nt since I was'nt extending any CI class.
This is 2021. In case anyone is having this same issue with CodeIgniter 4, this is how I solved it when I came across this issue.
Problem
I installed CI in a subfolder in my public_html folder i.e example.com/api. When I visited www.example.com/api, I saw a 403 forbidden error.
Solution
Download and unzip CI on your local machine or use composer.
Rename public folder to the name of your subfolder. In my case, I named it api.
Create another folder and give it any name of choice, for example, let's use mango (yes, I love mangoes). Copy all the remaining files and folders (app, system, writables, env, LICENSE, README, composer, phpunit, spark) into the mango folder. After doing this, we should have 2 folders: api and mango
Copy both folders to your live server cpanel root (Do not copy into public_html or www). Let them be on the same level as public_html
Open api/index.php and change $pathsConfig = FCPATH . '../app/Config/Paths.php'; to $pathsConfig = FCPATH . '../mango/app/Config/Paths.php';
Create a subdomain and point it to /api
Go to the api folder, duplicate the env file and rename it to .env
Open .env and look for app.baseURL=''. Remove the '#' to uncomment that line and the change it to app.baseUrl='http://subdomain' where subdomain is the subdomain you created above e.g http://api.example.com
Open mango/app/config/App.php and look for public $baseUrl and set it to subdomain e.g $baseUrl = 'http://api.example.com'
Your CI project is now well configured. Visit http://api.example.com. and you should see the CodeIgniter welcome page.