How to Install CakePHP on AlmaLinux, Rocky Linux, Debian, and Ubuntu

CakePHP is an open-source web application framework that makes building web apps easier and faster. This guide will walk you through the steps to install CakePHP on AlmaLinux, Rocky Linux, Debian, and Ubuntu.


Prerequisites:

Before starting the installation, ensure you have the following:

  • A server running AlmaLinux, Rocky Linux, Debian, or Ubuntu.
  • Root or sudo access to your server.
  • LAMP stack (Linux, Apache, MySQL/MariaDB, PHP) installed.
  • A domain or subdomain pointing to your server.

Step 1: Update the System

Make sure all the system packages are up-to-date.

  • For Ubuntu/Debian:
 
sudo apt update && sudo apt upgrade -y
  • For AlmaLinux/Rocky Linux:
 
sudo dnf update -y

Step 2: Install Required Software

CakePHP requires Apache, MySQL/MariaDB, PHP, and Composer (PHP dependency manager).

  1. Install Apache, MySQL/MariaDB, PHP, and required PHP extensions:
  • For Ubuntu/Debian:
 
sudo apt install apache2 mariadb-server php php-cli php-mbstring php-xml php-mysql libapache2-mod-php unzip curl -y
  • For AlmaLinux/Rocky Linux:
 
sudo dnf install httpd mariadb-server php php-cli php-mbstring php-xml php-mysqlnd unzip curl -y
  1. Install Composer (PHP dependency manager):
  • For all distributions (Ubuntu/Debian/AlmaLinux/Rocky Linux):
 
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer

Step 3: Configure the Database

CakePHP requires a database to store its data. Here, we'll use MySQL/MariaDB.

  1. Log in to MariaDB:
 
sudo mysql -u root -p
  1. Create a database and user for CakePHP:
sql
 
CREATE DATABASE cakephp_db; CREATE USER 'cakephp_user'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON cakephp_db.* TO 'cakephp_user'@'localhost'; FLUSH PRIVILEGES; EXIT;

Step 4: Download and Install CakePHP

  1. Navigate to the web directory (usually /var/www/html):
 
cd /var/www/html
  1. Download and install CakePHP using Composer:
 
composer create-project --prefer-dist cakephp/app cakephp

This command will create a cakephp directory inside /var/www/html and install the latest CakePHP version.

  1. Set proper permissions for the CakePHP directory:
 
sudo chown -R www-data:www-data /var/www/html/cakephp # For Ubuntu/Debian sudo chown -R apache:apache /var/www/html/cakephp # For AlmaLinux/Rocky Linux

Step 5: Configure Apache (for AlmaLinux/Rocky Linux)

  1. Create a new Apache configuration file for CakePHP:
 
sudo nano /etc/httpd/conf.d/cakephp.conf
  1. Add the following content:
apache
 
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/cakephp/webroot ServerName yourdomain.com ErrorLog /var/log/httpd/error_log CustomLog /var/log/httpd/access_log combined <Directory /var/www/html/cakephp/webroot> AllowOverride All Require all granted </Directory> </VirtualHost>
  1. Restart Apache:
 
sudo systemctl restart httpd

Step 6: Configure Apache (for Ubuntu/Debian)

  1. Create a new Apache site configuration file:
 
sudo nano /etc/apache2/sites-available/cakephp.conf
  1. Add the following content:
apache
 
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/cakephp/webroot ServerName yourdomain.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html/cakephp/webroot> AllowOverride All Require all granted </Directory> </VirtualHost>
  1. Enable the new site and rewrite module:
 
sudo a2ensite cakephp.conf sudo a2enmod rewrite
  1. Restart Apache:
 
sudo systemctl restart apache2

Step 7: Configure CakePHP

  1. Navigate to the CakePHP configuration file:
 
cd /var/www/html/cakephp/config
  1. the app_local.php file to configure the database:
 
sudo nano app_local.php
  1. Add the database configuration:
php
 
'Datasources' => [ 'default' => [ 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', 'username' => 'cakephp_user', 'password' => 'your_password', 'database' => 'cakephp_db', 'encoding' => 'utf8', ], ],

Step 8: Set Up CakePHP for Production

  1. Set correct file permissions:
 
sudo chmod -R 777 /var/www/html/cakephp/tmp sudo chmod -R 777 /var/www/html/cakephp/logs
  1. Run the CakePHP migrations:
 
cd /var/www/html/cakephp bin/cake migrations migrate

Step 9: Access CakePHP in the Browser

  1. Open your browser and go to http://yourdomain.com. You should see the CakePHP welcome page.

  2. From here, you can start building your CakePHP application.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution