How to Install CakePHP?
Are you in love with the development of websites with PHP (an acronym for hypertext preprocessor), then a web development framework is waiting to make your life easy and now you can lay emphasis at your business logic rather than messing around with setting up all architectural logistics from scratch?
- CakePHP is that sound framework, likely to offer you more than enough, just you must do is to incorporate PHP version 7.3 favorably ( or at least PHP 5.6.0 ).
- Are you juggling up with performance issues of your existing site and looking for something which could fix the stuff right up there for you, then CakePHP carries all those characteristics and can make your web application development faster, not excessively coded i.e. no complicated XML or YAML files, just you need to set up your database and you are done.
- While developing applications the prime objective is to keep it secure along with functional requirements, CakePHP has built-in tools for input data validation, CSRF tokens are there to keep track of every request and response ( keeping them unique and less vulnerable to hacking attacks). This framework also has features like SQL injection prevention (thereby keeping your database safe) and XSS prevention (cross-site-scripting).
Pre-requisites Of CakePHP
Let’s describe certain pre-requisites which are to be satisfied to install CakePHP.
- HTTP Server ( Apache, Nginx or Microsoft IIS)
- PHP 7.3
- mbstring PHP extension
- intl PHP extension ( if using XAMPP, intl extension shall be included but make sure to uncomment extension = php_intl.dll in Php.ini and restart the XAMPP server through control panel, in case you are using WAMP, the intl extension is activated by default, just you have to do is to go to php folder and copy all files synonymous to icu*.dll and paste them to apache bin directory, then restart the services ).
- SimpleXML PHP extension
- PDO PHP extension
Any databases among given list shall be installed in your machine :
- MySQL ( v5.5.3 or greater )
- MariaDB (v 5.5 or greater)
- PostgreSQL
- SQLite3
- Microsoft SQL server ( >= version 2008)
Steps to Install CakePHP
Now the steps which are required to install CakePHP are described as follows:
Again you are reminded to likely carry PHP version greater than 5.6 ( preferably 7.3), you can check that by running command php -v
Composer Installation
This is a tool used for dependency management
Step 1: Go to https://github.com/composer/windows-setup/releases/ for windows installation, the windows installer shall have a glance at the readme.md file present at this GIT repository
4.5 (5,464 ratings)
View Course
Step 2: The mac/ Linux users can run the scripts provided at https://getcomposer.org/download/ and then execute the given command:
mv composer.phar /usr/local/bin/composer
Step 3: After the successful installation, you will get the response image as attached below :
So you are done with the installation part and now we can head with the project created using the CakePHP
Create a Project
Use composer’s command named as “composer create-project -prefer-dist CakePHP/app custom_application_name”
Once you do this, CakePHP will start the application structure download.
You need to make sure that the directories named as logs, tmp and their subdirectories are permitted to be written by CakePHP web server user.
Development Server
Open CakePHP’s console for running PHP’s built-in web server and you can access the application at http://host:port. From the app directory, execute bin/cake server
In case there appear any conflicts with localhost or port then you can direct CakePHP to run a web server on a specific host or port, you can use following arguments to do that:
bin/cake server -H 192.168.13.37 -p 5673
Production
Production installation is also a way to setup/install CakePHP, it makes entire domain to act as single CakePHP application.
Developers using Apache should set the DocumentRoot directive for the domain to:
DocumentRoot /cake_install/webroot
Configurations to Install CakePHP
Few database configurations are required to be done here and few optional configurations too.
- Configurations are installed in the php/ini files and when the application is bootstrapped these files are loaded. One configuration file is by default incorporated in the CakePHP, you just need to add additional config files. Cake\Core\Configure is used for global configuration
- Load all of your configuration files (if they are multiple) in php ( you should have created those in config/ directory.
- Debug – It changes the CakePHP debugging output, if production mode = true then warnings and errors are shown else if it is set to false then hopefully, no errors and warning.
- Add.namespace – This is default namespace, in case you need to make the same change in the composer.json file to avoid errors.
- App.baseURL – Its presence enables Apache’s mod_rewrite with CakePHP, in case you don’t want to use this then uncomment this line and remove .htaccess files too.
- App.base – App resides in this base directory, if it is turned false then it is autodetected else one shall ensure that the string starts with / ( doesn’t end with / ).
- App.webroot – It is a web root directory
- App.wwwRoot – It is a file path to webroot.
- App.fullBaseUrl – Represents the absolute URL. By default, this is generated using $_SERVER environment
- App.imageBaseUrl – Web path to public images directory placed in the webroot.
- App.cssBaseUrl – Web path to CSS directory placed in the webroot.
- App.jsBaseUrl – Web path to js directory placed in webroot.
- App.paths – Includes the path configuration for non-class based resources, templates, plugins, locale subkeys are supported.
- Security.salt – Used for hashing, this value further which is used as HMAC salt for encryption purpose.
- Asset.timestamp – Asset URLs have a suffix containing the last modified timestamp for the particular file in the picture. It can take true, false and a string ‘force’ value, the false value stops the appending of timestamp, true appends the timestamp when debug is true and the ‘force’ argument makes compulsive to append the timestamp.
- Asset.cacheTime – This determines the HTTP header’s cache-control and expires time for assets. The default value is 1 day.
In case you need to use a CDN then App. imageBaseUrl, App.jsBaseUrl, App.cssBaseUrl shall be updated to point to CDN URI.
Recommended Articles
This has been a guide to Install CakePHP. Here we have discussed how to install CakePHP with pre-requisites and configurations respectively. You may also look at the following articles to learn more –