paint-brush
Deploying CakePHP Project To The Cloudby@Alex Golub
1,169 reads
1,169 reads

Deploying CakePHP Project To The Cloud

by Alex@bunnyshellAugust 26th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Some cloud providers offer simple solutions, but others require more technical know-how. We show you how to deploy an app to Microsoft Azure as well as Amazon AWS (using Elastic Beanstalk) The easiest way you can deploy a CakePHP to any cloud is to use Bunnyshell. It’s faster, works better, and it saves you a lot of time and overhead. We also show you the easiest way to deploy a cakePHP application to any. cloud by using Bunnyhell. The easy way to do this is to set up any staging- or demo-server.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Deploying CakePHP Project To The Cloud
Alex@bunnyshell HackerNoon profile picture

Follow these steps to understand how to deploy a CakePHP application to the cloud. While some cloud providers offer simple solutions, you will notice that others require a bit more technical know-how for you to deploy an app.

Summary

In this article we’re going to show you how to deploy a CakePHP application to the cloud. We’ll take it step by step and show you how to deploy an app to Microsoft Azure as well as Amazon AWS (using Elastic Beanstalk).

For those who are not tech-savvy, coding can be a little frightening. That’s why we’re also going to show you the easiest way you can deploy a CakePHP to any cloud by using Bunnyshell. It’s faster, works better, and it saves you a lot of time and overhead. 

Let’s start with the basics: 

What is CakePHP and why you should use it

CakePHP is an open-source framework that makes it easier for you to develop and manage any PHP application. For those who don’t want to spend a lot of time coding, and instead focus on app development and design, CakePHP is a great framework. Less coding, more action!

Using a framework instead of pure code is better, especially if you are new to coding. Frameworks like CakePHP come with systems that already contain best practices in “how” your application should be structured and how development needs to be done.

CakePHP itself is a great framework and comes with: 

  • Robust Performance
  • CRUD Scaffolding (Create, Read, Update and Delete)
  • Testing Methods
  • User-friendly experience

CakePHP application deployment to the cloud

Even before you’ve finished working on your application, you’ll still need to deploy it. You don’t want to risk losing the updates, right? 

Before you do, there are a few steps you need to go through: 

1. Start by Moving files: 

You need to create a git commit and pull or clone that commit or repository on your server and run composer install. 

Be aware that when deploying via FTP you will at least have to fix the file and folder permissions.

You can also use this deployment technique to set up any staging- or demo-server and keep it in sync with your dev box.

2. Afterwards, make sure to Adjust config/app.php

Turning debug = false  disables a number of development features that should never be exposed to the Internet at large.

This will help you avoid deploying any application with debug true and also save yourself from having to change the debug level every time before deploying to a production environment.

3. Don’t forget to Check your security

You’ll want to have your  webroot directory publicly visible. Make sure that your secrets (such as your app salt, and all security keys) are private and unique. Do not forget to check if your models have the correct validation rules enabled.

4. Next, you will want to Set document root

CakePHP applications need to have the document root set to the application’s webroot. This makes the apps and configuration files inaccessible through a URL. 

 5. Finally, once your CakePHP app is deployed, improve your application’s performance

To do so, you will need to run this command in your production server:

php composer.phar dump-autoload -o

Now that you know the basic steps to deploying a CakePHP application to the cloud, let’s take a look at how you can do it on two of the most important cloud providers: Microsoft Azure and AWS.

How to deploy a CakePHP application to Azure

The needs: 

To deploy a CakePHP application to Azure you will need: 

  • An account on Microsoft Azure
  • A Git repository
  • CakePHP installed
  • Your CakePHP application 

Some cloud providers make it easier for their users to deploy an app, while others go the old fashion way. 

Microsoft Azure seems to be a bit more complicated when it comes to deployments, but it’s actually easier than it seems. Here’s what you need to do before deployment:

1. Create an empty Azure Web Apps and enable Composer extension. If you want, you can enable Visual Studio Online for easy script modifications and command running.

2. Create a file named web.config in the root directory of your application. 

