You have made your first Laravel application. That is great, so now what to do next! I bet you would like to show it to your friends or colleagues. The best thing you could do is deploying the app to a cloud. Well, I am assuming that you know the basics of Laravel hosting and the term cloud.

Cloud hosting is one of the leading ways to host your apps or websites. There are a bunch of hosting providers available. However, it is making the task quite harder to choose the ideal one. I can still remember I was just frustrated and tired choosing the best one.

Luckily, after a few days, I have found Cloudways. The perfect destination to do Laravel hosting.

Cloudways – Laravel hosting

First of all, Cloudways is not a hosting provider. It is a managed cloud hosting platform.

They have tied up with many top-notch hosting providers like Google Cloud, AWS.

The best part is you can manage multiple different servers from within a single admin panel. So that makes Cloudways an amazing platform.

This platform is specially designed for PHP. You can host Laravel, WordPress, Magneto, Presta Shop and few more.

It provides a blazingly fast experience for WordPress. Sites load under 1.3s (Tested with GeneratePress). So definitely it is a gem for PHP developers.

Currently, you will find the servers of AWS, Digital Ocean, Google Cloud, Vultr, Linode. Digital Ocean is my favourite one among all these. As because of its impressive response time and availability of servers in India.

Here are the sample tests I have made on my testing app. I am attaching the results below.

The speed of the server is blazing fast.

Laravel cloudways DO gtmetrixSubscribe to this website and I will send you the Pingdom and gtMetrix results of Laravel as well as WordPress site test reposts.

However, all of these hosting providers are quite amazing so you can try anyone.

Now one thing will definitely arise in your mind, the cost. A platform that is providing such services may cost a lost right!. Well, the answer is no, not always.

Cloudways is providing all such great services starting only at 11$.

So hurry up and start your Laravel hosting today with it.

Oh, wait! you may not trust my opinions and would like to try before you buy.

Don’t worry even for that case I have something interesting for you. Just follow the link below and get your free 3 days trial.

Faster Laravel Hosting

Laravel deploy to Digital Ocean

laravel deploy to digital ocean** UI of Cloudways admin panel

I am assuming that you have already created your Cloudways account. So in this section, I will guide you to upload your first Laravel app.

First of all, you will see a launch button after your email verification. Click on that and you will find a page to deploy your app.

Now select the app Laravel and then name your server, project and app whatever you like.

Unfortunately, Cloudways supports currently up to Laravel 5.5 only. However, I will show you the way to deploy Laravel 5.7 with it.

Okay, so now choose the server. I am choosing Digital Ocean for this tutorial. After that choose the server location.

This part plays a vital role in your app success. So make sure you are choosing the server location carefully.

I suggest you choose the location which your app is targeting.

Once you set it, click on launch now. Cloudways will now start creating the server. It will take a while to set up the server. So until then let’s go to our Laravel app and add it to a git provider (GitHub, Bitbucket).

I am using Bitbucket.

Add existing Laravel project to Git

add existing laravel project to git

 

The first thing you will need to do is create a new repository. Once you create it go to your local project folder and open the terminal.

Now follow the steps mentioned below

git init

Initialize an empty git to the root project directory.

git add .

Add all the files inside the project for staging. Laravel by default comes with a .gitignore file so no need to create that.

git commit -m "Initial changes"

Commit the changes and finally its time to add the origin. Go to your repository and copy the git address.

git remote add origin [email protected]:username/repository_name.git

In this way, you can add the remote origin.

Now the final step to push it to git.

git push -u origin master

Hooray! your app is now added to Git.

Okay so now our app is added to git and our server is ready. So its time to move to the next step.

Cloudways Laravel deployment via git

cloudways laravel deployment via git

First of all, go back to the Cloudways and click on applications from the menu. You will be able to find your app name. Click on it and go inside.

At the left, you will find an option called Deployment via Git.

The first thing you will need to do is generate the SSH key. So click on it, generate the key.

Now view the SSH key and you will find a long string as below.

cloudways ssh keysClick on the keys to copy or download it.

Now go to your repository settings and find out the access keys option.

Once you find it go ahead and paste the SSH key as follows.

