Setup a Laravel CMS with a digital ocean server and free SSL

I am not a fan of server configurations. Its the most boring part of every project. I hate it! Luckily, there are shortcuts. In this post i will let you know how to:

Setup your server quickly to run PyroCMS
Install PyroCMS
Install a free SSL certificate using Let's Encrypt
Schedule daily backups / snapshots

Let's get started!

Getting a server

There are a number of different options. I normally go with Vultr or Digital Ocean. For this article, lets setup a server with Digital Ocean.

Log in / sign up to Digital Ocean and click on create and select Ubuntu 16.04. Let's go with a 5 dollar server and select a server region close to you. I only use SSH when logging into servers.

Once you click create, your server will be created in a couple of seconds.

Configuring the server

Next, head to to Server Pilot and create an account. It's totally free, but if you follow the link above you will get 10 dollars to start with if you would like to upgrade to another plan in the future. But as i said, 100% free for what we are doing.

Create an App

An app, is your website or application. Create an app and enter:

  • The name (Example: test)
  • Domain (Example: test.com)
  • Choose PHP 7.1
  • Select your server

Your application directory will be located at : /srv/users/serverpilot/apps/test

Createanapp

Setting up PyroCMS

In this example, i specified a non-existing domain, test.com. Since we don't own that domain, we have to change our hosts file making sure we can still use the url. Edit your hosts file with your droplets ip address followed by test.com xxx.xxx.xx.xx test.com

It's time to setup PyroCMS. You got your server at digital ocean, you have it configured by Server Pilot, let's ssh into your server.

When logged in, run this command: cd /srv/users/serverpilot/apps/test to enter your application directory. Then delete the public folder by entering the following command : rm -rf public/.

If you need more information on how to set up PyroCMS other than what i will go through next - please see PyroCMS Documentation

Download PyroCMS using composer

There are different ways of setting up PyroCMS. I normally go with compose. Next command to run is : composer create-project pyrocms/pyrocms .

Create our database

While composer is doing its thing, let's create a database. Head back to ServerPilot and go to the tab: Databases. I choose to call name my database test and accept the generated username and password.

When our database is created, go ahead and continue installing PyroCMS.

Createdatabase

Installing PyroCMS

Again, we have a few options how to proceed. We could install everything using the GUI. But why do that when there is a much faster way!

Add a .env file

Create/Open up your .env file with this command: nano .env

If you have used Laravel, it should be easy to understand what we are doing next. Make sure you enter your own database name, username and password. But other than that you could paste this and save the file:

APP_ENV=local  
APP_KEY=zfesbnTkXvooWVcsULw2r4SmPVNGbFoS  
DB_CONNECTION=mysql  
DB_HOST=localhost  
DB_DATABASE=test  
DB_USERNAME=8957a7b86fb9  
DB_PASSWORD=9bbfd5a8074d59a6  
APPLICATION_NAME=Default   
APPLICATION_REFERENCE=default  
APPLICATION_DOMAIN=test.com  
ADMIN_EMAIL=test@test.com  
ADMIN_USERNAME=admin  
ADMIN_PASSWORD=password  
LOCALE=en  
TIMEZONE=UTC

After saving the file, run the following command : php artisan install --ready and then let's set some necessary permissions:

chmod -R 775 /srv/users/serverpilot/apps/test/public/app/  
chmod -R 775 /srv/users/serverpilot/apps/test/storage/  
chmod -R 775 chmod -R 775 /srv/users/serverpilot/apps/test/bootstrap/cache/  
sudo chown -R serverpilot:serverpilot /srv/users/serverpilot/apps

DONE! Go visit your site at http://test.com

Automatic and Schedules backups

Next , we need to have some backups configured. Unfortunately Digital Oceans backups suck because they are done only once a week. We would like daily backups, and thankfully we got backupSheep. So head on over there and create your account.

When you are done, navigate to Accounts and connect to Digital Ocean. Add your server under the Servers tab. When done, click on the last icon next to your server you just added.

Click on the plus sign next to Schedule and specify a name for your Schedule. Under Status, select active and enter the following data under the specific fields:

  • Minute : 00
  • Hour : 03
  • Day : *
  • Month : *
  • Day(week) : *

Select your timezone and tell BackupSheep how many backups you want to keep. Finally click save. Now BackupSheep will tell Digital Ocean to take a snapshot of your system every day at 3 am. Voila!

Addschedule

Add a free SSL Certificate

We will be using a bash script Written by Rudy Affandi. Since there is already a good tutorial written for this, i won't go into details. Just head over to the tutorial written by Sridhar.