How To Install CakePHP Framework On Ubuntu 20.04

We can install CakePHP 4 framework on ubuntu 20.04. Let’s see, how to install the CakePHP framework on ubuntu. CakePHP framework is a popular PHP development framework that allows rapid apps development and faster delivery. you only need to set up the database and start writing the coding. so


  • You must have PHP Composer installed on your machine.
  • Database installed on ubuntu.
  • Apache installed on ubuntu.

Check Out: How To Install Jupyter Notebook On Ubuntu 20.04 / 19.10

How To Install CakePHP Framework On Ubuntu 20.04

We will configure and install CakePHP using the LEMP setup on ubuntu. you need to install a PHP Composer on ubuntu 20.04.  so

Install PHP Composer:

We’ve already installed on ubuntu 20.04 and you can run the following commands. so

sudo apt install php -y

Make a few changes in the /etc/php/7.4/apache2/php.ini file with the below lines and save the file. so

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
max_input_vars = 1500
date.timezone = Asia/Kolkata

Install the repository and update the system. so

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt upgrade -y

Download the PHP Composer installer using the below command.

php -r "copy('', 'composer-setup.php');"

Run to verify the script is corrupted or not. 

ubuntu@ubuntu:~$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Installer verified

Check Out: How To Configure Master Kubernetes With Worker Node On Linux

Install the Composer using the below command. 

ubuntu@ubuntu:~$ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Once it’s installed, we need to type “composer” in the terminal and you should be able to see the composer output. 


We’ve successfully installed the composer and you need to install Apache, PHP extension, and MySQL database. 

Install Apache, PHP Extension, and MySQL:

You can use the following command to install LEMP on ubuntu 20.04 / 19.10. 

sudo apt install php7.4 libapache2-mod-php7.4 php7.4-common php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-mysql php7.4-gd php7.4-imap php7.4-ldap php-cas php7.4-bcmath php7.4-xml php7.4-cli php7.4-zip php7.4-sqlite
sudo apt install apache2
sudo apt install mysql-server
sudo apt install php7.4-mysql php7.4-intl

Start and enable the apache service.

sudo systemctl start apache2 && sudo systemctl enable apache2

Once the above packages are installed. we have to create a database for CakePHP using the following commands. I’m using MySQL 8 version. 

mysql> create database cakephp;
Query OK, 1 row affected (0.02 sec)

mysql> create user 'cakephp'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.04 sec)

mysql> GRANT ALL PRIVILEGES ON cakephp.* TO 'cakephp'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Check the PHP version with php -v command. 

ubuntu@ubuntu:~$ php -v
PHP 7.4.9 (cli) (built: Aug 7 2020 14:30:01) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies

Check Out: How To Configure Simple Notification Service(SNS) On AWS Cloud

Install the CakePHP Framework on Ubuntu:

We’ve to create a directory to download the CakePHP framework. Use the below command. 

sudo mkdir /var/www/cakephp
cd /var/www/cakephp
sudo composer create-project --prefer-dist cakephp/app

Create a backup of the existing database file. 

cd /var/www/cakephp/app/config
sudo cp app_local.example.php app_local.example.php-back

Open the app_local.php configuration file and put the DB credentials. Save the file. 

* Connection information used by the ORM to connect
* to your application's datastores.
* See app.php for more configuration options.
     'Datasources' => [
          'default' => [
          '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' => 'cakephp',
         'password' => 'password',

         'database' => 'cakephp',
        * If not using the default 'public' schema with the PostgreSQL driver
        * set it here.
        //'schema' => 'myapp',

Once you have saved the file. we need to change the owner and permissions on the CakePHP folder using the following commands.

sudo chown -R www-data:www-data cakephp/
sudo chmod -R 755 cakephp/


Error 1: If you face any issue after running the below command like: “PHP Fatal error: You must enable the intl extension to use CakePHP. in /var/www/cakephp/app/config/requirements.php on line 31“, you need to enable the extension in the /etc/php/7.4/apache2/php.ini file.


Error 2: “PHP Warning: require(/var/www/cakephp/app/vendor/autoload.php): failed to open stream: No such file or directory in /var/www/cakephp/app/bin/cake.php

To solve the error 2, we need to run the below command.

ubuntu@ubuntu:/var/www/cakephp/app$ sudo composer dumpautoload
[sudo] password for ubuntu:
Do not run Composer as root/super user! See for details
Generating autoload files
Class Cake\Composer\Installer\PluginInstaller is not autoloadable, can not call post-autoload-dump script
Generated autoload files

Check Out: Learn Cat Commands With Examples On Linux

We will start the server using the below command. 

ubuntu@ubuntu:~$ cd /var/www/cakephp/app

ubuntu@ubuntu:/var/www/cakephp/app$ sudo bin/cake server

Welcome to CakePHP v4.1.4 Console
App : src
Path: /var/www/cakephp/cakepro/src/
DocumentRoot: /var/www/cakephp/cakepro/webroot
Ini Path:
built-in server is running in http://localhost:8765/
You can exit with `CTRL-C`
[Mon Sep 7 09:40:36 2020] PHP 7.4.9 Development Server (http://localhost:8765) started

We need to browse the URL http://localhost:8765/ and you can see CakePHP 4.1.4 strawberry is working perfectly. 

We’ve successfully install CakePHP 4 on ubuntu 20.04. In a similar way, you can install it on any ubuntu distro.

That’s it.

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment