In this tutorial I’ll show you step by step on how to install the popular rapid development framework CakePHP on Ubuntu Linux. Recently CakePHP has released its latest version 3.5 with a variety of changes to improve speed and security.
Install LAMP Server (Linux Apache MySQL PHP)
I’ll assume you’ve got Ubuntu already set up and you’ve got a working ssh connection. That’s why I start right with installing the Apache, MySQL PHP part.
$ sudo apt-get update $ sudo apt-get install curl apache2 mysql-server libapache2-mod-php $ sudo apt-get install php php-mysql php-mbstring php-intl php-xml
I recommend doing the update before the actual installation, that way you’re really getting the latest version of each component. For those of who are wondering why we’re installing curl: We’ll need curl later on for setting up composer.
Configuring the httpd config
This step is crucial as CakePHP’s default rooting wouldn’t work otherwise. You’ll need to add the following snippet to your apache2.conf file. See screenshot below for the file path.
<Directory "/var/www/html"> AllowOverride All Options FollowSymLinks </Directory>
You can add the snippet right beneath the other directory settings.
Don’t forget to restart the Apache server by issuing this command:
sudo service apache2 restart
The next step is installing Composer using the following command on the system. CakePHP uses Composer for creating new projects and for managing dependencies. As you can see, we are now making use of the previously installed curl application.
$ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer $ chmod +x /usr/local/bin/compos
Create your first CakePHP application using Composer
composer create-project --prefer-dist cakephp/app <nameofyourapplication>
Just replace <nameofyourapplication> with whatever name you’ll want to use for your new application.
Change the Permissions
This step is necessary as the owner, the group and others need read, write and execute privileges to the Cake’s tmp folder. Issue this command right from the /var/www/html directory.
$ chown -R www-data:www-data <nameofyourapplication> $ chmod -R 755 MyApp $ chmod -R 777 MyApp/tmp
Change the firewalls rules.
To make your EC2 instance accessible from everywhere in the world you need to allow http access to your compute instance.
Click “Edit” of the inbound Security Group and add a new HTTP rule. You might also want to add a HTTPS rule in case you plan to use SSL encryption.
You should now be able to access your newly created CakePHP installation through the internet. It should look similar to the following image.
Configure the database (connection)
First we’ll need to create a new blank database unless you have an exciting database or a backup already in place. You can create a new database easily from within the terminal.
$ mysqladmin -u root -p create <nameofyourdatabase>
Once asked for the password leave it blank (just hit enter).
Pretty much the last step in order to setup CakePHP is to configure the database settings. By default the standard MySQL user is root and the password is blank. I would highly recommend you to create a new user with a strong password. Though, for the sake of this tutorial, I’ll keep the default settings. Edit the app.php file in /var/www/html/<nameofyourapplication>/config/app.php. Make the corresponding changes to the database section (change the username, password, databasename and encoding).
Go back to the main page of your CakePHP installation and check if CakePHP was able to successfully establish a database connection. If everything has been setup correctly, you should see a green chef hat.
That’s it for this tutorial. I hope you find it useful!