How to install cakePHP on Ubuntu Server running VestaCP

By | December 16, 2014

CakePHP is a free, open-source, rapid development framework for PHP. It’s a foundational structure for programmers to create web applications. Our primary goal is to enable you to work in a structured and rapid manner–without loss of flexibility. CakePHP makes building web applications simpler, faster and require less code.


CakePHP is simple and easy to install. The minimum requirements are a web server and a copy of CakePHP, that’s it! CakePHP will run on a variety of web servers such as Apache2, Nginx, LightHTTPD, or Microsoft IIS.


•HTTP Server. For example: Apache. Having mod_rewrite is preferred, but by no means required.
•PHP 5.4.16 or greater.
•mbstring extension
•mcrypt extension
•intl extension

While a database engine isn’t required, we imagine that most applications will utilize one. CakePHP supports a variety of database storage engines:

•MySQL (5.1.10 or greater)
•Microsoft SQL Server (2008 or higher)
•SQLite 3

In this tutorial you will learn how to easily install and get started with CakePHP. For this guide it is assumed that you are already running your own server instance, a web server and have full root access to your server. This tutorial will use Ubuntu Server for the operating system and Apache for the webserver (+ PHP and MySQL).

Installing CakePHP on Ubuntu Server powered by Vesta Control Panel.

First, you’ll need to download and install the latest release of cakePHP if you haven’t done so already. Switch folder and create a new folder as follows:

root@gs2:~# cd /backup/
root@gs2:~# mkdir installs
root@gs2:~# cd installs/

If you have wget installed, it’s as easy as running the following:

root@gs2:/backup/installs# wget

Now that you’ve downloaded the file, you need to unzip it to extract the CakePHP application by running:

root@gs2:/backup/installs# unzip

You should get a new folder that contains all the CakePHP files called cakephp-2.5.7. Now go ahead and move all the content in this folder to the root directory of your VestaCP something more usable, like:

root@gs2:/backup/installs# mv cakephp-2.5.7/* /home/admin/web/default.domain/public_html/

Next up, let’s change the folder to our root directory, where we moved all CakePHP files to:

root@gs2:/backup/installs# cd /home/admin/web/default.domain/public_html/

We are now located into the root directory and when you run ls you should see all CakePHP files.


Next up, let’s adjust the permissions of the app/tmp folder of your application as CakePHP will need to use it quite a bit so it needs to be writable by the webserver run the following:

root@gs2:/home/admin/web/default.domain/public_html# chown -R root:www-data app/tmp
root@gs2:/home/admin/web/default.domain/public_html# chmod -R 775 app/tmp

URL Rewriting


While CakePHP is built to work with mod_rewrite out of the box–and usually does–we’ve noticed that a few users struggle with getting everything to play nicely on their systems. Here is what you might try to get it running correctly.

root@gs2:/home/admin/web/default.domain/public_html# apache2ctl -M

Now we need to go and make a few changes on CakePHP core.php file. This helps to improve security and to avoid warns popping up when you running your CakePHP application. Go ahead and Edit the core.php file located in the app/Config folder and run the following:

root@gs2:/home/admin/web/default.domain/public_html# vi app/Config/core.php

Find the following block and replace the longstring Security.salt and Security.cipherSeed:

* A random string used in security hashing methods.
 Configure::write('Security.salt', 'VOsTwxSCrZIWT6rhEKPZNxD6Bvog1Phomai40xMz');
* A random numeric string (digits only) used to encrypt/decrypt strings. 
 Configure::write('Security.cipherSeed', '598173280301592121433557250171');

The actual strings and numbers may differ in your case, but this is where you’ll have to change the values into something impossible to guess. Just make sure you only include numbers for the cipherSeed. You can use this website to automatically generate your random strings:

In my case, I adjusted the values for ‘Security.salt’ as follows: Generate 1 random strings 40 objects in length then click “Generate Random String”,


The numbers for ‘Security.cipherSeed’ as follows: Generate 1 random strings 30 objects in length – then click “Generate Random String”, what’s key in this part is that you need to remove all characters and leave only the numbers like: 0123456789

Save the file and exit.

Database connection

From the console of your Vesta Control Panel, go and create the database and database login details:

In my case I created the database called: admin_db and the database user called: admin_12

Next, let’s go ahead and configure CakePHP to use this database. First thing you need to do is make a copy of the database.php.default file located in the /app/Config/ folder and name it database.php.

root@gs2:/home/admin/web/default.domain/public_html# cp app/Config/database.php.default app/Config/database.php

Then open the file and locate the following block of code (change database to ‘admin_db’ and ‘login’ => ‘admin_12’, to your mysql login and password ‘WsMyyfzM32’) :

root@gs2:/home/admin/web/default.domain/public_html# vi app/Config/database.php
public $default = array(		
'datasource' => 'Database/Mysql',		
'persistent' => false,		
'host' => 'localhost',		
'login' => 'admin_12',		
'password' => 'WsMyyfzM32',		
'database' => 'admin_db',		
'prefix' => '',		
//'encoding' => 'utf8',

Now you need to make sure that your apache2 vhost for your CakePHP is configured correct, You should have something like:

root@gs2:~# vi /home/admin/conf/web/apache2.conf
DocumentRoot /home/admin/web/default.domain/public_html/app/webroot
ScriptAlias /cgi-bin/ /home/admin/web/default.domain/cgi-bin/
Alias /vstats/ /home/admin/web/default.domain/stats/ 
Alias /error/ /home/admin/web/default.domain/document_errors/    
#SuexecUserGroup admin admin    
CustomLog /var/log/apache2/domains/default.domain.bytes bytes  
CustomLog /var/log/apache2/domains/default.domain.log combined 
ErrorLog /var/log/apache2/domains/default.domain.error.log

           Options -Indexes +FollowSymLinks
           AllowOverride All
           Order allow,deny
           Allow from all

        AllowOverride All

        RMode config        
	RUidGid admin admin        
	RGroups www-data    
	AssignUserID admin admin    
IncludeOptional /home/admin/conf/web/apache2.default.domain.conf

We are almost done, You should run these two commands:

root@gs2:/home/admin/web/default.domain/public_html# sudo a2enmod rewrite
root@gs2:/home/admin/web/default.domain/public_html# sudo service apache2 restart

If all is followed right to the ‘T’ and configured correctly, you should now find your CakePHP application accessible at your website, in my case:

Alright, now your CakePHP application should be running smoothly and ready for baking.