How to install Cake PHP on CentOS 7?

0
288
cake PHP
cake PHP

Cake PHP is a very good framework for web application development. It has many advantages that make it a very popular framework with features that meet current market needs. So, I will install Cake PHP on CentOS 7.

Recently I was saying that CentOS had published a new maintenance version and maybe this is the best time to use it. Also, developers prefer to use stable Linux distributions so CentOS 7 and Cake PHP make a great combination.

There are many features of Cake PHP, perhaps the most important is that it is a framework that when installed, is ready to start developing. Another important feature is that it is object-oriented and has very clear conventions. So, let’s not waste any more time and get started.

1.- Upgrade the system

First, you need to update the system. This is very important to have the security patches installed and thus improve the robustness of the system.

:~$ su
:~# yum update
1.- Upgrade the system
1.- Upgrade the system

Now with all this installed, it’s safe to continue.

2. Install Apache web server

Cake PHP has the great advantage of being a framework compatible with several web servers. This is indispensable because it can be adapted to many different servers. However, in this case, I will use the Apache web server.

:~# yum install httpd
2.- Install apache web server from CLI
2.- Install Apache web server from CLI

Then, enable and start the service.

:~# systemctl enable httpd
:~# systemctl start httpd
3.- Enabling apache web server service
3.- Enabling apache web server service

Next, add the firewall rule.

:~# firewall-cmd --zone=public --permanent --add-service=http
4.- Setting the firewall rule
4.- Setting the firewall rule

Finally, restart the firewall.

:~# firewall-cmd --reload

And that’s it.

3. Install PHP

It’s obvious, isn’t it? If we are going to install a PHP framework you need to install PHP first. This popular programming language is almost one of the pillars of the internet. Many sites are made with this language.

Since CentOS 7 comes with a very old version of PHP, I’m going to use an external repository to install PHP 7.2.

:~# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
5.- Adding an external repository to install PHP
5.- Adding an external repository to install PHP

Next, enable the repository.

:~# yum-config-manager --enable remi-php72

Now, you can install PHP 7.2.

:~# yum install php php-common php-opcache php-cli php-xml php-pdo php-mysqlnd php-mbstring php-gd php-curl php-mcrypt php-zip php-imap php-intl
6.- Install PHP 7.2
6.- Install PHP 7.2

Next, restart Apache.

:~# systemctl restart httpd

Now, PHP is installed.

4. Install MariaDB

Like the Apache web server, it is possible to use various database managers. In this case, I will use MariaDB, but you can also use PostgreSQL or SQLite.

:~# yum install mariadb-server
7.- Install MariaDB
7.- Install MariaDB

So, enable and start the service.

:~# systemctl enable mariadb
:~# systemctl start mariadb
8.- Starting MariaDB
8.- Starting MariaDB

Now, it is time to set a root password for MariaDB. It is easy to do it.

:~# mysql_secure_installation
9.- Setting a root password
9.- Setting a root password

After defining the root password, you will be asked other questions. You can answer as you like because they are not relevant, however, you have to read them well. I answered Y, N, Y, Y.

With this MariaDB is installed. However, it is a good idea to create a user dedicated to Cake PHP. I’ll show you how.

:~# mysql -u root -p
CREATE DATABASE cake;
GRANT ALL ON cake.* to 'cakeuser'@'localhost' IDENTIFIED BY 'cakepss';
FLUSH PRIVILEGES;
exit;
10.- Creating a new user and database for Cake PHP
10.- Creating a new user and database for Cake PHP

Of course, replace the name of the database, user and password with the one you want.

5. Install Cake PHP

Now it’s Cake PHP’s turn. The best way to install it is through Composer.

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

Now create a Cake PHP project. I’ll call it example, but you know, you have to put the one you want.

:~# composer create-project --prefer-dist cakephp/app example
12.- Install Cake PHP using Composer
12.- Install Cake PHP using Composer
13.- Cake PHP installed
13.- Cake PHP installed

Then, you need to change the permissions and the owner of the folder.

:~# chown -R apache:apache example
:~# chmod -R 755 example
:~# chmod -R 777 example/tmp
14.- Setting the permissions to the project folder
14.- Setting the permissions to the project folder

Now you need to tell Cake PHP the parameters of the database and user created. So, edit the config/app.php file.

:~# vi example/config/app.php
15.- Setting the database parameters
15.- Setting the database parameters

Set the firewall rule and restart it:

:~# firewall-cmd --zone=public --permanent --add-port=8765/tcp
:~# firewall-cmd --reload

Finally, deploy Cake PHP.

:~# cd example
:~# bin/cake server
16.- Starting Cake PHP
16.- Starting Cake PHP

Or you can specify the host and port:

:~# bin/cake server -H 192.168.250.4 -p 8765

Open your web browser, and go to your host and port. You will see this.

17.- Cake PHP installed
17.- Cake PHP installed

And you can start to code!

Conclusion

Now you know how to install Cake PHP on CentOS 7 it is important to remember that it is a very popular and successful framework in the web world.

Please share this article with your friends.

LEAVE A REPLY

Please enter your comment!
Please enter your name here