This blog is about C++, CakePHP, Linux, PEAR, PHP, Pyrus, Apache, and MySQL and related topics.

Thursday, December 18, 2008

How to install CakePHP on Linux Ubuntu 8.10 (Step 3.3)

In this blog post I am going to show how I installed CakePHP on my Ubuntu Linux computer. CakePHP does have instructions on how to do this but even with the instructions there are several points where you can run into problems, so I'm writing this to help anyone with a similar setup and also to remember what I did!

I intend this to be a companion to the installation guide that can be accessed here (cake guide).

My setup:
(step 3.1)

Linux Ubuntu 8.10
Apache 2.2.9-7ubuntu3
PHP 5.2.6-2ubuntu4
MySQL 5.0.67-0ubuntu6

(To keep things simple I will not list all the modules installed)

mod_rewrite

To enable mod_rewrite I typed the following in the Terminal:

sudo a2enmod rewrite


Get CakePHP: (Step 3.2.1)

Getting CakePHP was easy I just went to the main website and downloaded the latest version which at the time of this article is version 1.2.0.7692 RC3.

There are four different files to choose from, I chose cake-1.2.0.7692-rc3.tar.gz

I downloaded the tar.gz file to my desktop

Installation Options: (Step 3.3)

There are three main installation types, Development, Production, and Advanced. Development is the easiest option, but is less secure. Production allows an entire domain to act as a single CakePHP application, is very secure, and has clean URL's. The Advanced option is more complicated and requires more configuration.

I decided that Production is the way to go.

Switching to the Terminal I created a cake_install directory as follows:

cd /var
sudo mkdir cake_install

Next, I went to the desktop and extracted the files there (right click). Then using the Terminal I copied the contents into the cake_install directory like this:

cd /home/jon/Desktop/cake_1.2.0.7692-rc3
sudo cp -r * /var/cake_install

Now my directory structure looks like this:

/var/cake_install/app/
/var/cake_install/cake/
/var/cake_install/docs/
/var/cake_install/vendors/
/var/cake_install/index.php

/app/tmp permissions: (Step 3.2.2)

Once I got here I went back to step 3.2.2 to make the /app/tmp folder writable by the web server user.

In the Terminal now, I navigated to the app folder to verify the current permissions:

cd /var/cake_install/app/
ls -ld tmp

and this is the output:

drwxr-xr-x 6 www-data www-data 4096 2008-12-18 11:30 tmp

If you see root instead of www-data then you need to type this command in the terminal:

sudo chown www-data:www-data /var/cake_install/app/tmp


Almost done. The next step was to change the DocumentRoot to /var/cake_install/app/webroot

(how to create a new site in Apache is described here)

In the Terminal I typed:

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite
sudo nano /etc/apache2/sites-available/mysite

I changed the DocumentRoot to point to: /var/cake_install/app/webroot

Then I saved the file. (like this: Ctrl-X to exit, Y to save, then enter to confirm address of file.)

Then I had to deactivate the old site and activate the new one.

In the Terminal I typed:

sudo a2dissite default && sudo a2ensite mysite

then to reload Apache so the new configuration will be in effect, I typed:

/etc/init.d/apache2 reload

To verify it is working correctly you type www.example.com in your browser where example is your domain. If you are running as localhost then type http://localhost/.

If your web server is configured correctly, you should now find your Cake application accessible there.

If there are any errors in your installation they will show up on this screen.

I had the following errors to fix before I could consider the job complete:

Warning 512: /var/cake_install/app/tmp/cache/ is not writable [CORE/cake/libs/cache/file.php, line 262]

Notice 1024: Please change the value of 'Security.salt' in app/config/core.php to a salt value specific to your application [CORE/cake/libs/debugger.php, line 541]

Your database configuration file is NOT present.
Rename config/database.php.default to config/database.php


I found the solution to Warning 512 , on SitePoint's forums which references a post on the CakePHP Google Group. To fix this you go to the app directory like this:

cd /var/cake_install/app/
then as administrator you fix the permissions like this:
sudo chmod -R 0777 tmp

I reloaded the browser and the error is now gone.

Next to fix Notice 1024 I found this solution.


The solution says to open the core.php file at app/config and change one digit in the salt. So first I navigated to the right folder:

cd /var/cake_install/app/config

Then to change the permissions so that I could edit the file I did this:

sudo chown jon:jon /var/cake_install/app/config/core.php

To open and edit the file I typed:

gedit core.php

I scrolled down to Security.salt. Then I changed one character in the salt, saved, then closed the file. I reloaded the browser. Problem fixed!

Two down one to go.


Now my last little problem is this one:

Your database configuration file is NOT present.
Rename config/database.php.default to config/database.php

I used the Terminal to rename the file. For info, type man mv in the Terminal or refer to this.

sudo mv /var/cake_install/app/config/database.php.default /var/cake_install/app/config/database.php

Problem fixed!

A new message pops up that "Cake is NOT able to connect to database" and I'll deal with that seperately, I'm just glad to make it this far.





7 comments:

  1. Saved my life. Tahnks

    ReplyDelete
  2. This is a great process doc. thank you for it. fills in the gaps in the manual.

    ReplyDelete
  3. The 'chown' to grant permissions on the tmp directory should be recursive '-R'

    ReplyDelete
  4. Damn you are so good. Thanks

    ReplyDelete
  5. great fix, thanx a lot!!

    ReplyDelete

Followers