PHP as a Service – Fortrabbit

Share this article

PaaS (platform as a service) is not a new concept. The fact of the matter is hosting companies have long since provided PaaS when they sell shared-hosting services that include PHP on the shared server. This is fundamentally different, however, from how a PaaS business works. In this article, we’ll take a look at a newcomer to the platform service provider arena – Fortrabbit – and set up a simple PHP/MySQL application that can be publicly accessed in a matter of minutes. Basic knowledge of the LAMP stack is assumed, and you also need to have a basic grasp of Git (if you don’t here’s a decent introduction), and you need to have SSH keys generated and ready for use (if you don’t, refer to this resource from GitHub). This walk-through is Unix oriented (so OS X and Linux users are fine), but it can also be applied to a Windows environment with minor changes.

Fortrabbit – the Who, Why, and How

Fortrabbit is a young PaaS company who say the hosting business is broken, and too much about price dumping and too little about quality. In order to fix the problem, they made a PHP-exclusive business that caters to developers’ most common needs. Their hosting plans are accessibly-tiered for everyone, from hobbyists (free plans) to enterprises (high-availability upgrades are available at the click of a button). With a single dashboard, you have an overview of all your applications, regardless of your role in them. Applications can be made publicly visible whenever you choose to deploy, so you can easily demonstrate what you’re building to your clients whenever you want. Once an application is complete, you can transfer ownership to the client, who then becomes in charge of payments from that point onward. You can even retain a “Project Manager” role on the application to be able to perform future fixes and upgrades. The whole freelancing process is literally streamlined into minutes. Deploying works with Git, SSH, SFTP, ReSync, and Composer. You have full SSH access to your application and can play around with it however you see fit. Frameworks and content management systems are supported and easily installable out of the box, and Phalcon support is coming soon now available too (version 0.9)!

The demo app

Let’s get a simple Hello World application up and running. Clone the example repository from Github. It’s nothing but a simple CodeIgniter skeleton application, slightly modified for our purposes here. The controller reads the URL input to find an ID parameter, and if it finds none, it sets it to 1, otherwise, it uses the one provided. This ID parameter dictates which database row we fetch, and thus whether the output will print “Hello World” or “Hello Bruno”. See the db directory for the SQL import script create a database called “sitepoint”. Also, modify the database.php file in the application/config directory accordingly so your app can access the database. In my case, the username is root, and I have no password. Test the application by creating a virtual host for it. For the sake of example, let’s assume you named the host fortrabbit.sitepoint.test. Thus, entering fortrabbit.sitepoint.test/ into your browser should say “Hello World!” and fortrabbit.sitepoint.test/welcome/index/id/2 should say “Hello Bruno!”. All good? Great! Let’s cloud it up.

Setting up a Fortrabbit Application

Go to Fortrabbit and sign up for an account. Once you have an account, proceed to click the New App button on the dashboard: Select the Bootstrap Free plan on the next screen and click Purchase. Note the “freeze” limitation – after a certain amount of inactivity, you app will become frozen and unavailable and you’ll have to log back in to “thaw” it. This is to both conserve resources and prevent users from hogging their services without paying. Consider it an unlimited free trial. On the next screen, enter an app name and your public SSH key. We’ll need this to push our app live. See the following figure for reference. You’ll have to wait for the setup to complete on the next screen, and a couple of minutes later for your app to be ready. You’ll receive an email with all the necessary credentials and URLs to manage and visit your application. In fact, visiting the Test URL from the email/final configuration screen will produce a screen not unlike this one:
A full report of the stack you’re running is shown, a working application ready to be turned into something useful.

Dashboard

The app dashboard Fortrabbit takes you to after you click “Take me to my app” on the final configuration screen is where proper management takes place. Here you can see how much time you have until the app is frozen, and can reset the timer at will. All you do by doing that is prove your activity and the app stays alive, simple as that. The strength and cost of your app’s plan are defined here as well, along with some quick stats and a list of purchased add-ons (e.g. Memcache is an add-on you need to pay extra for). The stats tab will give you a detailed overview of your app’s performance, and the Git tab lets you revisit the public SSH key input from the initial configuration.The SSH/SFTP tab simply lists access credentials. The PHP tab lets you set some configuration directives and PHP options and the domains tab provides an easy access to defining new domains and subdomains so you can have a custom domain point to your application and get rid of the long eu.frbit suffix. There is also the permissions tab which lets you define a new owner for the application for the purposes of a transfer, add team members, and more (the free bootstrap plan only supports a one-man operation though).

Deploying

Fortrabbit, being young, still does’t have a web GUI for MySQL installed, so no PHPMyAdmin. You can, of course, install your own – but there’s another option that’s quite practical. MySQL Workbench supports remote tunnel connections via SSH, so assuming you have it installed (and you really should have it installed), open a new connection and define all the required parameters: Now you have access to your remote database via a local client – and editing the database could not be easier. Since the Fortrabbit MySQL user/pass combo is different from our local setup, we need a way to accommodate this without having to constantly update the database configuration. Luckily there’s an easy way to do this as well. At the end of application/config/database.php, we placed the following code (replace your username and password accordingly):
<!--?php <br ?-->if (isset($_SERVER['APP_NAME'])) {
    // This means we're on Fortrabbit, and need different credentials.
    // Local setups don't have the "APP_NAME" environment variable
    $db['default']['hostname'] = 'sitepoint.mysql.eu1.frbit.com';
    $db['default']['username'] = 'sitepoint';
    $db['default']['password'] = 'xxxxxxxx';
}
This works because Fortrabbit defines an environment variable for every app called APP_NAME which we don’t have on our local machine. Whenever we’re testing locally, our app accesses the local database as it did before. When we test online, the username, password, and host switch to the Fortrabbit credentials. Note that you can define an arbitrary amount of environment variables in the app’s dashboard under the PHP tab. The next step is importing the SQL file into the database. With our connection to MySQL still open, import the provided SQL file from the db folder. Now let’s finally deploy our application. This is done in several steps and has multiple possible approaches; we’ll cover only one.

