How to create a phalcon application inside an ispconfig webspace

How to create a Phalcon application inside an ISPConfig webspace.

In this tutorial, I will explain how to create a website using phalconphp. Phalcon is a web framework implemented as a C extension offering high performance, low resource consumption. Phalcon ships as a module that is compiled and loaded inside the webserver. In this example, I will be loading it on a nginx webserver, it is setup to be managed by ISPConfig. It uses php5-fpm ( if you need a tutorial on how to set that up, head over to https://www.howtoforge.com/perfect-server-debian-wheezy-nginx-bind-dovecot-ispconfig-3 ).

 

1.) Compile Phalcon extension and load it in PHP.

installing dependencies for compilation:

Code:
sudo apt-get install php5-dev libpcre3-dev gcc make

compilation:

Code:
git clone git://github.com/phalcon/cphalcon.git

cd cphalcon/build

sudo ./install

load the module within php5-fpm:

Code:
echo "extension=phalcon.so" > /etc/php5/fpm/conf.d/20-phalcon.ini

Finally, restart nginx and php5-fpm.

Code:
service nginx restart && service nginx restart

 

2.) Test it.

Create a file called phpinfo.php in your webroot with the contents:

Code:
<?php phpinfo(); ?>

Now, access the site via http://yourserver/phpinfo.php and look for Phalcon. If the module was loaded properly, you should see something similar to:

test if phalcon module got loaded properly

test if phalcon module got loaded properly

3.) Nginx re-write rules.

For Phalcon to turn the URLs into nicely readable URLs /controller/action/param1/param2 etc, you will have to make sure the webserver has the proper rewrite rules loaded. since we installed the website inside an ispconfig webspace, you can just head to the “options” tab in the “website settings” and create a nginx directive there:

nginx rules phalcon

nginx rules phalcon

4.) A bit about ISPConfig’s folder structure:

When you create a website in ISPConfig, it will create a folder in /var/www/clients/clientX/webY ( X being the client ID, Y being the website ID). After the folder has been created, it will create a symlink that links /var/www/yourwebsite.com to /var/www/clients/clientX/webY. Inside the webY folder it creates two folders, web and private, so we’ll end up with the following structure for the first website setup in ISPConfig:

/var/www/clients/client1/web1
/var/www/clients/client1/web1/web
/var/www/clients/client1/web1/private 
/var/www/yourwebsite.com/ ( softlink to /var/www/clients/client1/web1 )

So why a web, AND a private folder inside there?

/var/www/clients/client1/web1/web will be the public web-root of yourwebsite.com, so it can be accessed by everybody. The /private folder on the other hand, is outside the public area. Meaning, if you have files that should not be accessible by everybody like your template files or your controllers, etc, put them inside /private instead of /web.

 

You can see a project that better explains this structure on https://github.com/loeken/phalcon-internetz.me

 

5.) Setup test project.

5.1.) Start by downloading the files from github to your computer using git:

Code:
git clone https://github.com/loeken/phalcon-internetz.me

5.2.) Create a Database and a Database User on your mysql database

5.3.) Enter the information to this database in the database section of the config.ini

5.4.) Import the database schema.

Code:
mysql -u <dbusername> -h <databaseserver> -p <databasename>

mysql> source /path/to/db1.sql

5.5.) You should now be able to access the website, perform login / logout action etc.

 

 

No Responses

Leave a Reply

Your email address will not be published.

Powered by themekiller.com