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 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
Once the installation is complete, verify the Composer version by running.
composer --version
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
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
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
This will start the development server and make your CakePHP application available at:
http://localhost:8765 OR http://domain.com
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.