Step 1: Clone your current Fortrabbit app

In the terminal, enter git clone git@git1.eu1.frbit.com:sitepoint.git which will clone an empty repository from your Fortrabbit app. It might be strange that the repo is empty when in fact you see some content when you visit the app’s URL, but this is because there’s a hidden index.php file inside it already that’s initially ignored. As soon as you push the first commit, this index.php file is overwritten (if you added such a file in the root of your project, that is).

Step 2: Add content to folder, add to Git

Next, we take the entire content of our local application and just move it into this directory. Then add the contents of the directory to the repository with the following command: git add *, and of course, make a commit (git commit -am 'Initial commit'
)

Step 3: Push the app live

Use the git push origin master command to push your application live. The origin master part is only required on first push – subsequent pushes do not require it.

Step 4: Change the domain setting

In the “Manage app” screen under the domains tab, add public after the original URL in the input field, like so: This is so the server looks for the application root inside public, instead of the unavailable top folder. That’s it! Visit your app now via its URL and you should see it work just as it does locally. Append the URL part with the parameters (/welcome/index/id/2) and see the string change. This shows us that both URL rewriting and the database connection work as they should.

Free Give Away

In a sea of *aaS services, Fortrabbit stands out with usability, simplicity, approachability and a heavily involved staff that are there for you every step of the way. In this generous and ambitious spirit, Fortrabbit is teaming up with SitePoint for an awesome give away! Five lucky readers will win coupon codes worth 100€ redeemable for Fortrabbit service. To be eligible, 1) try out Fortrabbit and post a comment below letting us know your experiences, or 2) follow @phpmasterdotcom and share this article on Twitter with the hashtag #phpmaster, all by February 20th. Five winners will be chosen at random shortly thereafter. Comment winners will be notified by email (be sure to provide a valid email address in the contact-form!) and Twitter winners by direct-message. Good luck!

Frequently Asked Questions (FAQs) about PHP as a Service on Fortrabbit

What is PHP as a Service on Fortrabbit?

PHP as a Service on Fortrabbit is a cloud-based platform that allows developers to run, manage, and scale PHP applications. It provides a fully managed PHP environment, eliminating the need for server management and configuration. This allows developers to focus on writing code and developing applications, rather than managing infrastructure.

How does Fortrabbit compare to other PHP as a Service providers?

Fortrabbit stands out for its simplicity and ease of use. It offers a fully managed PHP environment, which means you don’t have to worry about server management or configuration. It also provides a range of tools and features to help you develop, deploy, and manage your PHP applications, including Git integration, SSH access, and automated backups.

Is Fortrabbit suitable for beginners?

Yes, Fortrabbit is designed to be user-friendly and accessible to developers of all skill levels. It provides a simple, intuitive interface and a range of tools and features to help you get started with PHP development. Plus, it offers comprehensive documentation and support to help you along the way.

How secure is Fortrabbit?

Fortrabbit takes security seriously. It provides a range of security features, including SSL encryption, two-factor authentication, and automated backups. Plus, it operates in compliance with EU data protection regulations, ensuring that your data is handled securely and responsibly.

Can I use Fortrabbit for free?

Fortrabbit offers a range of pricing plans to suit different needs and budgets. While it doesn’t offer a free plan, it does provide a trial period that allows you to test out its features and see if it’s the right fit for you.

How does Fortrabbit handle scaling?

Fortrabbit is designed to scale with your needs. It provides automatic scaling, which means your applications can handle increased traffic without any manual intervention. Plus, it offers a range of pricing plans that allow you to scale up or down as needed.

Can I use my own domain with Fortrabbit?

Yes, Fortrabbit allows you to use your own domain. It provides a simple, straightforward process for setting up your domain, and it offers comprehensive documentation to guide you through the process.

What kind of support does Fortrabbit offer?

Fortrabbit offers comprehensive support to its users. This includes detailed documentation, a community forum, and a dedicated support team that’s available to assist with any issues or questions.

Does Fortrabbit support other programming languages besides PHP?

Fortrabbit is primarily a PHP platform, but it does support other technologies that are commonly used in PHP development, such as MySQL, Git, and Composer.

How does Fortrabbit handle backups?

Fortrabbit provides automated backups to ensure that your data is safe and secure. You can also manually backup your data at any time, giving you complete control over your data.

Bruno SkvorcBruno Skvorc
View Author

Bruno is a blockchain developer and technical educator at the Web3 Foundation, the foundation that's building the next generation of the free people's internet. He runs two newsletters you should subscribe to if you're interested in Web3.0: Dot Leap covers ecosystem and tech development of Web3, and NFT Review covers the evolution of the non-fungible token (digital collectibles) ecosystem inside this emerging new web. His current passion project is RMRK.app, the most advanced NFT system in the world, which allows NFTs to own other NFTs, NFTs to react to emotion, NFTs to be governed democratically, and NFTs to be multiple things at once.

Intermediate
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week