add ssh key to bitbucket

Now all set for our deployment. Go back to Cloudways and add your project git address.

Now go ahead and click Authenticate. Make sure you have added your project to this repository. An empty repository cannot be authenticated.

Once Cloudways successfully authenticates it you will be able to choose the branch and deployment path.

Now everything is set up for our Cloudways Laravel deployment via Git. So let’s move to the next part and do the required changes to make our app live.

Laravel 5.7 Cloudways setup

The very first thing you will find is the following array_keys() error when you visit your site.

array_keys error laravelI have already said that Cloudways is supporting up to Laravel 5.5. That is the reason behind this small error.

So the first thing you will need to do is go to app/Http/Middleware/TrustProxies.php file. Now change the headers from string to an array as follows.

protected $headers = [
        Request::HEADER_FORWARDED => 'FORWARDED',
        Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
        Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
        Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
        Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
    ];

Replace the headers with above value and save.

Now add the changes, commit and push to git.

Now Git is updated so go ahead and pull the latest commit from the deployment via git tab of Cloudways.

Go ahead and check your website. Here I am checking mine.

laravel cloudwaysThat’s great, it’s running successfully. Now the last and final step of our tutorial the database migration part.

Cloudways is providing a great 30% discount with this Black Friday.

Use the Code “BFCM18” to get flat 30% discount on your first 3 transactions.

cloudways black friday sale
Get the discount

Laravel Cloudways database migration

Cloudways comes with in-built MySQL support. So there is no need to buy add-ons or anything else. It comes absolutely free with every cloud hosting package.

So how do we connect to a database using Laravel!

There are two ways to specify the database credentials. The .env and the config/database.php file.

However by default .env file used for the local environment. So gitignore is used to ignore that file.

In this case of production environment always use the second option.

So first of all, go to the Cloudways Access Details section. You will find the MySQL access credentials there as below.

cloudways laravel database

Now take the values and update your database .php file.

Once its updated follow the steps you have already done – add, commit, push and finally pull it from Cloudways.

That’s it, now let’s go to the console and migrate it.

Migrate from the SSH terminal

Now its time to go to the servers page. So click the servers from the menu and you will find your server name.

Click on it go inside and you will find an option called Launch SSH terminal.

cloudways ssh terminalYou can access terminal in two ways either online browser-based terminal or you can use your own computer terminal.

I am using the online terminal for simplicity. However, you can use your own terminal by using SSH public keys.

So now launch the SSH terminal and provide the username and password. You can find the credentials location from the above image.

Once you log in, go inside the applications/username/public_html folder. Its the place where your app is residing.

Now as you are inside the project root directory. You can simply run the database migration as follows.

php artisan serve

but there is one issue we have not solved yet. The error, the specified key was too long.

In order to fix it just add the following code into your app/Providers/AppServiceProvider.php file as follows.

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

use the Schema facade and call the method to specify default string length.

It will set the default string length to 191. Now go ahead push and pull the changes.

Final migration

I am dividing the Laravel hosting migration part into 2 pieces for simplicity.

Until now you have seen the various steps to migration. Most of you are getting frustrated by how long it can be.

Well its the last and final section. It’s not going to be that much longer.

Ok so now you know we have used the config to add database credentials.

However, Cloudways include .env file to every Laravel project by default. So if you have not added the credentials there you can modify it from .env.

Use nano to edit the env file as follows.

nano .env

Now just go ahead and add your details. Once its done press ctrl+x then and finally enter. It will save the file and close the editor.

So that’s it you are all ready to run the database migration. Run the php artisan migrate and it will show the output as below.

cloudways online sshNow go to your site and reload.

You have successfully learnt Laravel hosting with Cloudways.

Whether you are a newbie or a professional in Laravel hosting. I would surely recommend you to use Cloudways. They are doing the awesome work by making cloud hosting really easy and affordable.


Subham Mitra

Subham Mitra is a full-stack developer as well as well as an aspiring entrepreneur who is pursuing MCA and providing brilliant stuff for a great range of people's through Coders Diaries.

https://codersdiaries.com


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

WhatsApp WhatsApp us