How to Install CakePHP on Ubuntu 24.04

CakePHP is a most popular and widely-used open-source web application framework built in PHP that follows the Model-View-Controller (MVC) architectural pattern and is designed to make the development of web applications easier and more organized.

In this article, we will guide you through installing CakePHP on an Ubuntu 24.04 system.

Prerequisites

  • A server running Ubuntu 24.04 with administrative access (root user or sudo privileges).
  • A server running the LAMP (Apache, MySQL, and PHP) stack was installed and configured.

Install LAMP Stack in Ubuntu 24.04

First, begin by updating your local system packages to make sure you have the latest versions of software packages installed.

sudo apt update
sudo apt upgrade -y

Next, you need to install a LAMP stack, which is required by CakePHP applications to handle incoming requests and deliver web pages.

sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql php-cli php-curl php-gd php-mbstring php-mysql php-xml php-zip php-sqlite3 -y
Install LAMP in Ubuntu
Install LAMP in Ubuntu

Install PHP Composer in Ubuntu 24.04

Next, install Composer, which is a dependency management tool for PHP that will help us install and manage the CakePHP framework.

sudo apt install -y composer
Install Composer in Ubuntu
Install Composer in Ubuntu

Once the installation is complete, verify the Composer version by running.

composer --version
Check Composer Vesrion in Ubuntu
Check Composer Version in Ubuntu

Install CakePHP on Ubuntu 24.04

Now, we can proceed with the installation of the CakePHP framework using the following command, which will create a new directory called my_cakephp_app and install the latest stable version of CakePHP within it under the Apache web root directory, which is /var/www/html/.

cd /var/www/html/
sudo composer create-project --prefer-dist cakephp/app my_cakephp_app
Install CakePHP in Ubuntu
Install CakePHP in Ubuntu

After the installation is complete, navigate to the my_cakephp_app directory using the cd command and list the files.

cd my_cakephp_app
ls -l
List CakePHP Project Files
List CakePHP Project Files

Here, you will find the following important directories and files:

  • config – This directory contains the configuration files for your CakePHP application.
  • src: This directory holds the application’s source code, including controllers, models, and views.
  • templates: This directory contains the view templates for your application.
  • webroot: This directory is the document root for your web server and contains the public-facing files, such as CSS, JavaScript, and images.

CakePHP comes with a built-in development server that you can use to test your application during development.

Configure Apache for CakePHP

Create a new Apache configuration file for your CakePHP project.

sudo nano /etc/apache2/sites-available/myapp.conf

Add the following configuration, adjusting paths and domain as necessary.

<VirtualHost *:80>
    ServerName phpcake.tecmint.com
    DocumentRoot /var/www/html/my_cakephp_app
    <Directory /var/www/html/my_cakephp_app>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save the file and enable the virtual host.

sudo a2ensite myapp.conf

Reload Apache for the changes to take effect.

sudo systemctl reload apache2

Adjust permissions so that CakePHP can write to specific directories.

sudo chown -R www-data:www-data /var/www/html/my_cakephp_app/tmp
sudo chown -R www-data:www-data /var/www/html/my_cakephp_app/logs

Finally, start the server, and run the following command.

bin/cake server
Or
/var/www/html/my_cakephp_app/bin/cake server
Start CakePHP in Ubuntu
Start CakePHP in Ubuntu

This will start the development server and make your CakePHP application available at:

http://localhost:8765
OR
http://domain.com
Access CakePHP in Ubuntu
Access CakePHP in Ubuntu

Explore the CakePHP Application

Now that you have CakePHP installed and configured, you can start exploring the application. The default CakePHP installation comes with a few sample pages and functionality, which you can use as a starting point for your own development.

Some of the key features you can explore include:

  • Home Page: The default home page, which provides a basic overview of your CakePHP application.
  • Articles: A sample CRUD (Create, Read, Update, Delete) application for managing articles.
  • Users: A sample CRUD application for managing user accounts.

To access these features, simply navigate to the corresponding URLs in your web browser, such as:

http://localhost:8765/articles 
or 
http://localhost:8765/users
Conclusion

In this article, we have walked through the process of installing the CakePHP framework on an Ubuntu 24.04 system. We covered the necessary prerequisites, the installation of Composer, the creation of a new CakePHP project, and the configuration of the application.

Finally, we explored the default features and functionality provided by the CakePHP framework. With CakePHP installed, you can now start building your own web applications using this powerful and flexible framework.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.