Install CakePHP2 on Codio

I only just discovered Codio yesterday! How come nobody ever told me about this? If you haven’t tried it yet and you are a keen programmer you should try it out. Chances are though you here because you are trying to get CakePHP2 working.

Well I’ve put in the hard work for you so just follow the steps below to get it working.

Step 1 – Create Project

  1. Create a new project.
  2. Give it a name. I named mine CakePHP2 but you can call it what you want.
  3. Select the “Template” tab.
  4. Choose “Empty project” from drop down list.
  5. Click Create

Sit back while your virtual machine and programming area is created for you. Step one is done.

Step 2 – Install Apache2, MySQL and PHP with PHP Modules

Your new project should launch with a tab called “Backend”, this is just a terminal you can use to run commands. If for some reason it’s not showing just go to Tools > Terminal. Then run the following command to install Apache2, MySQL and PHP with PHP Modules.

You will notice a few important things are installed

  1. Apache2 – Webserver
  2. MySQL – Database Server
  3. PHP5 – Version 5.5.15 (at the time of writing)
  4. Composer – PHP Package Manager
  5. PDO – Required for CakePHP database connection

After installation you are given some important information about where to find things later such as the php.ini and httpd.conf files etc.

You might also be wondering what “parts” is? It’s the codio command for doing a variety of things such as package installation and starting or stopping services such as Apache2. For example “parts search php” lets you search PHP packages that you can install. Lets do that now by installing PHP My Admin, we will need it later.

for good measure let’s restart Apache

Now you should be able to go to the last Menu option on the right and select “Box URL”. Then type /phpmyadmin on the end of the URL. You should now see the PHP My Admin login page for MySQL.

Before we can login to PHP My Admin we need to add a password to the default “root” user of MySQL. Let’s do that with the following command. Change “newpassword” to the password you want. You may need to start MySQL first.

Now that you have added a password to your “root” MySQL account you can go to the “Box URL” and then access /phpmyadmin. Then login with the following

  1. User: root
  2. Password: newpassword

Now that you are logged in to PHP MyAdmin go ahead and create a database for our CakePHP installation. I created a database called: cakephp but you can create and name as many as you like. You can also create database users however remember to GRANT access to these newly created users.

Step 3 – Install CakePHP2 with Composer

We now can install CakePHP. The environment is ready and we have a database ready to use with root/newpassword. First make sure you are outside of the “workspace” folder. In the terminal you can type the “pwd” (present working directory) and it will show you where you are. If you have followed the guide so far then you should be by default be inside the workspace directory however we want to move up a directory to the /home/codio/ directory.  To move back directory you can type “cd ..”. So once you sure you’re inside the “codio” directory type the following.

You may get an error saying that composer needs an update. That’s easy to fix with the following command line. Even with the error CakePHP should have successfully downloaded. You can check by using “ls” to list the items in the folder. You will need to first “cd workspace/” to see the downloaded CakePHP files.

After all this you should now be able to select “Box URL” and see a working copy of CakePHP. You will however notice a few errors. Lets fix those errors now.

Step 4 – Fix CakePHP Errors and Tidy Up

Since we are getting good with composer lets add the official CakePHP Debug Kit so that error goes away.

Next open app/Config/bootstrap.php and add the following

Lets now fix the WARNING: strtotime() error. This is an easy one. Open app/Config/core.php and uncomment the following line.

While we have the core.php file open lets change the Security.salt and Security.cipherSeed values. That gets rid of two more errors.

Last but not least let’s now connect our database. First you will need to create a new file app/Config/database.php. You can copy and paste the code from app/Config/database.php.default. Once you have done that edit the following code with your database user and password.

Make sure you edit the $default datasource and NOT the $test otherwise you will not see any changes.

Installation Finished

Give yourself a pat on the back, that wasn’t to hard was it. I hope that this guide gives you an idea of the process used for installing various packages. With the power of composer the world is your limit. You should be able to set up any PHP package available to you. Once CakePHP3 goes stable then you’ll be ready to install that as well!

Happy app building.


Tags: , ,

No comments yet.

Leave a Reply