FuelPHP Application Development Blueprints - Sebastien Drouyer - E-Book

FuelPHP Application Development Blueprints E-Book

Sebastien Drouyer

0,0
35,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

This book is for intermediary to seasoned web developers who want to learn how to use the FuelPHP framework and build complex projects using it. You should be familiar with PHP, HTML, CSS, and JavaScript, but no prior knowledge about MVC frameworks is required.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 284

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

FuelPHP Application Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Building Your First FuelPHP Application
About FuelPHP
Development process of a FuelPHP application
Installing the environment
Windows
Mac
Ubuntu
Recommended modules and extensions
Getting the FuelPHP framework
Installing FuelPHP 1.7.2
Downloading the appropriate ZIP file
Using Composer
Updating FuelPHP
Installation directory and apache configuration
The simplest way
By setting up a virtual host
FuelPHP basics
The FuelPHP file system hierarchy
The app directory
The packages
Class name, paths, and coding standard
MVC, HMVC, and how it works on FuelPHP
What is MVC?
How it works on FuelPHP
Actions and controllers
Views
Parameters
Routes
Presenters
What is HMVC?
The oil utility and the oil console
Building your first application
Database configuration
Scaffolding
Migrating
Using your application
Refining the application
Refining the monkey listing
Refining the monkey detailed view
Allowing an empty description
Checking whether the height is a float
Using a checkbox instead of an input for the still_here attribute
Setting custom routes
Removing useless routes and files
A few notes about deploying your application
Summary
2. Building a To-do List Application
Specifications
Conception
FuelPHP installation and configuration
Scaffolding
Routes configuration
The profiler
Models, relations, and the ORM
Differences between CRUD and ORM
The FuelPHP ORM
DB and ORM basics
Executing queries without the ORM
Creating new objects
Finding specific objects
Updating an object
Deleting an object
Loading several objects
Using method chaining
More complex requests
ORM relations
Defining relations inside the models
Testing the relations
Getting objects' relations
Updating objects' relations
Observers and events
Implementation of the to-do list
Allowing the user to see and change tasks' status
Allowing the user to add tasks
Allowing the user to change tasks' order
Axis of improvements
Summary
3. Building a Blog Application
Specifications
Conception
Preliminary steps
Scaffolding the posts
Migrating part 1
The administration panel
The Auth package
Creating the Blog module
Moving files to the Blog module
Improving the navigation bar
Scaffolding the rest of our project
Scaffolding categories
Generating files
Moving categories to the blog module
Migrating
Scaffolding comments
Scaffolding posts (front)
Refining the administration panel
Refining the posts administration panel
Improving the post creation and edition forms
Removing and automatically filling the slug
Changing the small description input to a textarea
Editing the post content using a WYSIWYG editor
Replacing the category input by a select box
Replacing the user_id field by author
Removing the View link
The posts' list
Removing the Slug, Small description and Content columns
Displaying the category and author names
Removing the view link
Refining the categories administration panel
Removing the View link
Adding the number of post's column
Solution 1: using count
Solution 2: using related
Solution 3: using DB::query
Refining the comments administration panel
Improving the comments listing
Removing the view and adding a new comment link
Removing the Email and Content columns
Replacing the Post id column by Post
Improving the comment edition form
Changing the Status input to a select box
Replacing Post id by Post
Removing the View link
Protecting your website against CSRF attacks
Protecting links
Protecting forms
Refining the front-end
Refining the posts' listing
Deleting useless features
Changing how the posts' listing is displayed
Adding pagination
Using posts' slug
Listing posts by categories
Adding indexes
Refining the posts' visualization webpage
Changing the post layout
Adding the comment form
Displaying comments
Notifying the author when a new comment is posted
Clearing rejected comments
Additional improvements
Summary
4. Creating and Using Packages
What are CAPTCHAs?
Preliminary steps
Generating the sample application
The reCAPTCHA solution
Installing the recaptcha package
Configuring the recaptcha package
Integrating the recaptcha package
Creating your own package
Conception
Generating the package
Generating the Captcha_Answer model
Migrating the package
Integrating the package into our application
Implementing the get_html method
Implementing the CAPTCHA verification method
Cleaning old captchas
Possible improvements
Summary
5. Building Your Own Restful API
Specifications
Conception
FuelPHP installation and configuration
The Parser package and template engines
A major benefit of language-agnostic template engines
Subscription and authentication features
Implementing the subscription and authentication forms
Handling the signup form
Handling the signin form
Allowing the user to sign out
Allowing the user to create and view posts
Generating the Post model
Allowing the user to create new posts
Implementing the user interface
Implementing the post creation action
Implementing the profile page
Configuring the routes
Creating the user model
Implementing the show action
Implementing views
Implementing the API
Implementing the base controller
Implementing your first hybrid action
Implementing mappers to control how the information is shared
Improving the listing
Giving JavaScript access to our Mustache views
Generating the templates.js file
The easy and dirty way
Using guard-templates
Integrating template.js and Mustache.js
Implementing the post/list action
Implementing the See more button
Redirecting the home page to the logged user's web page
Unit tests
Possible improvements
Summary
6. Building a Website Using Novius OS
About Novius OS
Getting Novius OS
Configuring Novius OS
Exploring Novius OS
The applications manager
The Novius OS desktop
Novius OS' front and the default homepage
The Webpages application
Novius OS templates
The App Desk
Inserting enhancers in your webpages
The Novius OS file system hierarchy
Applications folder structure
Files extensions
Configurations and classes
Creating an application
Installing the 'Build your app' wizard
Generating the application
Testing your generated application
Application basics
The metadata configuration file
The migration files
The App desk
The edition and creation forms
The front controller
More about Novius OS
Summary
Index

FuelPHP Application Development Blueprints

FuelPHP Application Development Blueprints

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: February 2015

Production reference: 1200215

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78398-540-1

www.packtpub.com

Credits

Author

Sébastien Drouyer

Reviewers

Ivan Đurđevac

Márk Sági-Kazár

Kenji Suzuki

Aravind Udayashankara

Commissioning Editor

Kartikey Pandey

Acquisition Editor

Nikhil Chinnari

Content Development Editor

Melita Lobo

Technical Editors

Sebastian Rodrigues

Mohita Vyas

Copy Editors

Pranjali Chury

Sameen Siddiqui

Ashwati Thampi

Project Coordinator

Kinjal Bari

Proofreaders

Simran Bhogal

Kevin McGowan

Linda Morris

Indexer

Tejal Soni

Graphics

Sheetal Aute

Disha Haria

Abhinash Sahu

Production Coordinator

Alwin Roy

Cover Work

Alwin Roy

About the Author

Sébastien Drouyer is a computer science research engineer from France. He has a master's degree in computer science from the National Institute of Applied Sciences of Lyon, one of the most prestigious engineering schools in France. He has been developing web applications since 2005 and has won various contests and awards from GitHub, NASA, and Intel. He has also been a member of the Novius OS core team (an open source content management system based on the FuelPHP framework) and published many additional open source projects. He has trained several teams on FuelPHP and is a conference speaker on the subject.

First of all, I would like to thank the FuelPHP core team and its community for improving this wonderful framework every day.

If there are only a countable number of errors in this book, then it is due to Aravind Udayashankara, Kenji Suzuki, Sági-Kazár Márk, Ivan Đurđevac, Craig Hooghiem, and John Alder who all did excellent reviews.

I would like to salute the amazing Novius OS core team and I wish them the best in their future endeavors.

I would also like to thank the Packt Publishing team, especially Melita Lobo, for their patience and professionalism.

Last, but not least, I would like to thank my very supportive family and friends. A special thanks to my mother and father for making me the person I am today; I wouldn't be here without you two.

About the Reviewers

Ivan Đurđevac is a PHP developer from Serbia, Pančevo. Long time ago, he found out the "development" word with Delphi. Prior to 2000, the Web was a huge deal, and he decided to pick PHP as his main tool. He started with CodeIgniter as his first framework. After a while, he realized that CodeIgniter did not allow him to write beautiful code to solve problems with design patterns, and he saw it would stay that way, trapped in PHP4. So, he switched to Kohana and Zend Framework and it was a big step forward. FuelPHP was a new kid on the block. It took all the best features from others and created a modern framework. He used FuelPHP to build large-scale applications. At the time this book was written, he used Laravel as his codebase. No matter which framework he uses, clean code is always a priority for him. He will never stop learning from better developers and modern practices.

He has worked for various companies on many projects, such as e-learning platforms, CMS-ES, social network sites, and business applications. Currently, he is working for a USA-based company that builds various internet marketing tools, which collaborate with AWeber, Infusionsoft, and other tools. He is also interested in DevOps and likes to play with Linux administration and set up server boxes and maintain them.

Márk Sági-Kazár was previously working with CodeIgniter, and picked up FuelPHP in 2011. Since 2014, he has been actively developing for FuelPHP, starting with the E-mail package. From the autumn of 2014, he has been an official member of the FuelPHP team.

Mark started playing with programming at the age of 6. While in high school, he worked with several Microsoft languages; Visual Basic is one of them. After finishing high school, he switched to PHP as his programming language of choice. Starting with CodeIgniter, he quickly switched to FuelPHP and delivered his first production application (an e-commerce site) in 2012, followed by IndigoPHP in 2013, which is an application framework and CMS built on top of FuelPHP. Besides his work on FuelPHP V2, he's currently working on some good quality packages such as a SupervisorPHP (http://supervisorphp.com) and shopping cart abstraction, to name some.

Kenji Suzuki is a programmer and web developer living in Japan. He is a contributor to FuelPHP, BEAR.Sunday, CodeIgniter, and many other open source projects. He is a PHP expert, Certified PHP 5 Engineer Expert by the Engineer Certification Corporation for PHP (http://www.phpexam.jp/about/English/), and coauthor of the Japanese best-seller and highly-praised PHP recipe book, PHP gyakubiki reshipi, SHOEISHA.Co.,Ltd. He has published several books about PHP with famous Japanese IT book publishers. His latest book is Hajimeteno Framework toshiteno FuelPHP,Rutles, Inc. You can find the repositories of his various projects on GitHub at https://github.com/kenjis.

Aravind Udayashankara is an autodidactist and software engineer. He has been working on several open source server-side technologies, such as NodeJS, PHP, and Ruby, and browser-side technologies such as AJAX, JavaScript, XML, HTML, and many more since 2008. He loves and enjoys to learn, understand, and express complex things, as well as blog on his own website, http://aravindhu.com. He is now eagerly eyeing the world of mobile application development and big data.

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Preface

The main idea behind FuelPHP Application Development Blueprints is to teach you FuelPHP's basic and advanced features by building various projects of increasing levels of complexity. It is very result-oriented; at the beginning of the chapters, we specify the application we want to build, and then we progressively implement it by learning how to use new FuelPHP features along the way. Our approach will therefore be very practical; a lot of concepts will be explained using code examples, or by integrating them directly into our projects. Thus, it is important to highlight that there will be a lot of code and you should be comfortable with reading and understanding PHP and HTML. As we will use them from time to time, having some knowledge about server/system administration and some foundation in JavaScript, jQuery, and CSS will be an added advantage.

Though this book is for intermediary to advanced web developers, any prior knowledge of the FuelPHP framework, or any other PHP framework, is not required. In order to understand this book, you don't have to know common concepts such as MVC, HMVC, or ORM. We take into account this shortcoming some of you might have, and important notions will be explained. We won't explain all of those in the first chapter though, as we want this to be as painless as possible; we will instead approach them when they become necessary for the project completion.

The ultimate purpose of FuelPHP Application Development Blueprints is to give you the ability to build any project using FuelPHP. By the end of this book, you certainly won't know every little detail of the framework, but you will hopefully have the necessary toolbox required to implement complex and maintainable projects.

What this book covers

Chapter 1, Building Your First FuelPHP Application, covers the very basics of the FuelPHP framework; how to install it, how to configure it, how it is organized, and its main components. Along the way, we will generate our first FuelPHP application using the oil utility and tweak some files, in order to illustrate how things work.

Chapter 2, Building a To-do List Application, focuses on FuelPHP's ORM and debugging features. We will illustrate these features using a lot of examples, and then implement a small to-do list application. We will also use some JavaScript and jQuery to send AJAX requests.

Chapter 3, Building a Blog Application, will teach you how to generate and tweak an administration interface easily, how to create your own modules and tasks, how to manage paginations easily, and how to use the Auth and Email packages. We will create a blog application implementing all these features.

Chapter 4, Creating and Using Packages, will approach the FuelPHP package system. This is a rather short chapter; we will first try to protect our website from spam bots by installing an existing package, and then create our own original solution by creating a new package.

Chapter 5, Building Your Own RESTful API, covers more advanced subjects such as building a JSON API, using language agnostic template engines, allowing user subscriptions, and implementing unit tests. To illustrate this, we will create a responsive micro blogging application featuring a public API.

Chapter 6, Building a Website Using Novius OS, will quickly introduce you to Novius OS, a FuelPHP-based Content Management System. Using such a system can greatly speed up the implementation of complex projects.

What you need for this book

The applications in this book are based on FuelPHP 1.7.2, which requires:

A web server: The most common solution is ApacheA PHP interpreter: The 5.3.3 version or greaterA database: we will use MySQL

FuelPHP works on Unix-like and Windows operating systems. The mod_rewrite Apache module and some additional PHP extensions are recommended; the complete list is available at http://fuelphp.com/docs/requirements.html.

Who this book is for

This book is for intermediary to seasoned web developers who want to learn how to use the FuelPHP framework and to build complex projects using it. You should be familiar with PHP, HTML, CSS, and JavaScript, but no prior knowledge about MVC frameworks is required.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Remove APPPATH/classes/controller/welcome.php as we don't need this controller anymore."

A block of code is set as follows:

<?php echo Form::checkbox( 'still_here', 1, Input::post( 'still_here', isset($monkey) ? $monkey->still_here : true ) ); ?>

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: " Click on the Generate button."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/5401OS.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Building Your First FuelPHP Application

Throughout the book, we will use the FuelPHP framework to build different types of projects. The objective of this chapter is to make you familiar with the basics of the framework and create your first project as quickly as possible. We won't create anything exceptional in this chapter and there will be very little coding, but we will go through the whole process from installing FuelPHP to publishing your project on a production server. You will learn the necessary basics for the other projects as well.

By the end of the chapter, you should know the following:

A common development process of a FuelPHP applicationHow to install FuelPHP (the latest or a specific version)The FuelPHP file system hierarchyTwo different ways to configure Apache to access your applicationHow to configure FuelPHP to connect to a databaseThe oil command line and how to use it for scaffolding your applicationHow does an application respond to a URL requested by a visitorWhat are the FuelPHP templatesHow to publish your project to a host

Since this book is intended for intermediate developers, we will assume that you have already installed Apache and MySQL on your system. Some prior knowledge of Git and Composer is an added advantage as you might need it, but you should be fine in this book if you are not familiar with these tools. However, for advanced applications that need collaboration between several developers mastering them is highly recommended.

In this chapter, we will go from installing the FuelPHP framework to having a functional – though limited – web application. As our objective here is to introduce the framework and create a sample application as quickly as possible, we won't address important topics such as the ORM, which will be addressed in Chapter 2, Building a To-do List Application.

About FuelPHP

Dan Horrigan started the FuelPHP framework in late 2010, and was later joined by Phil Sturgeon, Jelmer Schreuder, Harro Verton, Frank de Jonge, Steve West and Márk Sági-Kazár. The first stable version was released on July 31st, 2011 and this book is based on FuelPHP 1.7.2, the latest stable version available as of writing this book. With over 300 contributors, its community is large and active.

The core team is currently working on the second version of FuelPHP; several alpha versions of it have already been released.

If you want to know more about the FuelPHP team and the framework philosophy, I recommend you to read the About FuelPHP section of the official website at:

http://fuelphp.com/about

You can read the latest news about the framework on its official blog at:

http://fuelphp.com/blogs

The official documentation can be found at: http://fuelphp.com/docs/

If you have any questions about FuelPHP or encounter any issues, you can search the official forum (http://fuelphp.com/forums/) and start a new discussion if you don't find any answer. In a general manner, the official website (http://fuelphp.com) is an excellent resource.

Development process of a FuelPHP application

The development process of a FuelPHP application generally contains the steps shown in the following image:

Install FuelPHP: Since we are using this framework, this first step is quite obvious.Config (configuration): At the beginning, you will generally need to specify how to connect to the database and which package you will use. Later on, you might also need to create and use your own configuration files to improve the maintainability of your application.Scaffold: The oil command line of FuelPHP allows you to easily generate code files ready to be used. This step is not necessary, but we will often use this functionality in this book because it really speeds up the implementation of your application.Dev (development): This is where you, as a developer, step in. You customize the generated code to get exactly what you want. When you want to add new features (for instance a new model), you go back to the scaffolding step.Tests: Functional and unit testing are important if you want large applications to stay maintainable. When bugs are discovered, you go back to the development step in order to fix them. Unlike the other steps, we won't approach this subject in this chapter for the sake of its conciseness. It will be addressed in Chapter 5, Building Your Own RESTful API.Prod (production): Having a project working locally is nice, but the final objective is generally to publish it online. We will give you some directions about this step at the end of this chapter, but we won't get too much into the details, given the diversity of available hosting services.

Just to be clear, this is a very general guideline, and of course the order of the steps is not rigid. For instance, developers using the test-driven development process could merge the fourth and fifth steps, or a preproduction step could be added. The development process should only depend on each developer and institution's standards.

Installing the environment

The FuelPHP framework needs the following three components:

Web server: The most common solution is ApachePHP interpreter: The 5.3.3 version or greaterDatabase: We will use MySQL

FuelPHP works on Unix-like and Windows operating systems, but the installation and configuration procedures of these components will depend on the operating system used. In the following sections we will provide some directions to get you started in case you are not used to installing your development environment. Please note that these are very generic guidelines, so you might need to search the web for complimentary information. There are countless resources on the topic.

Windows

A complete and very popular solution is to install WAMP. This will install Apache, MySQL, and PHP, in other words everything you need to get started. It can be accessed at http://www.wampserver.com/en/.

Mac

PHP and Apache are generally installed on the latest version of the OS, so you just have to install MySQL. To do this, you are recommended to read the official documentation at http://dev.mysql.com/doc/refman/5.1/en/macosx-installation.html.

A very convenient solution for those who have the least system administration skills is to installMAMP, the equivalent of WAMP, but for the Mac operating system. It can be downloaded from http://www.mamp.info/en/downloads/.

Ubuntu

As this is the most popular Linux distribution, we will limit our instructions to Ubuntu.

You can install a complete environment by executing the following command lines:

# Apache, MySQL, PHPsudo apt-get install lamp-server^# PHPMyAdmin allows you to handle the administration of MySQL DBsudo apt-get install phpmyadmin# Curl is useful for doing web requestssudo apt-get install curl libcurl3 libcurl3-dev php5-curl # Enabling the rewrite module as it is needed by FuelPHPsudo a2enmod rewrite # Restarting Apache to apply the new configurationsudo service apache2 restart

Recommended modules and extensions

The Apache mod_rewrite module and some additional PHP extensions are also recommended, but not required:

http://fuelphp.com/docs/requirements.html (can be accessed through the FuelPHP website by navigating toDOCS | TABLE OF CONTENTS | FuelPHP | Basic | Requirements)

Getting the FuelPHP framework

As this book is being written, there are four common ways to download FuelPHP:

Downloading and unzipping the compressed package which can be found on the FuelPHP website.Executing the FuelPHP quick command-line installer.Downloading and installing FuelPHP using Composer.Cloning the FuelPHP GitHub repository, it is a little bit more complicated but allows you to select exactly the version (or even the commit) you want to install.

These approaches are very well-documented on the website installation instructions page at http://fuelphp.com/docs/installation/instructions.html (It can be accessed through the FuelPHP website by navigating to DOCS | TABLE OF CONTENTS | FuelPHP | Installation | Instructions)

Installing FuelPHP 1.7.2

FuelPHP is always evolving and will continue to evolve even after this book is published. As we used FuelPHP 1.7.2 in this book, you might want to install the same version in order to prevent any conflict. You can do this by either downloading the appropriate ZIP file, cloning the 1.7/master branch of the GitHub repository, or using Composer.

Downloading the appropriate ZIP file

This is the simplest solution. You should be able to download it by requesting the URL http://fuelphp.com/files/download/28.

Alternatively, you can access all the compressed packages of important FuelPHP releases at http://fuelphp.com/docs/installation/download.html (It can be accessed through the FuelPHP website by navigating to DOCS | TABLE OF CONTENTS | FuelPHP | Installation | Download)

Using Composer

First, if you didn't do it yet, you need to install Composer. You can find out how by reading the official website at https://getcomposer.org/.

The installation instructions for major operating systems are given in the Getting Started guide. Please note that you can install Composer either globally or locally.

From now on, we will generally assume that you have installed Composer globally. If Composer is installed locally into your working directory, our instructions will work if you replace composer by php composer.phar.

In order to specifically install FuelPHP 1.7, you can simply execute the following command line (replace TARGET by the directory in which you want to download FuelPHP):

composer create-project fuel/fuel:dev-1.7/master TARGET

Updating FuelPHP

If you have downloaded FuelPHP by cloning the GitHub repository, or if you simply want to update FuelPHP and its dependencies, you have to enter the following command line at the location you installed your instance of FuelPHP:

php composer.phar update

As you can see, Composer is locally installed in the FuelPHP root directory.

Installation directory and apache configuration

Now that you know how to install FuelPHP in a given directory, we will give you the two main ways you can integrate the framework in your environment.

The simplest way

Assuming you have activated the mod_rewrite Apache module, the simplest way is to install FuelPHP in the root folder of your web server (generally the /var/www directory on Linux systems). If you install FuelPHP in the DIR directory of the root folder (/var/www/DIR), you will be able to access your project at the following URL:

http://localhost/DIR/public/

However, be warned that FuelPHP has not been implemented to support this, and if you publish your project this way in the production server, it will introduce security issues you will have to handle. In such cases, you are recommended to use the second way we will explain in the upcoming section, although, for instance if you plan to use a shared host to publish your project, you might not have the choice. A complete and up-to-date documentation about this issue can be found in the FuelPHP installation instruction page at http://fuelphp.com/docs/installation/instructions.html (It can be accessed through the FuelPHP website by navigating to DOCS | TABLE OF CONTENTS | FuelPHP | Installation | Instructions)

By setting up a virtual host

Another way is to create a virtual host to access your application. You will need a little bit more Apache and system administration skills, but the benefit is that it is more secure and you will be able to choose your working directory. You will need to change two files:

Your Apache virtual host file(s) in order to link a virtual host to your applicationYour system host file in order to redirect the wanted URL to your virtual host

In both cases, the files' location will be dependent on your operating system and the server environment you are using; therefore, you will have to figure out their location yourself (if you are using a common configuration, you won't have any problem to finding instructions on your preferred search engine).

In the following example, we will set up your system to call your application when requesting the my.app URL on your local environment (*nix system recommended).

Let's first edit the virtual host file(s). Add the following code at the end:

<VirtualHost *:80> ServerName my.app DocumentRoot YOUR_APP_PATH/public SetEnv FUEL_ENV "development" <Directory YOUR_APP_PATH/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>

Then, open your system host file and add the following line at the end:

127.0.0.1 my.app

Depending on your environment, you might need to restart Apache after this. You can now access your website at: http://my.app/.

Congratulations! You just have successfully installed the FuelPHP framework. The welcome page shows some recommended directions to continue your project.

FuelPHP basics

Now that we have installed a