Recapping what’s been done so far;
- Downloaded latest CakePHP v1.2.0.6311
- Unzipped into folder as \htdocs\cake12
- Baked project files into into my project folder \htdocs\aa01
- Removed all .htaccess files
When the basic files were baked at the command prompt (see last post) , a number of things were actioned inside your project files. These are
- Created a Welcome page
- Created a new hash key
- Altered the path to show where the core Cake files reside
Connecting to the database
Get into MySQL create a user with Select, Insert, Delete, Read, Create and Drop rights. Create a schema called ‘aa01′, matching the project name. Give the user rights to the newly created schema. I use a user called ‘fred’, password of ’shhh’ for all local projects whilst testing – makes it real easy.
Next, the project needs to link to the MySQL database, so what we do is run the bake project comand line again. Exactly the same command string as previously. On the second pass, the console looks for the database. Enter the schema name and the user name and password. Cake copies the file \aa01\config\database.php.default, loads your newly entered details and saves it as \aa01\config\database.php.
Opening the project
At this stage we should be able to open the Cake application and see whether it all works. The URL to use points at my separate project folder \htdocs\aa01 as below
http://localhost/aa01/index.php
When I try this URL, the Welcome screen from within the depths of the project at \aa01\views\pages\home.ctp is generated and it displays a series of messages, some of which might need slight fixups. Below are notes on each of these possible issues, noting that none or some may require a fixup in your project.
Issue 1 – Cake reports it is unable to locate the core files
The project file detailing where all the folders and files are located is \aa01\webroot\index.php. The first bake pass modified this file and loaded the path to the core Cake build files at \htdocs\cake12 into a variable called CAKE_CORE_INCLUDE_PATH. There are two other variables that I manually modify in this file – they are ROOT and APP_DIR. An excerpt from the modified index.php is below, starting at Line 35.
/**
* These defines should only be edited if you have cake installed in
* a directory layout other than the way it is distributed.
* Each define has a commented line of code that explains what you would change.
*/
if (!defined('ROOT')) {
//define('ROOT', 'FULL PATH TO DIRECTORY
WHERE APP DIRECTORY IS LOCATED.
DO NOT ADD A TRAILING DIRECTORY SEPARATOR');
//You should also use the DS define to separate your directories
//define('ROOT', dirname(dirname(dirname(__FILE__))));
define('ROOT', 'c:\apache224\htdocs');
}
if (!defined('APP_DIR')) {
//define('APP_DIR', 'DIRECTORY NAME OF APPLICATION');
//define('APP_DIR', basename(dirname(dirname(__FILE__))));
define('APP_DIR', 'aa01');
}
/**
* This only needs to be changed if the cake installed libs are located
* outside of the distributed directory structure.
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
//define ('CAKE_CORE_INCLUDE_PATH', 'FULL PATH TO DIRECTORY
WHERE CAKE CORE IS INSTALLED.
DO NOT ADD A TRAILING DIRECTORY SEPARATOR');
//You should also use the DS define to separate your directories
//define('CAKE_CORE_INCLUDE_PATH', ROOT);
define('CAKE_CORE_INCLUDE_PATH', 'c:\apache224\htdocs\cake12');
}
On completion of the above changes/additions, reload the URL and see that the various messages re the lack of the core files have gone.
Issue 2 – A message re Security.salt shows as below.
Notice (1024): Please change the value of 'Security.salt'
in aa01/config/core.php to a salt value specific to your application
[CORE\cake\libs\debugger.php, line 535]
The security salt is used for generating hashes, particularly for password security. The Cake build has a default salt which should be changed otherwise there is the potential that another site with the same build and thus the same default salt could be well on the way to crack your passwords. Note that the first Cake bake pass should have modified this salt, but you can manually change it. Sometimes I manually generate a project salt based on the project name and build version so that I can check it during subsequent processing.
Change one or more characters of the salt or generate yourself a completely new salt. Use something like echo sha1(‘my own security salt string’) and copy the 40 character hashed string. The security.salt is stored in \htdocs\aa01\config\core.php at around line 153.
Once you’ve done that, reload the URL and see that the message re the salt has gone.
Issue 3 – Screen is a plain vanilla webpage with browser default colours of say black text and a few coloured hyperlinks. Got a fix for that too – the .htaccess files I removed apparently cause that because Cake can no longer find its CSS file at \htdocs\aa01\app\webroot\css. The message is below from around line 48 of \htdocs\aa01\congfig\core.php
/**
* To configure CakePHP *not* to use mod_rewrite and to
* use CakePHP pretty URLs, remove these .htaccess
* files:
*
* /.htaccess
* /app/.htaccess
* /app/webroot/.htaccess
*
* And uncomment the App.baseUrl below:
*/
//Configure::write('App.baseUrl', env('SCRIPT_NAME'));
What we do here is uncomment the line at the bottom, reload the URL. All should now be in glorious colour. By uncommenting line 59, Cake now has a base URL for the application, thus can find and access the CSS file, dredging up a few garish colours. Green is an OK message, yellow can be ignored and red requires fixing.
Issue 4 – There is a message onscreen about being unable to find a configuration file called database.php. Message as below;
Your database configuration file is NOT present.
Copy \htdocs\aa01\config\database.php.default to database.php. Modify this file (database.php) filling it with the detail needed to connect to the database, in our case MySQL. The second Cake pass should have done this (and Issue 5) operation already. Reload the URL and Issue 5 now appears.
Issue 5 – Cake cannot connect to the database. The database configuration file renamed at Issue 4 contains two arrays detailing how to connect to a specific database. The message displayed is below, having tried to connect and login to a MySQL database using the default array details. Note that the referenced code lines where the errors occur have nothing to do with what has to be modified to fix the issue. The joys of debugging.
Your database configuration file is present.
Warning (2): mysql_connect() [function.mysql-connect]:
Access denied for user 'user'@'localhost' (using password: YES)
[CORE\cake\libs\model\datasources\dbo\dbo_mysql.php, line 100]
Warning (2): mysql_select_db():
supplied argument is not a valid MySQL-Link resource
[CORE\cake\libs\model\datasources\dbo\dbo_mysql.php, line 105]
Cake is NOT able to connect to the database.
Set the details to suit your situation in the database configuration file at \htdocs\aa01\config\database.php.
For my local development MySQL database, in all projects, I use a standard user of ‘fred’, password of ’shhh’ and the database schema name matches the project name – in this case, a database schema name of ‘aa01′. Note that this Joe Public user ‘fred’ can only Select, Insert, Update and Delete within the MySQL database schema. No point in giving him elevated (more risk) rights he should never need to use, although initially I quite often add Create and Drop rights whilst I am sorting tables out. Create and Drop usually are removed before production.
Reload the URL and see that the screen report states that the database configuration file is present.
Issue 6 – Caching is turned on and using the File Engine.
Now I will readily admit that here I do not fully understand the implications, but I turn off all caching. When developing, I want every URL reload to serve up a new page loaded from the server, complete with any recent modifications I might have made. In a production server, caching might be good for overall speed, as some web pages may be stored locally and not have to be reloaded across the wire, be it via a network or the Internet.
To kill caching, back into \htdocs\aa01\app\config\core.php at line 75 and uncomment the line ‘Configure::write(‘Cache.disable’, true)’. Reload URL and see the message changes.
Summary
Note I have only addressed issues relating to my project in \htdocs\aa01. Similar issues still exist in the application (project) folder under the main build at \htdocs\cake12\app. I leave these alone, so it remains a clean master that could be used for a new project although I suspect when using Bake at the command line, these files are not used at all.
I have now
- Loaded the latest build of CakePHP, with the project in a separate folder.
- Told the project where specific Cake files are
- Set our own salt for hashing
- Turned off caching
- Connected to a MySQL database
Next I am off hopefully to create a few views.