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
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
Then, enable and start the service.
:~# systemctl enable httpd :~# systemctl start httpd
Next, add the firewall rule.
:~# firewall-cmd --zone=public --permanent --add-service=http
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
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
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
So, enable and start the service.
:~# systemctl enable mariadb :~# systemctl start mariadb
Now, it is time to set a root password for MariaDB. It is easy to do it.
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;
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
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
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
Now you need to tell Cake PHP the parameters of the database and user created. So, edit the
:~# vi example/config/app.php
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
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.
And you can start to code!
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.