Skip to main content

Install CakePHP 2.x in Ubuntu


Requirements:

  • HTTP Server. For example: Apache. mod_rewrite is preferred, but by no means required.
  • PHP 5.2.8 or greater.
  • Database Engine (MySQL (4 or greater), PostgreSQL, Microsoft SQL Server, SQLite)
Download CakePHP 2.x at their website: http://cakephp.org/

Extract your downloaded file.

Copy and paste the contents of the Cake archive in /var/www/cakephp

Make it writable, open your terminal and type:  

    sudo chmod 777 -R /var/www/cakephp

Create your database.

Goto /var/www/cakephp/app/Config/ and rename your database.php.default to database.php.

Open database.php, then just replace the values in the $default array with those that apply to your setup. . A sample completed configuration array might look something like the following:

<?php
public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'port' => '',
    'login' => 'DatabaseUsername',
    'password' => 'DatabasePassword',
    'database' => 'DatabaseName',
    'schema' => '',
    'prefix' => '',
    'encoding' => ''
);

The security salt is used for generating hashes. Change the default salt value by editing /app/Config/core.php line 187. It doesn’t much matter what the new value is, as long as it’s not easily guessed.

<?php
/**
 * A random string used in security hashing methods.
 */
Configure::write('Security.salt', 'tYp3Anythin5H3r3');

The cipher seed is used for encrypt/decrypt strings. Change the default seed value by editing /app/Config/core.php line 192. It doesn’t much matter what the new value is, as long as it’s not easily guessed.

<?php
/**
 * A random numeric string (digits only) used to encrypt/decrypt strings.
 */
Configure::write('Security.cipherSeed', '7485712659625147843639846751');

If your web server is configured correctly, you should now find your Cake application accessible at  http/localhost/cakephp/

If your CakePHP site still has problems with mod_rewrite you might want to try and modify settings for virtualhosts. If on ubuntu, edit the file /etc/apache2/sites-available/default (location is distribution dependent). In this file, ensure that AllowOverride None is changed to AllowOverride All, so you have:

<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /var/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>
 

Restart your apache.

   sudo service apache2 restart




Post a Comment

Popular posts from this blog

CakeAdminLTE is based on AdminLTE Theme for CakePHP 2.4+

CakeAdminLTE v.1.0 CakeAdminLTE is based on Twitter Bootstrap 3.0+ and AdminLTE Theme for CakePHP 2.4+


AdminLTE Dashboard and Control Panel Template  Responsive admin template Free & open source Built with Bootstrap 3 Easy to customize Quick StartDownload the .zip fileExtract the files into your CakePHP folderTo enable your theme add the following to your "app/Controller/AppController.php" class:public$theme="CakeAdminLTE"; IMPORTANT: If you would like to bake your app, please make sure you have enabled the theme before baking. DOWNLOAD: CakeAdminLTE

CakePHP: COUNT data and GROUP BY date

Goal: Count Tip Offs created per day for a month to use for graph
Problem: created field name is in datetime format: Y-m-d H:i:s
Solution: format SQL Query date: DATE_FORMAT(TipOff.created, '%Y-%m-%d')





Inside the function of controller
<?php$tipOffsMonthly=$this->TipOff->find('all', array('conditions'=>array('AND'=>array('TipOff.electric_cooperatives_id'=>AuthComponent::User('electric_cooperatives_id'), 'TipOff.created BETWEEN ? AND ?'=>array($first_day, $last_day))), 'fields'=>array("COUNT('created') as per_day", 'created'), 'group'=>array("DATE_FORMAT(TipOff.created, '%Y-%m-%d')") ));?>

CakePHP: Calling function from other controller

Import Controller of the function you want to use.

Once you imported  the controller you can call any function of this controller.

<?php//Import controller  App::import('Controller','SmsOutgoings');class ReportsController extends AppController {publicfunctionadd(){$message="Notification: New report submitted!";//Instantiation$SmsOutgoings=new SmsOutgoingsController;//Call a method from SmsOutgoingsControllerwith parameter$SmsOutgoings->notify_user($user_id,$message);}}?> Other way is by using the requestAction() function
<?phpclass ReportsController extends AppController {publicfunctionadd(){$message="Notification: New report submitted!";//Call a method from SmsOutgoingsController with parameter$this->requestAction('/sms_outgoings/notify_user',array($user_id,$message))