Last year I wrote an article covering best available PHP RESTful micro frameworks, now I want to show you how to create a simple RESTfull using the Fat-Free Framework. This article will cover only installation, configuration, and basic example. Next one will include more Fat-Free information and additional working examples. I will include Windows and Linux (Debian/Ubuntu) setup, one after another.
Before we start this tutorial make sure, you have everything installed/configured to handle PHP and Fat-Free. To make it easier, we will use preconfigured development environments, WAMP for Windows and LAMP for Linux. I do not advise using WAMP/LAMP for your production environment.
Useful LinksOfficial Site GitHub User Guide
Table of Contents
Fat Free Example
Go to the official WAMP site and get the latest version, or any other if you don’t want the use latest version. Depending on your Windows platform (32 bit or 64 bit), select Windows Installer (.msi) and download it.
When you click on download directly current page will change to sourceforge.net download location, don’t click on anything, download will start automatically. Begin the installation when download completes. During this process, you will be prompted to select your default browser, do so.
If you receive this error during the installation you should also install Visual Studio 2012 VC 11 vcredist_x64/86.exe (again select 32 or 64 bit version):
Restart WAMP or Windows. If you did everything correctly, WAMP icon (in the icon tray) should glow green, and you will be able to open your browser and go to the localhost. For the purpose of this article, WAMP is installed at this location:
and PHP should be installed at this location:
Copy this path and add it to your environment PATH. Take a look at this tutorial if you don’t know how to do that, you will find examples for Windows XP, Windows 2000 and Windows 7. It should look like this:
Do the same thing with curl, find it here:
If you are using different WAMP version then this there’s a good chance you won’t find curl in that folder. In this case just go to WAMP root folder and search for curl.exe. Copy this path and add it to your environment PATH, it should look like this:
First create a folder for the Composer. Go to this location:
And create a folder named:
Copy this path and add it to your environment PATH, it should look like this:
Open Windows command prompt (at this location: c:\WAMP\bin\) and execute:
curl -sS "http://getcomposer.org/installer" | php -- --install-dir=composer
If you did everything correctly, output should look like this:
#!/usr/bin/env php All settings correct for using Composer Downloading... Composer successfully installed to: C:\WAMP\www\composer\composer.phar Use it: php composer/composer.phar
While you are still in the command prompt, go to this newly created folder: C:\WAMP\bin\composer and execute this:
echo @php "%~dp0composer.phar" %*>composer.bat
First create a project folder. Go to this location:
And delete everything you find there, do this only once after the initial WAMP installation. The www folder (sometimes it’s also called public_html or htdocs) is the web root for your primary domain name. This means that www is the folder where you put all website files which you want to appear when someone types your primary domain (the one you provided when you signed up for hosting, or localhost in our case). Our project folder name will be (name it any way you want):
Open command prompt and go to the project folder. Execute this line:
composer require bcosca/fatfree *
File structure will look like this:
fatfree_demo --->composer.json --->composer.lock --->vendor --->composer --->bcosca --->autoload.php
Start WAMP server by clicking on its icon (if it’s already not running). Wamp icon should appear in Windows system tray. Left click on it, browse through Apache -> Apache modules -> end finally
Restart Apache server.
This tutorial has been tested on a single VPS DigitalOcean 512MB droplet, Ubuntu 14.04 x64. It is much shorter than a Windows preparation tutorial … go figure.
Execute this first:
sudo apt-get update
If you don’t update package lists from the repositories, you will probably receive this error: tasksel: aptitude failed (100). Now we’ll install the LAMP stack:
Taskel will open a GUI menu, select only LAMP server, press OK, wait some time and finally enter MySQL root password when GUI prompts you:
If you still can’t manage to finish the installation (error mentioned above) install it directly like this:
sudo tasksel install lamp-server
Do this step only if haven’t previously installed Curl:
sudo apt-get install curl
Execute these lines:
curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer
It should look like this: