Installing & Configuring PhalconPHP

PhalconPHP

Phalcon PHP is a very impressive PHP MVC Framework that I’ve started to play around with. What differentiates it from the rest of the pack is the fact that it runs in memory on your server in the form of an extension. It’s compiled c code thus it’s executed much faster than a normal PHP framework would be. Unsurprisingly, this results in Phalcon blowing away all of the competition in speed tests.

Build & Install Phalcon Extension

First we need to make sure we have all the pre-requisites

Now lets download and build

The extension is built, now we need to enable the extension for use in php5-fpm. Create a new file at /etc/php5/mods-available/phalcon.ini and paste in the following

Symlink the file to the conf.d folder

That’s all for the install. Restart php5-fpm and the extension should be active.

Setup your domain

Assuming you are following the directory structure outlined in my previous articles, your domain looks something like this.

<!– Crayon Syntax Highlighter v_2 .7.2_beta –>

We will be using both the private and the public folder for our Phalcon project. I’m going to re-use the Phalcon tutorial project that is actually on github already. You can find it here.

Most of the code will be the same, with the exception of where the files are placed and some paths in the index.php file.

Lets start with the index.php file. On github it’s inside the public folder. Take that file and place it inside your domains /public folder as well. Replace the contents of the file with the following (change database info to match your server obviously, or comment the whole block out and you can enable it afterwards).

As you can see by the code above, we’re going to be storing the /app folder from github inside our private folder. This is so none of the app code is publicly accessible. Go ahead and copy the whole folder from github there. You can also download the schema and create a new database and import the schema as well.

When the app folder and the index.php are both in their proper places, we are ready to edit the nginx vhost file for the domain. /etc/nginx/sites-available/[domain]

Replace the contents of your vhost file with the following:

This should be all you need to get your Phalcon project loading via nginx. Restart nginx and php5-fpm for good measure.

Load the domain in your browser and you should see a page that has “Hello” on it with a link to a form that you can fill out and submit. If you configured your database and kept the db code in the index.php you should then get a row inserted into your database table. You can verify that command line if you like!

Git (optional)

If you are going to put this code into a Git repository such as bitbucket or github, you can easily accomplish that by creating somewhere new for the git repo to live (I chose to make a directory at ~/domains/[domain]/repo to house it. Move both your public and private folders into that folder after you init an empty git repo. Then symlink your old public and private folder locations to the /repo/public and /repo/private locations. Now you can edit and commit your code straight to your git repo and your old folders will utilize it the same as before.

Posted in Server Admin, Web Application Development Tagged with: , , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*