(LEMP) Installing CakePHP 3.8, PHP 7.3, Mariadb 10.4 and NGINX on Ubuntu 19.04

In this blog, we’re not just going to give details about CakePHP but provide information as well on how to install LEMP. I know frustrations one sometimes have when using Nginx, PHP, and MySQL/MariaDB like “wt* is wrong with permissions?! I’ve already added it to groups in www-data, I’ve already set my folder to 777, etc” well, I’m with you on that, that is why this tutorial will help you cover everything and starts working on LEMP environment.

CakePHP is the only Rapid Application Development out there that is easy to use, fast, and only require less code. It uses clean MVC conventions and it is secure.

Step 1: Install NGINX 

sudo apt update && sudo apt install nginx 

Configure Nginx 

Next, open the Nginx configuration file, which can be found at /etc/nginx/nginx.conf 

sudo nano /etc/nginx/nginx.conf 

Start by setting the user to the username that you’re currently logged in with. This will make managing file permissions much easier in the future. 

The worker_processes directive is the amount of CPU cores your instance. In my case, this is 1. 

Uncomment the multi_accept directive and set it to on. 

Lower the keepalive_timeout directive to 15. 

For security reasons, you should uncomment the server_tokens directive and ensure it is set to off. 

Add the new client_max_body_size directive below the server_tokens and set the value to 64m. 

Uncomment the gzip_proxied directive and set it to any, uncomment the gzip_comp_level directive and set it to the value of 2 and finally uncomment the gzip_types directive. 

In order for Nginx to correctly serve PHP you also need to ensure the fastcgi_param SCRIPT_FILENAME directive is set, otherwise, you will receive a blank white screen when accessing any PHP scripts. So open fastcgi_params file by issuing 

sudo nano /etc/nginx/fastcgi_params 

Add the following at the end of the file 

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

That’s all, this is the basic Nginx configuration, hit CTRL+X followed by Y to save the changes. Ensure that the configuration file contains no errors and restart Nginx for the changes to take effect by issuing the following command 

sudo nginx -t 

If you get a successful message, then proceed with the following command 

sudo service nginx restart 

Step 2: Install PHP 7.3 FPM and Related Modules 

sudo apt-get install software-properties-common 

sudo add-apt-repository ppa:ondrej/php 

sudo apt-get update 

sudo apt-get install php7.3-fpm php7.3-cli php7.3-mysql php7.3-gd php7.3-imagick php7.3-recode php7.3-tidy php7.3-xmlrpc php7.3-common php7.3-curl php7.3-mbstring php7.3-xml php7.3-bcmath php7.3-bz2 php7.3-intl php7.3-json php7.3-readline php7.3-zip curl 

To check if PHP 7.3 was installed correctly 

php –v 

Now that PHP 7.3.* has installed and you need to configure the user and group that the service will run under. 

sudo nano /etc/php/7.3/fpm/pool.d/www.conf 

Change the following lines by replacing the www-data with your username. 

user = username 
group = username 
listen.owner = username = username 

Now we configure PHP for CakePHP by changing some values in php.ini. 

sudo nano /etc/php/7.3/fpm/php.ini 

Hit F6 for search inside the editor and update the following values 

upload_max_filesize = 32M 
post_max_size = 48M 
memory_limit = 256M 
max_execution_time = 600 
max_input_vars = 3000 
max_input_time = 1000 

Hit CTRL+X and Y to save the configuration and check if the configuration is correct and restart PHP 

sudo php-fpm7.3 -t 
sudo service php7.3-fpm restart 

Step 3: Install Maridb 10.4 

sudo apt-get install software-properties-common 

sudo apt-key adv –recv-keys –keyserver hkp:// 0xF1656F24C74CD1D8 

sudo add-apt-repository “deb [arch=amd64,arm64,ppc64el] $(lsb_release -cs) main” 

sudo apt update 

sudo apt -y install mariadb-server mariadb-client 

sudo systemctl status mariadb 

sudo mysql_secure_installation

The script will prompt you to set up the root user password, remove the anonymous user, restrict root user access to the local machine and remove the test database. At the end the script will reload the privilege tables ensuring that all changes take effect immediately.

All steps are explained in detail and it is recommended to answer “Y” (yes) to all questions.

Step 5: Install phpMyadmin

sudo apt install phpmyadmin

During the installation, it will prompt you to select a web server to configure. Nginx isn’t in the list, so press the Tab key and hit OK to skip this step.

Next, select Yes to create a new database and let dbconfig-common to configure it.

This will also create a new database user named phpmyadmin. Give this user a password.

Step 6: Create Nginx Server Block for phpMyadmin

sudo nano /etc/nginx/conf.d/phpmyadmin.conf


server {
  listen 80;
  listen [::]:80;
  server_name phpmyadmin.test;
  root /usr/share/phpmyadmin/;
  index index.php index.html index.htm index.nginx-debian.html;
  access_log /var/log/nginx/phpmyadmin_access.log;
  error_log /var/log/nginx/phpmyadmin_error.log;
  location / {
    try_files $uri $uri/ /index.php;
  location ~ ^/(doc|sql|setup)/ {
    deny all;
  location ~ .php$ {
    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  location ~ /.ht {
    deny all;

sudo nano /etc/hosts

Add phpmyadmin.test on your host file

sudo nginx -t

sudo nginx -s reload

Open http://phpmyadmin.test/

Step 7: Create Directory and Grant Permission

sudo chown -R $(whoami):$(whoami) /var/www/html/

sudo chmod -R 755 /var/www

Step 8: Install Composer

curl -sS | sudo php — –install-dir=/usr/local/bin –filename=composer

Step 9: Install Cakephp 3.8

Install cakephp into the default directory /var/www/html Run the Composer create-project command to install cakephp in the directory inventory(Change with your own prefer name)

cd /var/www/html

sudo composer clearcache

composer create-project –prefer-dist cakephp/app inventory

After running the commands above, a new project directory will be created… Run the commands below to set the correct permissions for that directory

sudo chmod -R 755 /var/www/html/inventory/

Step 10: Server Configuration

sudo nano /etc/nginx/sites-available/inventory.test


server {
    listen   80;
    listen   [::]:80;
    server_name inventory.test;
    root   /var/www/html/inventory/webroot;
    index  index.php;

access_log /var/www/html/inventory/logs/nginx_access.log;

error_log /var/www/html/inventory/logs/nginx_error.log;


    location / {
        try_files $uri $uri/ /index.php?$args;
    location ~ .php$ {
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

sudo ln -s /etc/nginx/sites-available/inventory.test /etc/nginx/sites-enabled/

sudo nano /etc/hosts

Test configuration if its all working.

sudo nginx –t

sudo systemctl restart nginx

Step 11: Testing cakephp on the Browser

You can now view this page in your web browser by visiting your server’s domain name or public IP address http://inventory.test/