CakePHP is a PHP framework for rapid development of web application. Recently CakePHP has released its latest version 3.X with a variety of changes for faster speed and security. This article will help you to Setup CakePHP 3.3 on Linux-based systems.
- PHP 5.5.9 or greater (including PHP 7).
- PHP mbstring extension
- PHP intl extension
- MySQL (5.1.10 or greater)
1. Install LAMP Server
LAMP stands for Linux, Apache, MySQL and PHP. Use the following commands to Setup LAMP on your Linux Server.
CentOS / RHEL and Fedora:
# yum install httpd mysql-server php php-mysql php-mbstring php-intl
Ubuntu and Debian:
$ sudo apt-get install apache2 mysql-server php5 php5-mysql php5-mbstring php5-intl
2. Install Composer
Now cakephp is using composer for managing dependencies. So first we need to install Composer using following command on system.
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer $ chmod +x /usr/local/bin/composer
3. Create CakePHP 3 Application
After installing composer on your system. Let’s create your Cakephp project named “MyApp” using composer command as below.
$ composer create-project --prefer-dist cakephp/app MyApp
Now set the proper permission for your project files. For CentOS users, Apache runs as “apache” user and for Debian based system Apache default uses www-data as the user. So change files ownership as per your setup.
$ chown -R apache:apache MyApp $ chmod -R 755 MyApp
4. Setup Database for CakePHP
For this article we are using MySQL as database server. First use following commands to create MySQL database and create.
# mysql -u root -p Enter password: mysql> CREATE DATABASE
mydb; mysql> GRANT ALL ON mydb.* to ' myuser'@'localhost' IDENTIFIED BY ' _password_'; mysql> FLUSH PRIVILEGES; mysql> quit
Now edit config/app.php configuration file and search for your database setting. Make necessary changes as per below details
'Datasources' => [ 'default' => [ 'className' => 'CakeDatabaseConnection', 'driver' => 'CakeDatabaseDriverMysql', 'persistent' => false, 'host' => '
localhost', //'port' => 'nonstandard_port_number', 'username' => ' myuser', 'password' => ' _password_', 'database' => ' mydb', 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => true,
5. Setup Web Server Virtual Host
Now the time is for creating a virtual host in Apache. Edit your Apache configuration file or create separate file whatever best suited you.
<VirtualHost *:80> ServerAdmin [email protected] ServerName cakephp.tecadmin.net DocumentRoot /var/www/html/MyApp <Directory /var/www/html/MyApp> Allowoverride All </Directory> </VirtualHost>
6. Verify Setup
After making all above configuration’s, let’s restart your Apache server using following command.
CentOS/RHEL and Fedora:# service httpd restart Ubuntu and Debian:$ service apache2 restart
Now access the website with configured ServerName in the web browser. I have done host file entry to map domain name with ip on local system.