In this post i am going to explain how to setup cakePHP latest version. If you are new to cakePHP then this post help you to setup cake in your local server. Later i am going post series of cakephp tutorial to cover some basic functionality.
Official Site: http://cakephp.org/
Requirements for cakephp v3
- PHP 5.5.9 or greater
- Mbstring PHP extension
- Xampp/Wamp latest version [i am using XAMPP V3.2.2 for this example.]
Step 1. Open XAMPP Control Panel start Apache and MySql. Now click on shell and type bellow command in your shell.
curl -s https://getcomposer.org/installer | php
and download & install Composer, a dependency management tool by running simple command on xampp shell i.e.
Step 2. After successful installation of composer, All we need to create new project by running command on shell i.e
php composer.phar create-project --prefer-dist cakephp/app mycake
I have named my project as mycake, Using the above command our project is created in htdocs folder and all dependencies required for project are downloaded automatically.
Step 3. After dependencies install we are asked to set folder permission. Just type ‘Y’ and press enter and give permission.
Now we have successfully installed cakephp v3 on xampp. Open download location where you install your CakePHP. In CakePHP V3 folder structure is different from older versions.
Setup Database connection in your cake
To connect our project with database go to \xampp\htdocs\mycake\config, Look for app.php inside this folder and add your connection in it as shown below
'Datasources' => [ 'default' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', /** * CakePHP will use the default DB port based on the driver selected * MySQL on MAMP uses port 8889, MAMP users will want to uncomment * the following line and set the port accordingly */ //'port' => 'non_standard_port_number', 'username' => 'root', 'password' => '', 'database' => 'mycake', 'encoding' => 'utf8', 'timezone' => 'UTC', 'flags' => , 'cacheMetadata' => true, 'log' => false, /** * Set identifier quoting to true if you are using reserved words or * special characters in your table or column names. Enabling this * setting will result in queries built using the Query Builder having * identifiers quoted when creating SQL. It should be noted that this * decreases performance because each query needs to be traversed and * manipulated before being executed. */ 'quoteIdentifiers' => false, /** * During development, if using MySQL < 5.6, uncommenting the * following line could boost the speed at which schema metadata is * fetched from the database. It can also be set directly with the * mysql configuration directive 'innodb_stats_on_metadata = 0' * which is the recommended value in production environments */ //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'], 'url' => env('DATABASE_URL', null), ], /** * The test connection is used during the test suite. */ 'test' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', //'port' => 'non_standard_port_number', 'username' => 'my_app', 'password' => 'secret', 'database' => 'test_myapp', 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => true, 'quoteIdentifiers' => false, 'log' => false, //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'], 'url' => env('DATABASE_TEST_URL', null), ], ],
After make change save file and open your browser and type your project URl: http://localhost/mycake . If cake is successfully installed and database connection is setup you see this screen.
CakePHP Folder Structure
After you successfully install CakePHP these are the files and folders you should see:
- bin :- this folder holds the Cake console executable.
- config :- this folder contain cake configuration file like Database connection, email config, Routes, bootstrapping etc.
- logs :- Contain logs file
- plugins :- Contain plugin for your project
- src :- Contain your application files, Main logic of your project, Model View Controller etc.
- tests :- in this folder where you put the test cases for your application.
- tmp :- Store temporary data.
- vendor :- folder is where CakePHP and other application dependencies will be installed. Don’t make any change inside this folder :-p
- webroot :- here you can place your CSS, JS, Images etc. All those thing which publicly access.
Hope this help you to setup your cake. Stay tune i am going to post some more useful topics on cakePHP.