Deploy Laravel 5.1 on a cloud hosting

2019-02-28 23:27发布

问题:

I developed my laravel application on wamp. I am finally done and rent a cloud hosting server with CPanel interface. I uploaded all my files on public html and tried going to the site. It's supposed to go to login page but not working.

I used to deploy classic html file, this is the first time I'm deploying a PHP laravel site. I've successfully imported my MySQL database so it's ready. I'm just clueless of the configuration etc.

回答1:

I'll walk you through the steps. Since you mentioned about public_html folder, I assume that this solution will work for you. Please follow the steps and change myapp to whatever your app name is.

  • Copy your project's public folder into public_html folder and rename it (Say myapp_public)
  • You will see a .htaccess file in public_html folder. Edit the contents of that file as follows: RewriteEngine On RewriteCond %{REQUEST_URI} !^myapp_public RewriteRule ^(.*)$ myapp_public/$1 [L]

  • Copy other folders in the root directory inside another directory say myapp

  • Now the final thing that you need to do is, to edit index.php file at the path public_html/myapp_public/index.php (if you followed the steps I wrote above). Change require statement as follows

Change require statement as follows:

require __DIR__.'/../../myapp/bootstrap/autoload.php';

Change $app variable as follows:

$app = require_once __DIR__.'/../../myapp/bootstrap/app.php';

And this should do it. Drawing out the simple directory structure for easiness.

~
|__ myapp
|     |____ .env
|     |____ app
|     |____ artisan
|     |____ .........so on
|
|__ public_html
          |_____ .htaccess (this is the file to edit)
          |_____ myapp_public
                     |________ .htaccess
                     |________ index.php (this is the file to edit)
                     |________ robots.txt ...... so on

I will explain in detail if you do not understand what is happening here.

EDIT

Make sure that you have installed composer via cURL as apt-get wont work on shared hosts. Once done, run composer install from your project's root directory i.e. myapp if you followed above steps.



回答2:

Finally I got it, Vishal's answer really helped, but I needed to change my PHP version setting to 5.5 or higher, after looking at the error log and googling the error. Thanks again Vishal. I still have problems with database connection but I think I can handle it from here.