How To Install and Get Set Up with FuelPHP on Your VPS

Published on September 18, 2013
How To Install and Get Set Up with FuelPHP on Your VPS

About FuelPHP

FuelPHP is a community-driven open source PHP framework based on the OOP hierarchical Model-View-Controller (MVC) architecture. It features a great command line tool called Oil that allows you to speed up the development of your project. You can use it to generate code, debug or perform database migrations.

In this tutorial we will get started with a small FuelPHP application. To illustrate this, I will use an Ubuntu powered VPS with the LAMP stack installed. If you want more information about how to set this up, please consult this great tutorial. FuelPHP requires though a web server installed (has been tested with Apache, Nginx and IIS) and PHP 5.3+.


The first thing we need to do is get the quick installer onto our VPS using curl. Run the following command:

curl get.fuelphp.com/oil | sh

This will download the oil package and place it into the /usr/bin folder on your cloud server.

Quickly install Git as oil will need it to fetch the application code:

sudo apt-get update
sudo apt-get install git-core

Next, navigate to the web server document root (/var/www for Apache) and run the following command for creating your FuelPHP application:

oil create fuel

This will fetch the necessary files using Git and dependent libraries using Composer and put everything you need into a folder called fuel. If you now navigate in the browser to your-ip-address/fuel/public you should see the front page of your application.

If you want, you can change the web server's document root to point directly to the public folder of your FuelPHP application so that you can access it straight from your IP address (or domain name if you have one pointing at it). To do this, edit the following virtual host file:

nano /etc/apache2/sites-available/default

And change this line from this:

DocumentRoot /var/www/

To this:

DocumentRoot /var/www/fuel/public/

Then restart Apache for the changes to take effect:

sudo service apache2 restart

If you want FuelPHP to have clean URLs (to remove the ugly index.php segment from its URLs) you should make sure its .htaccess files can override default Apache instructions. For this, mod_rewrite needs to be enabled.

To check if it is available, use the following command:

apache2ctl -M

If you see "rewrite_module" in the list, you are fine. If not, use the following command to enable the module:

a2enmod rewrite

Next, edit the Apache default virtual host file (again) and make sure that Allow Overrides is set to All under the /var/www/ directory. This includes also the fuel application folders. Edit the file with the following command:

nano /etc/apache2/sites-available/default

And where you see this block, make the changes to correspond to the following:

<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all

Before we restart the server, let's quickly also set a default timezone in the php.ini file:

nano /etc/php5/apache2/php.ini

And in this file where you see the following line:

;date.timezone =

Remove the preceding semi-colon and set a PHP type timezone in the following format:

date.timezone = America/Toronto

Save the file and then restart Apache for the all the changes to take effect:

sudo service apache2 restart

Next up, let's create an empty database to use with our application. Assuming you are using MySQL or MariaDB, log into the appropriate terminal and run the following command:

create database fuel;

This will create an empty database called fuel. Exit the MySQL terminal and return to your application as we now need to edit its configuration file and enable some things. From the root of the FuelPHP application, edit the config file:

nano /var/www/fuel/fuel/app/config/config.php

In there, uncomment the always_load array, the packages array inside and the orm package. This will make sure FuelPHP loads the ORM package it comes with to help us create our working models. Save the file and exit. Now it's time to set the database connection. Still inside the app/config folder, inside a folder called development (given that you are by default in the development environment of FuelPHP), edit the db.php file:

nano /var/www/fuel/fuel/app/config/development/db.php

In there set the database name and credentials to connect to it, then save and exit.

Next, we'll need something called scaffolding. This is basically a set of controllers, models and views that define our model and contain the default CRUD operations code. Let's say our small application deals with articles for which we need a title and a body. So let's generate the scaffolding with the following command (from within the root application folder - /var/www/fuel):

oil generate scaffold articles title:string body:text

This command generates the scaffolding for our articles model for which we define a title of the type string (varchar(255)) and body of the type text. If you look in your fuel/app/classes folder you should see a new controller, model and views files. One last command we need to run for this model - the database migration command - which will create the table to house our article content:

oil refine migrate

This will use the instructions in the /var/www/fuel/fuel/app/migrations/001_create_articles.php file generated with the scaffolding to create the table with the appropriate columns. If you check in the database, you'll notice a new table called articles with 5 columns: id, title, body, created_at, updated_at (the first and last 2 generated automatically by FuelPHP).

Now you can navigate in the browser to the articles controller (ip-address/articles if your web server's document root points to the FuelPHP application's public folder) and you can from there perform all the CRUD operations on your article model. You can add, view, update and delete articles immediately.


In this tutorial we've seen how to install FuelPHP from the command line and how to quickly generate a bare bones application. Additionally we've seen how to generate a scaffolding for our articles model that creates automatically the necessary controller and model classes, as well as the views for performing CRUD operations on this model.

Article Submitted by: Danny

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Great Tutorial!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel