DEV Community

Ndifreke Friday
Ndifreke Friday

Posted on • Edited on • Originally published at voidnerd.com

Deploying Laravel on shared Hosting

If you are here, you are probably exploring how laravel works on shared hosting, on some low-budget project or just have reasons you prefer shared hosting. Alright, let's get down to business.

Here are the steps to get laravel up and running on shared hosting:

(1) Run php artisan config:clear; this clears the cache config. Since you are going to be editing .env online; you don't need your local configurations cached.

(2) Export Your migrated Database to a file (db.sql) without the create database statement, like so:

DROP TABLE IF EXISTS `users`;

CREATE TABLE `users` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `title` varchar(255) DEFAULT NULL,
 `name` varchar(255) NOT NULL,
 `facebook_id` varchar(255) DEFAULT NULL,
 `google_id` varchar(255) DEFAULT NULL,
 `linkedin_id` varchar(255) DEFAULT NULL,
 `tagline` varchar(255) DEFAULT NULL,
 `email` varchar(255) DEFAULT NULL,
 `username` varchar(255) DEFAULT NULL,
 `email_verification_code` varchar(255) DEFAULT NULL,
 `email_verified_at` timestamp NULL DEFAULT NULL,

 `password` varchar(255) DEFAULT NULL,
 `remember_token` varchar(100) DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT NULL,
 `updated_at` timestamp NULL DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB;

DROP TABLE IF EXISTS `password_resets`;

CREATE TABLE `password_resets` (
 `email` varchar(254) NOT NULL,
 `token` varchar(254) NOT NULL,
 `created_at` timestamp NULL DEFAULT NULL,
 KEY `password_resets_email_index` (`email`)
) ENGINE=InnoDB;
Enter fullscreen mode Exit fullscreen mode

(3) go to MultiPHP Manager on c-panel and confirm you have php 7.1 or higher.

(4) Zip the finished project (we will call this myproject from now on) and upload to root directory of hosting storage through File Manager (c-panel) or FileZilla; it should be something like /home/domain-name.

(5) Extract myproject in root directory(/home/domain-name) of hosting storage.

(6) Enable "Show Hidden Files". This is so you could see files like .htaccess, .env, etc.

(7) In myproject/public, move all it's contents to /public_html.

(8) Now edit /public_html/index.php to point to your laravel project, like so:

//previous state
require __DIR__.'/../vendor/autoload.php';

// changed to
require __DIR__.'/../myproject/vendor/autoload.php';

//previous state
$app = require_once __DIR__.'/../bootstrap/app.php';

//changed to
$app = require_once __DIR__.'/../myproject/bootstrap/app.php';

Enter fullscreen mode Exit fullscreen mode

(9) Edit .env in /myproject with your config keys

(10) Import and run the db.sql script you exported earlier on your created database through phpmyadmin on c-panel.

The end!

Top comments (19)

Collapse
 
glennmen profile image
Glenn Carremans

Thanks for your blog post, I have a couple of questions though 😉

How about the symbolic link to the storage directory? Most shared hosting providers don't allow the creation of symbolic links.
laravel.com/docs/5.8/structure#the...

And this seems to work perfectly for new installs, what would you suggest the flow would be for updates that require DB migration?

Collapse
 
ndiecodes profile image
Ndifreke Friday • Edited

You are right, not all shared hosting providers allow creation of symbolic links so I have mostly just uploaded my public files to public_html by changing root path in filesystem config.

For update on db migrations... You will probably need a sql script to alter your tables or alter it manually using phpmyadmin.

Collapse
 
ndiecodes profile image
Ndifreke Friday

A friend of mine recommended this package (github.com/kofoworola/route-commands); It let's you run artisan commands through web routes. Pretty neat 😇

Collapse
 
glennmen profile image
Glenn Carremans

Interesting! Thanks for sharing.

Collapse
 
msamgan profile image
Mohammed Samgan Khan

Nice article. This was one you. You can also do the following.

it's much easier and needs min. configurations.

Collapse
 
ndiecodes profile image
Ndifreke Friday

Added some knowledge, Thanks!

Collapse
 
_shahroznawaz profile image
Shahroz Nawaz

Hi, In my experience shared hosting is not recommended for Laravel. You can instead use cloud servers like Digitalocean, Vultr, Linode etc. Also if you are non-technical you can use managed solution like Cloudways.

cloudways.com/blog/install-laravel...

Collapse
 
ibtisam021 profile image
Ibtisam021

Simple and easy process, but at todays age most people do not prefer getting into technicalities and focusing more on the business side (talking about the start-ups). So would do you prefer to them deploying on a shared hosting, or take the road of managed hosting, where there are just a few clicks and you are ready to deploy your site. Also, your data can be at risk on a shared hosting site. What do you personally prefer and why?

Collapse
 
martin_52 profile image
Martingray

Shared hosting is a bad choice for laravel. Laravel is a framework , and like other framework such as wordpress, drupal etc, it require a powerful server. For example, it requires a good amount of RAM, disk space and a good processor speed. But shared hosting is bad in all the three.If you are not a technical person, you can also choose a managed service such as Devrims.

devrims.com/blog/why-laravel-share...

Collapse
 
akashdas profile image
Akash Das

Here is another resource full article about Laravel project deployment in Shared Hosting
nihardaily.com/21-deploy-guideline...

Collapse
 
kaperskyguru profile image
Solomon Eseme

Great article explaining this process.. Thanks for the great work.

Collapse
 
ndiecodes profile image
Ndifreke Friday

Thanks Solomon 👍

Collapse
 
ace113 profile image
ace113

Do i need to upload vendor and node_modules to the ftp server??

Collapse
 
ndiecodes profile image
Ndifreke Friday

Yes on vendor, not sure about node_modules - It depends I guess.

Collapse
 
junicodefire profile image
Okechukwu Obi

Kudos Boss

Collapse
 
ndiecodes profile image
Ndifreke Friday

Mr Juni 😎

Collapse
 
rennjay profile image
rennjay soterio

Great Content. Thank you.

Collapse
 
ndiecodes profile image
Ndifreke Friday

Thanks for reading up man 🙇‍♂️