3. Add the inlt extension in PHP runtime on Azure. Next, add a folder with the name ext in your root directory and create a file ext.ini in the folder you just created with the content:

extension=php_intl.dll. 

4. Add an App Setting to your Web App with the following key:

PHP_INI_SCAN_DIR. 

Also, make sure to add the value

d:\home\site\wwwroot\ext

After deployment, you also can do this step to leverage Visual Studio Online extension.

5. Finally, you will need to set up the development environment of your Azure Web Apps and deploy your CakePHP application to Azure via Git.

Deploying the CakePHP application via Git is easy: 

  1. In the local terminal window, add an Azure remote to your local Git repository. Replace 
    <deploymentLocalGitUrl-from-create-step>
     with the URL of the Git remote
  2. Push to the Azure remote to deploy your app with the following command: git push azure master

Congrats! You’ve successfully deployed your CakePHP application to Azure!

Now that you have deployed your CakePHP application, you can focus on improving and upgrading the app without fearing that you might make a coding error and ruin your process so far. 

How to deploy CakePHP to AWS

The needs: 

In order to deploy a CakePHP application to AWS you will need: 

  • An account on AWS
  • An Elastic Beanstalk subscription
  • CakePHP installed
  • Your CakePHP application 

To deploy your CakePHP application to AWS you’ll want to use Elastic BeanStalk – an orchestration service offered by Amazon Web Services to help its users deploy applications. 

With Elastic Beanstalk you will be able to deploy your CakePHP application in no time, by following a few simple steps: 

  1. First off, start by creating a source bundle containing the files created by Composer.
  2. The following command creates a source bundle named 
    cake-default.zip
    . This also excludes files in the vendor folder, which take up a lot of space. Don’t worry, they are not necessary for the deployment process. 
  3. Upload the source bundle to Elastic Beanstalk to deploy CakePHP to your environment.
  4. When you choose to deploy a source bundle you will need to go to the Regions list from your Elastic Beanstalk and select your AWS Region.
  5. In your navigation pane, choose Environments, and then select the name of the environment you want to use from the list.
  6. Click on Upload and DeployUse the on-screen dialog box to upload the source bundle. Finally, click on Deploy.

As you can see, each cloud provider has its own set of steps that you need to follow to deploy a CakePHP application. If you’re using both of these cloud providers, manually deploying your app could become a time-consuming and repetitive task.

Looking for a better solution? Keep on reading!

How to use Bunnyshell to deploy CakePHP to the cloud

The needs: 

In order to deploy a CakePHP application to any cloud with Bunnyshell you will need: 

  • A Bunnyshell account
  • A Git repository
  • An account for any cloud provider supported by Bunnyshell (Digital Ocean, AWS and Azure)
  • Your CakePHP application 

Bunnyshell helps you manage and automate your cloud infrastructure. Creating and deploying applications is easier, faster and more secure, no matter which cloud provider you’re using. 

With Bunnyshell, you can deploy your applications directly from Git Repository: just log into your Bunnyshell account, connect your Git Repository, select the application and deploy it. You can also create and deploy your CakePHP applications directly in Bunnyshell, with no repository needed. 

Let’s take a look at how you can create and deploy your CakePHP application:

  1. First, you will need to create your application.
  2. Click on the button Create, located in the right corner of the dashboard. 
  3. Click on Framework and select CakePHP.Select Virtual machine and your Cloud provider (Bunnyshell supports DigitalOcean, AWS and Azure)
  4. Select the Location and your desired Plan. 
  5. Finally, name your application and press Create.

Once you finish creating the application, you can deploy it by going to your Application view, specifying the branch or tag you want to deploy, and hitting the Deploy button. 

Instant deployments, with just one click. Deploying a CakePHP application in AWS, Azure, or in any other cloud doesn’t have to be a manual, time-consuming task. With Bunnyshell, you can automate these repetitive tasks and boost your end-user experience through agile deployment.

Previously published at https://www.bunnyshell.com/blog/cakephp-application-cloud/