billysoftacademy.com

Learn how to Install CakePHP on Linux Ubuntu 22.04 LTS

Introduction

CakePHP is a popular option for developers who value efficiency and maintainable code. This open-source framework uses the Model-View-Controller (MVC) pattern to streamline web application development. By separating components, CakePHP promotes code organization and collaboration.This guide will walk you through installing CakePHP on your Ubuntu 22.04 server so you can take advantage of its benefits and speed up your development workflow. You’ll be able to simplify data management with the Model layer, create intuitive user interfaces with the View layer, and orchestrate logical application flow with the Controller layer. Read this tutorial right up to the end to learn how to install CakePHP on your Linux Ubuntu 22.04 LTS Server in a few simple steps.

Requirements

The following is a list of items needed to complete the installation successfully:
1) A desktop or laptop with 4GB of RAM or more, A dual core process or better and atleast 50GB of free disk space
2) Linux Ubuntu Server 22.04 LTS or any newer version
3) An SSH client such as Putty or the MacOS terminal app
4) For cloud deployments, you will also need a fully qualified domain name and a public static IP address
5) A basic understanding of Linux commands.

Overview

The following is an overview of the steps covered in this tutorial:
1) Download and install the LAMP stack
2) Create a MySQL database.
3) Download and install CakePHP.
4) Create an Apache VirtualHost.
5) Open a new browser window and open the CakePHP web app.

Download and install the LAMP stack

The first step is downloading and installing the LAMP stack. LAMP stands for Linux, Apache, Mariadb, PHP. It is a stack that make it possible to run apps such as WordPress. To set up your server with Apache, MariaDB, PHP, and necessary dependencies, follow these steps:

1. Begin by updating your package list:

apt update -y

2. Next, install Apache, MariaDB, PHP, and essential PHP modules with this command:

apt install unzip apache2 mariadb-server libapache2-mod-php php-mysql php-zip php-mbstring php-intl php-xml -y

Once the installation of the packages is complete, proceed to install PHP Composer.

wget -O composer-setup.php https://getcomposer.org/installer
php composer-setup.php --install-dir=/usr/local/bin --filename=composer

To confirm the installed PHP Composer version, run the following command:

composer -v

Expected output should show the following details:

Composer version 2.6.5 2024-01-31 02:47:11

Create a My SQL database

You have successfully completed the LAMP stack and composer installation process. The next step is creating a MySQL database to be used by CakePHP. Run the following commands to create the database:
CREATE DATABASE cakephpdb;
GRANT ALL ON cakephpdb.* TO cakephpuser@localhost IDENTIFIED BY 'verystrongpassword';
FLUSH PRIVILEGES;
EXIT;

Download and install CakePHP

The next step is using composer to download and install CakePHP. Run the following command to change the working directory to the virtual host root:

cd /var/www/html/

Run the following command to download and install CakePHP:

composer create-project --prefer-dist cakephp/app:~4.0 billysoftacademy

When the installation process completes, open the app_local.php configuration file:

nano /var/www/html/billysoftacademy/config/app_local.php

Set the mysql database username, password and database name on the ‘Datasouces’ array:

'username' => 'cakephpuser',
'password' => 'verystrongpassword',
'database' => 'cakephpdb',

Create an Apache virtualhost

Run the following command to create a virtualhost configuration file in the apache2 sites-available directory:
nano /etc/apache2/sites-available/cakephp.conf
Add the following configuration to the file:
< VirtualHost *:80>

ServerAdmin admin@example.com
ServerName cakephp.example.com
DocumentRoot /var/www/html/project/

< Directory /var/www/html/project/>
    AllowOverride All
    Require all granted
< /Directory>

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

< /VirtualHost>
Remember to update the ServerAdmin and ServerName parameters to match the domain name pointing to the IP address of your server. Enable the virtualhost by running the command:
a2ensite cakephp.conf
Enable the Apache rewrite engine by running the command:
a2enmod rewrite
Restart apache so that all the changes will take effect with the command:
systemctl restart apache2
You can also verify apache is running with the command:
systemctl status apache2

Open a new browser window and open the CakePHP web app.

The final step is opening a new browser window and accessing the CakePHP web application. To this, enter the domain name pointing to the CakePHP server and you should see the default CakePHP welcome page.

In this guide, we have walked you through the process of installing CakePHP on your Ubuntu 22.04 server. By following these steps, you have successfully set up the LAMP stack, created a MySQL database, downloaded and installed CakePHP, configured an Apache virtual host, and finally accessed the CakePHP web application.

With CakePHP up and running on your server, you can now leverage its advantages to streamline your web development workflow. The Model-View-Controller (MVC) pattern promotes code organization and maintainability, allowing you to focus on building robust and scalable web applications.

Remember to replace the placeholder values in the Apache virtual host configuration with your specific domain name and credentials. Additionally, secure your database with a strong password to protect your application’s data.

We hope this guide has been helpful! Feel free to explore CakePHP’s documentation and resources to delve deeper into its functionalities and unleash your development potential.

Scroll to Top