With the recent launch of CakePHP 3.0 we have begun our testing on both its flexibility and it’s performance as a PHP framework. We have extensively used CakePHP 2.x over numerous clients sites and for us, a big bonus was it’s simple install over any shared hosting.
With CakePHP 3.0 there comes some new approaches to the install. It requires Composer to compile all the files based on it’s location and links all the containing files where necessary.
We have managed to get a fresh install on some of our shared hosting packages and we will show you how:
- PHP 5.4.16 or greater.
- mbstring extension
- intl extension
There is no way around it. If your shared host does not have the above available, it is very unlikely that you will be able to successfully deploy your project. It must be noted that the PHP extension mod_rewrite is not necessary for CakePHP to function, but is a great recommendation.
FIRST THINGS FIRST:
Without the use of a self-managed server you will need to create the basis of the cake install on your local machine and tweak some files before uploading it to your shared hosting. To get a fresh install of CakePHP 3.0 you need to stage a local development server. I recommend using WAMP.
Install WAMP on your machine. In my case the default folder is:
Next you need to download Composer. Follow the steps to get Composer running on your machine, based on your operating system. For Unix/Linux & OSX OS’s its possible to initiate Composer either locally or globally. Determine which meets your requirements. Based off Windows OS we will assume that Composer is installed globally.
Composer attaches itself to your WAMP php.exe. e.g.
INSTALLING CAKEPHP 3.0:
Now that you have WAMP and Composer installed open up your command line or cmd.exe (run as adminstrator). Make sure your directory is set to your wamp localhost path. To set the directory enter in the following:
Now to intitate the download and install of the CakePHP files run this line:
composer create-project --prefer-dist -s dev cakephp/app app_name
“app_name” being the name of your project.
After the download is complete you should be able to navigate to your localhost directory and locate “app_name” with the skeleton CakePHP install.
If you point your browser to the project localhost/app_name/ you should see the brand new landing page.
TWEAKING CONFIG FILES FOR SHARED HOSTING:
We found simply uploading the skeleton to your shared hosting points obvious errors, unlike 2.x. We need to configure a few files by prefixing specific paths with the ROOT constant to get it behaving correctly.
The plugins.php file needs to have the Migrations, DebugKit & Bake paths prefixed:
$baseDir = dirname(dirname(__FILE__));
return array (
'Migrations' => ROOT . '/vendor/cakephp/migrations/',
'DebugKit' => ROOT . '/vendor/cakephp/debug_kit/',
'Bake' => ROOT . '/vendor/cakephp/bake/',
The app.php file needs to have the App Webroot path prefixed:
On line 42
'webroot' => ROOT . . 'webroot',
With this your CakePHP skeleton is ready for upload to you shared hosting, using your FTP client, transfer the files to your root directory (if you plan on using a different file structure you will need to update the paths to reflect it). Pointing your browser to the base of this directory should reveal the same welcome screen.
PS. There might be additional configuration regarding the setup for CakePHP on shared hosting, however these are the available issues we have dealt with so far. If you come across any other issues please notify us in the comments.