@Qlic I followed your suggestions from another post in the forum but it doesn't work for me, can you please help me? Thanks
Laravel 5.4 deploy with Cpanel
Hi guys, I know this topic has been discussed many times but I still can't figure it out after I read all the posts in the forum and watched I don't know how many videos on youtube. I have a very bad hosting (that I can't change) with cpanel and no shell, in my domain folder I have these folders:
/backup
/data
/stat
/tmp
/www
I have to upload my laravel app into this hosting. I created a folder '/laravel' in the root with everything I have in local except the /laravel/public directory. I copied the content of the 'laravel/public' into the /www folder. I changed the two lines in the index.php in this way:
require __DIR__.'/../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
The scenario now is this:
/backup
/data
/stat
/tmp
/laravel
|_ /app
|_ /bootstrap
|_ /config
|_ ...
/www
|_ .htaccess
|_ index.php
|_ ...
I also changed the permission of the storage folder, I changed the .env file with the smtp and db credentials given by the hosting and set the environment from local to production. However I still have a 500 internal server error. What am I doing wrong? Please help me out about this. Thanks in advance
You have to play with the dot dots, to resolve correct path. Just experiment til it works.
require __DIR__.'/../ // play with this til working
@jlrdw if I remove the htaccess file I don't have the 500 error but this one:
Fatal error: Cannot declare class ComposerAutoloaderInitab8252897bf023b8ecb3f4c9bce51624, because the name is already in use in /web/htdocs3/mydomain/home/laravel/config/vendor/composer/autoload_real.php on line 5
any idea?
The problem with this structure is that Laravel expects the public directory to be $base_path/public. The base path is set in boostrap/app.php and in your example would set it to the laravel folder. The public path would then be set in the Application class. In your case this would be /laravel/public.
https://github.com/laravel/framework/blob/5.4/src/Illuminate/Foundation/Application.php#L379
You want this to instead resolve to /www.
Because this path is hard-coded in the Application class if you want to change it we will have to extend it overwrite the method to return your public folder.
Create a class that extends Illuminate\Foundation\Application (making sure composer knows how to autoload it) and add the following method to it.
/**
* Get the path to the public / web directory.
*
* @return string
*/
public function publicPath()
{
return dirname($this->basePath).DIRECTORY_SEPARATOR.'www';
}
Now edit bootstrap/app.php and replace the Illuminate\Foundation\Application on the first line with your class.
Other things to be aware of.
If you are using public file storage you will have to make sure to set your symlink to point at your www directory rather than the default public directory.
If you use laravel mix to compile your front end assets you will also have to modify it so that it knows where your files are located.
Follow this, in fact for a trial run, use same folder names here http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/
Follow that exactly. Nothing else
NO
/www
|_ .htaccess
|_ index.php
|_ ...
YES
/www
|_ my_public_folder_named_whatever
|_ .htaccess
|_ index.php
|_ ...
@jlrdw I create inside /www a /public folder. In my index.php
require __DIR__.'/../../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
In my /laravel/server.php
require_once __DIR__.'/../www/public/index.php';
Assuming now I have this structure:
/backup
/data
/stat
/tmp
/laravel
|_ /app
|_ /bootstrap
|_ /config
|_ ...
/www
|_/public
|_ .htaccess
|_ index.php
|_ ...
But I still have this error:
Fatal error: Cannot declare class ComposerAutoloaderInitab8252897bf023b8ecb3f4c9bce51624, because the name is already in use in /web/htdocs3/mydomain/home/laravel/config/vendor/composer/autoload_real.php on line 5
Where is htdocs3 coming from? You may have to do some cleanup.
@jlrdw actually I see starting from /laravel/config what is above it's not accessible by cpanel, I see the structure I wrote before. Anyway that's the error I see if I try to access to www.mysite.com/public/index.php If I try to type simply www.mysite.com/ I have a 403 error: You don't have permission to access the requested directory. There is either no index document or the directory is read-protected. I really don't get it.
I don't know about your host, but the guide I posted works 100% on godaddy hosting. What is your host?
@jlrdw www.forpsi.com
Are you sure it meets laravel requirements?
@jlrdw these are the server information:
SERVER
- Linux CentOS
- Apache 2.2
- Server Side Includes - SSI
PHP
- PHP 5.6 / 5.5 / 5.4 / 5.3 (FastCGI)
- execution_time: 90 sec
- memory_limit: 128MB
- upload_limit: 32MB
- ini_set
- safe_mode OFF
- register_globals OFF
- extensions: gd2, ImageMagick, Zip
FTP
- SSL Support
- Country access limit
- WebFTP access
- Passive mode support
is it ok?
Make sure all required extensions on on. But yes looks good.
@jlrdw do you mean I have to put ON safe_mode and register_globals? What do you exactly mean with extensions?
Read the laravel requirements.
@vinschi DirectAdmin and cPanel should both support Larvel as long as you have FTP access to the actual domain root, and not just the public directory.
Like you already did, all you have to do is place the Laravel folder in the root, place the public folder contents in the public_html folder (or in your case the www folder), and add the ../ to your index files includes.
Do note that the server is to run at least PHP 5.6.4 and that the public_html folder (www in your case) should be chmodded to 644 or incase that doesn't work 755.
There really isn't anything else you should have to do, however if that still doesn't fix it it's not a problem with Laravel but with your host having some server settings which prevent it from working. Contact them and find out what's wrong.
Good luck!
@Qlic you mean the require should be in this way, am I right?
require __DIR__.'/../laravel/bootstrap/autoload.php';
If yes, I still have the error 500 when I hit www.mysite.com
small update: now if I hit www.mysite.com I see the whoops page but not the routes I set up, any ideas?
Turn error reporting to true temporarily so you can read the stack Trace.
@Qlic @jlrdw I have this in my .env in the hosting
APP_NAME=Laravel APP_ENV=production APP_KEY=base64:2qXAv2nFdUCrIdu5c8U6HXmlQJuXXbW4d0l/hsI/eAo= APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://mysite.com
but I can't see the stack Trace. How can I do it? Thanks
In config/app you have
return [
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => env('APP_DEBUG', true),
Make it true, This example is laravel 5.1, 5.4 should be same.
@jlrdw it worked, I fixed a couple of errors and now the homepage works. However looks like it doesn't load the routes from web.php
I tried to modify the /config/app/php in this way:
'url' => env('APP_URL', 'http://www.mysite.com/')
but still I can't access to http://www.mysite.com/login and all the other routes. Any idea? Thanks in advance
In your htaccess file
RewriteEngine On
RewriteBase /yoursite.com/
or say your site is /yoursite.com/mylaravel
then try
RewriteEngine On
RewriteBase /mylaravel/
Have to play with this stuff sometimes to get right.
@jlrdw the problem is that as soon as I copy the .htaccess inside the www folder (my public) I have a 500 error and I don't get why
A 500 error:
Internal Error 500
The server encountered an unexpected condition which prevented it from fulfilling the request.
Are you able to see the laravel welcome screen? Have you double checked all your configs? Have you cleared all cache?
If you see the laravel welcome screen, laravel is working. Check any and all settings.
If you developed under windows, remember linux is case sensitive, windows is not. Check all these little things. Did you put the htaccess file in the correct place?
I'm changing htaccess files (on root folder and on public folder)
on < root project > folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
on < root project >/public
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
Note: I only do this on cpanel, for development state, the .htaccess remain the same
Please or to participate in this conversation.