I added this article to Stackoverflow Laravel Documentation, i thought it would be great if it is in my blog too. Deploying Laravel Project to Shared Hosting is easy.
image-is-100-percent-not-related-to-the-topic |
Requirements:
- PHP >= 5.5.9
- OpenSSL PHP Extension
- PDO PHP Extension
- Mbstring PHP Extension
- Tokenizer PHP Extension
- First of all archive/zip/compress your project file
- Now Let say you have shared hosting server and you want to deploy your laravel project / app there. In your Hosting cPanel click on Filemanager it will lead you to another page where you can find the directory/folder called
public_html
. - Upload the compressed project file to
public_html
directory and extract it - Now you can move all your project files to public_html ( just select all project files and click on move, it will pops up a box enter public_html there )
- Now in cPanel you can find MySQL Databases, Create Database, database user and password plus assign user to your created database in there.
- After creating database, in cPanel Click on
PhpMyAdmin
and Select the database you have created. Import the .sql file from your localPhpMyAdmin
. - Once importing is done, Visit
public_html
directory and edit.env
file - In .env change the following lines accordingly
DB_DATABASE=yourdatabaseNameDB_USERNAME=databaseUsernameDB_PASSWORD=databasePassword
Save the
.env
file and now visit yourwebsite.com/public and your project will dance there.
BUT what if i want don't want
/public
in my website, i.e i want to run my application on my website root (website.com) for that do the following steps.
Copy all the /public directory files to root directory, and edit
index.php
.
Change
require __DIR__.'/../bootstrap/autoload.php';
And for LARAVEL 5.5+ Users Change the below
require __DIR__.'/../vendor/autoload.php'; TO the below
require __DIR__.'/vendor/autoload.php';
To
require __DIR__.'/bootstrap/autoload.php';
And
$app = require_once __DIR__.'/../bootstrap/app.php';
To
$app = require_once __DIR__.'/bootstrap/app.php';
Once that is done, in server.php change
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
To
if ($uri !== '/' && file_exists(__DIR__.'/'.$uri)) {
return false;
}
And
require_once __DIR__.'/public/index.php';
To
require_once __DIR__.'/index.php';
1 comments: