Install CakePHP 3.0 on CentOS

Install CakePHP 3.0 on CentOS VPSToday we are going to show you how to install CakePHP 3.0 on your Linux VPS. CakePHP is a rapid development PHP framework. It allows you to build web applications quickly without complex configurations. It is secure and licensed under the MIT license which makes it a very suitable framework for web developers.

In order to install CakePHP you need to make sure that your CentOS VPS meets the following requirements:

* LAMP is installed
* PHP 5.4.16 or higher is installed.
* PHP mbstring extension is loaded.
* PHP intl extension is loaded.

First, log in to your VPS via SSH and update your system software to the latest version with the following command:

yum update

Install PHP mbstring and intl extensions using the command:

yum install php-mbstring php-intl

Now, to manage the CakePHP dependencies you need to download and install composer. You can accomplish this by executing the following commands:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer

Also, you need to create a database, a database user and set up a password for your first CakePHP project. Log in to your MySQL as root:

mysql -u root -p

and execute the following commands:

mysql> CREATE DATABASE app_db;
mysql> GRANT ALL PRIVILEGES on app_db.* to 'app_user'@'localhost' identified by 'YoUrPaS$w0rD';
mysql> FLUSH PRIVILEGES;
mysql> exit

You can replace ‘app_db’, ‘app_user’ and ‘YoUrPaS$w0rD’ to match your needs.
Next, navigate to /var/www/html and create your first CakePHP project.

cd /var/www/html

To create your first CakePHP project you need to execute the following command:

composer create-project --prefer-dist cakephp/app CakePHPApp

You can replace ‘CakePHPApp’ to match the name of your first CakePHP project. You should wait no longer than one minute for your project to be ready. Then, change the ownership of the files and make Apache to be the owner using the following command:

chown apache: -R CakePHPApp/

Now, edit the ‘app.php’ configuration file:

nano CakePHPApp/config/app.php

Find the datasources section and change the ‘host’, ‘username’, ‘password’ and ‘database’ to match yours.

    'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'username' => 'app_user',
            'password' => 'YoUrPaS$w0rD',
            'database' => 'app_db',
            'encoding' => 'utf8',
            'timezone' => 'UTC',
            'cacheMetadata' => true,

It is time to configure Apache. Edit your Apache configuration file:

nano /etc/httpd/conf/httpd.conf

Add the following lines at the end of the file:

<VirtualHost *:80>
 ServerAdmin admin@yourdomain.com
 DocumentRoot /var/www/html/CakePHPApp/
 ServerName yourdomain.com
 ServerAlias www.yourdomain.com
 <Directory /var/www/html/CakePHPApp/>
 Options FollowSymLinks
 AllowOverride All
 </Directory>
 ErrorLog /var/log/httpd/yourdomain.com-error_log
 CustomLog /var/log/httpd/yourdomain.com-access_log common
</VirtualHost>

Restart Apache:

/etc/init.d/httpd restart

That’s it. You have successfully installed CakePHP 3.0 on your CentOS VPS. Open your favorite web browser and navigate to:

http://yourdomain.com/

The official CakePHP documentation is available at:

http://book.cakephp.org/3.0/en/index.html

Of course you don’t have to do any of this if you use one of our Linux VPS hosting services, in which case you can simply ask our expert Linux admins to install CakePHP for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. And don’t forget to check out our CakePHP hosting plans. Thanks.

Leave a Comment