CakePHP is simple and easy to install. The minimum requirements are a web server
and a copy of CakePHP, that’s it! While this chapter focuses primarily on
setting up on Apache (because it’s simple to install and setup), CakePHP will
run on a variety of web servers such as nginx, LightHTTPD, or Microsoft IIS.

HTTP Server. For example: Apache. Having mod_rewrite is preferred, but
by no means required.

PHP 5.6.0 or greater (including PHP 7.1).

mbstring PHP extension

intl PHP extension

simplexml PHP extension

Note

In both XAMPP and WAMP, the mbstring extension is working by default.

In XAMPP, intl extension is included but you have to uncomment
extension=php_intl.dll in php.ini and restart the server through
the XAMPP Control Panel.

In WAMP, the intl extension is “activated” by default but not working.
To make it work you have to go to php folder (by default)
C:\wamp\bin\php\php{version}, copy all the files that looks like
icu*.dll and paste them into the apache bin directory
C:\wamp\bin\apache\apache{version}\bin. Then restart all services
and it should be OK.

While a database engine isn’t required, we imagine that most applications will
utilize one. CakePHP supports a variety of database storage engines:

MySQL (5.1.10 or greater)

PostgreSQL

Microsoft SQL Server (2008 or higher)

SQLite 3

Note

All built-in drivers require PDO. You should make sure you have the correct
PDO extensions installed.

Once Composer finishes downloading the application skeleton and the core CakePHP
library, you should have a functioning CakePHP application installed via
Composer. Be sure to keep the composer.json and composer.lock files with the
rest of your source code.

You can now visit the path to where you installed your CakePHP application and
see the default home page. To change the content of this page, edit
src/Template/Pages/home.ctp.

Although composer is the recommended installation method, there are
pre-installed downloads available on
Github.
Those downloads contain the app skeleton with all vendor packages installed.
Also it includes the composer.phar so you have everything you need for
further use.

Each time you run phpcomposer.pharupdate you will receive patch
releases for this minor version. You can instead change this to ^3.5 to
also receive the latest stable minor releases of the 3.x branch.

If you want to stay up to date with the latest unreleased changes in CakePHP,
designate dev-master as the package version in your application’s
composer.json:

"require":{"cakephp/cakephp":"dev-master"}

Be aware that this is not recommended, as your application can break when the next major
version is released. Additionally, composer does not cache development
branches, so it slows down consecutive composer installs/updates.

Another quick way to install CakePHP is Oven.
It is a simple PHP script which checks the necessary system requirements,
installs the CakePHP application skeleton, and sets up the development environment.

After the installation completes, your CakePHP application is ready to go!

Note

IMPORTANT: This is not a deployment script. It is aimed to help developers install
CakePHP for the first time and set up a development environment quickly. Production
environments should consider several other factors, like file permissions,
virtualhost configuration, etc.

CakePHP uses the tmp directory for a number of different operations.
Model descriptions, cached views, and session information are a few
examples. The logs directory is used to write log files by the default
FileLog engine.

As such, make sure the directories logs, tmp and all its subdirectories
in your CakePHP installation are writable by the web server user. Composer’s
installation process makes tmp and its subfolders globally writeable to get
things up and running quickly but you can update the permissions for better
security and keep them writable only for the web server user.

One common issue is that logs and tmp directories and subdirectories
must be writable both by the web server and the command line user. On a UNIX
system, if your web server user is different from your command line user, you
can run the following commands from your application directory just once in your
project to ensure that permissions will be setup properly:

In order to use the CakePHP console tools, you need to ensure that
bin/cake file is executable. On *nix or macOS, you can
execute:

chmod +x bin/cake

On Windows, the .bat file should be executable already. If you are using
a Vagrant, or any other virtualized environment, any shared directories need to
be shared with execute permissions (Please refer to your virtualized
environment’s documentation on how to do this).

If, for whatever reason, you cannot change the permissions of the bin/cake
file, you can run the CakePHP console with:

A development installation is the fastest way to setup CakePHP. In this
example, we use CakePHP’s console to run PHP’s built-in web server which
will make your application available at http://host:port. From the app
directory, execute:

bin/cake server

By default, without any arguments provided, this will serve your application at
http://localhost:8765/.

If there is conflict with localhost or port 8765, you can tell
the CakePHP console to run the web server on a specific host and/or port
utilizing the following arguments:

bin/cake server -H 192.168.13.37 -p 5673

This will serve your application at http://192.168.13.37:5673/.

That’s it! Your CakePHP application is up and running without having to
configure a web server.

Note

Try bin/cakeserver-H0.0.0.0 if the server is unreachable from other hosts.

Warning

The development server should never be used in a production environment.
It is only intended as a basic development server.

If you’d prefer to use a real web server, you should be able to move your CakePHP
install (including the hidden files) inside your web server’s document root. You
should then be able to point your web-browser at the directory you moved the
files into and see your application in action.

A production installation is a more flexible way to setup CakePHP. Using this
method allows an entire domain to act as a single CakePHP application. This
example will help you install CakePHP anywhere on your filesystem and make it
available at http://www.example.com. Note that this installation may require the
rights to change the DocumentRoot on Apache webservers.

After installing your application using one of the methods above into the
directory of your choosing - we’ll assume you chose /cake_install - your
production setup will look like this on the file system:

Alright, let’s see CakePHP in action. Depending on which setup you used, you
should point your browser to http://example.com/ or http://localhost:8765/. At
this point, you’ll be presented with CakePHP’s default home, and a message that
tells you the status of your current database connection.

Make sure that an .htaccess override is allowed and that AllowOverride is set
to All for the correct DocumentRoot. You should see something similar to:

# Each directory to which Apache has access can be configured with respect# to which services and features are allowed and/or disabled in that# directory (and its subdirectories).## First, we configure the "default" to be a very restrictive set of# features.<Directory/>Options FollowSymLinks
AllowOverrideAll# Order deny,allow# Deny from all</Directory>

Make sure you are loading mod_rewrite correctly. You should see something
like:

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

In many systems these will be commented out by default, so you may just need
to remove the leading # symbols.

After you make changes, restart Apache to make sure the settings are active.

Verify that your .htaccess files are actually in the right directories. Some
operating systems treat files that start with ‘.’ as hidden and therefore
won’t copy them.

Make sure your copy of CakePHP comes from the downloads section of the site
or our Git repository, and has been unpacked correctly, by checking for
.htaccess files.

CakePHP app directory (will be copied to the top directory of your
application by bake):

If your CakePHP site still has problems with mod_rewrite, you might want to
try modifying settings for Virtual Hosts. On Ubuntu, edit the file
/etc/apache2/sites-available/default (location is
distribution-dependent). In this file, ensure that AllowOverrideNone is
changed to AllowOverrideAll, so you have:

On macOS, another solution is to use the tool
virtualhostx to make a Virtual
Host to point to your folder.

For many hosting services (GoDaddy, 1and1), your web server is being
served from a user directory that already uses mod_rewrite. If you are
installing CakePHP into a user directory
(http://example.com/~username/cakephp/), or any other URL structure that
already utilizes mod_rewrite, you’ll need to add RewriteBase statements to
the .htaccess files CakePHP uses (.htaccess, webroot/.htaccess).

This can be added to the same section with the RewriteEngine directive, so
for example, your webroot .htaccess file would look like:

nginx does not make use of .htaccess files like Apache, so it is necessary to
create those rewritten URLs in the site-available configuration. This is usually
found in /etc/nginx/sites-available/your_virtual_host_conf_file. Depending
on your setup, you will have to modify this, but at the very least, you will
need PHP running as a FastCGI instance.
The following configuration redirects the request to webroot/index.php:

Recent configurations of PHP-FPM are set to listen to the unix php-fpm
socket instead of TCP port 9000 on address 127.0.0.1. If you get 502 bad
gateway errors from the above configuration, try update fastcgi_pass to
use the unix socket path (eg: fastcgi_pass
unix:/var/run/php/php7.1-fpm.sock;) instead of the TCP port.

IIS7 does not natively support .htaccess files. While there are
add-ons that can add this support, you can also import htaccess
rules into IIS to use CakePHP’s native rewrites. To do this, follow
these steps:

If you don’t want or can’t get mod_rewrite (or some other compatible module)
running on your server, you will need to use CakePHP’s built in pretty URLs.
In config/app.php, uncomment the line that looks like:

'App'=>[// ...// 'baseUrl' => env('SCRIPT_NAME'),]

Also remove these .htaccess files:

/.htaccesswebroot/.htaccess

This will make your URLs look like
www.example.com/index.php/controllername/actionname/param rather than
www.example.com/controllername/actionname/param.