Skip to content

Deploying Craft CMS with Git

Posted by Ryan on

We’ve launched numerous web apps over the past 15+ years and not once have we’ve ever wanted to publish a blog article right after doing so. Typically, there’s always a bump or two in the road that you either have to figure out by reading hours of documentation or by spending half the day talking to support. Fortrabbit not only gave us a free trial to set up and test our app but their beautiful dashboard and easy to follow process made deploying our Craft CMS site a breeze using Git. Assuming you’re already have Craft installed and setup locally, here’s how we were able to migrate the craft code base over via Git.

# 1. Initialize Git (when not already done)
git init .

# 2. Add your App's Git remote to your local repo
git remote add fortrabbit c2e@deploy.us1.frbit.com:c2e.git

# 3. Download the fortrabbit Craft .gitignore file
curl -O https://raw.githubusercontent.com/fortrabbit/craft-starter/master/.gitignore

# 4. Add changes to Git
git add -A

# 5. Commit changes
git commit -m 'Initial commit'

# 6. Initial push and upstream
git push -u fortrabbit master

# 7. From there on only
git push

Now that your files are pushed up to the server, go ahead and login via SFTP (you’ll have to add your SSH Key) and upload your .env file. Once the file is uploaded, go ahead and change the credentials to match you new app setting that Fortrabbit has provided you with. It should look something like this.

# The environment Craft is currently running in ('dev', 'staging', 'production', etc.)
ENVIRONMENT="dev"

# The secure key Craft will use for hashing and encrypting data
SECURITY_KEY="PfAHJEUN348KFJD9378FJ-xkEvt"

# The database driver that will be used ('mysql' or 'pgsql')
DB_DRIVER="mysql"

# The database server name or IP address (usually this is 'localhost' or '127.0.0.1')
DB_SERVER="{{NAME OF YOUR APP}}.mysql.us1.frbit.com"

# The database username to connect with
DB_USER="{{NAME OF YOUR DB USER}}"

# The database password to connect with
DB_PASSWORD="{{MYSQL PASSWORD}}"

# The name of the database to select
DB_DATABASE="{{NAME OF YOUR DB}}"

# The database schema that will be used (PostgreSQL only)
DB_SCHEMA="public"

# The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database)
DB_TABLE_PREFIX=""

# The port to connect to the database with. Will default to 5432 for PostgreSQL and 3306 for MySQL.
DB_PORT="3306"

Like I said earlier, there’s typically at least one roadblock when deploying a site to a new hosting provider. Luckily, this one wasn’t too bad but hopefully by sharing it with you, it will make your life easier once you cross this bridge. In order to migrate the Database over we used Sequel Pro to do so. Instead of connecting with the standard details, you have to select SSH as the connection method like so:

Back over in the Fortrabbit dashboard, access the MySQL tab and there will be most of the info. Do notice the link in the bottom right corner (Show SSH tunnel infos) this will expand the SSH host and SSH user name that you need to securely login. You can leave that password blank since this is already using the SSH key that you set up. Simply connect and import your database and there you go! Using Git is essential for version control and it also makes deploying our Craft projects a walk in the park.

Oh ya, and don’t forget to point your assets to @web instead of your local directories.

craft cms santa cruz

Did you like this article?

Share it on these social networks!

Leave a Reply

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

So now what?

We’re ready! Let’s do this.

Milano Design: Branding, Web Design, Ecommerce, Graphic Design, Marketing, Santa Cruz, Monterey, Los Gatos, San Jose