Deploying Kohana PHP application on Debian








Are you trying to deploy Kohana on Debian?

This guide is for you.


Kohana is a web application development framework. Given PHP's nature as a language and the way the code written is executed on computers, there is no strict requirement to exploit frameworks to quickly develop applications when working with it.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Debian related Installtion tasks.

In this context, we shall look into how to set up Laravel with Nginx on Ubuntu 16.04.


More information about Kohana ?

Kohana is an HMVC (Hierarchical Model View Controller) light framework. It offers all the necessary tools out-of-the-box in order to build a modern web application.

It is mainly made of files that are scattered across carefully structured directories inside a single (application) one. So it means that each Kohana package can be considered as a web application.

The design of Kohana makes it extremely friendly for deployment.


How to prepare the System to deploy Kohana Application ?

Here, we will prepare the system before deploying Kohana.


We are considering a newly instantiated Ubuntu 13 VPS.

i. First, we update the system by executing the below commands.

aptitude update
aptitude -y upgrade

ii. Next, we install Nginx.

aptitude -y install nginx

iii. After that, we start the server by running the below command.

service nginx start

iv. Now, we will install MySQL 5.

aptitude -y install mysql-server mysql-client

Note: During the installation process a couple of questions regarding the root password will be asked.

We bootstrap everything using mysql_secure_installation:

# Run the following to start the process
mysql_secure_installation
# Enter the root password you have chosen during installation
# Continue with answering the questions, confirming all.
# Ex.:
# Remove anonymous users? [Y/n] Y
# Disallow root login remotely? [Y/n] Y
# ..
# .

v. To restart and check the status of MySQL installation, we run the below commands.

# mysql stop/waiting
# mysql start/running, process 25012
# mysql start/running, process 25012

We install PHP (PHP-FPM) by running the below command.

aptitude -y install php5 php5-fpm php5-mysql

Also, it will install the PHP5 commons.


How to configure the System ?

After installing the necessary tools, now we shall configure the system.


Configuring PHP

First, we configure PHP by editing the php.ini file. For that, we open the file by running the below command.

nano /etc/php5/fpm/php.ini

Then we scroll down the document and find the line ;cgi.fix_pathinfo=1. We modify it similar to the following to have application paths processed securely:

# Replace ;cgi.fix_pathinfo=1 with:
cgi.fix_pathinfo=0

Finally, we save and exit the file by pressing CTRL+X and confirm with Y.


Configuring Nginx

We will edit the default Nginx website configuration file. For that, we run the below command to open the file.

nano /etc/nginx/sites-available/default

Next, we copy and paste the below content:

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# Set the default application path root
# We are using my_app to host the application
root /var/www/my_app;
index index.php;
# Replace the server_name with your own
server_name localhost;
location /
{
try_files $uri /index.php?$args;
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ /\.
{
deny all;
}
location ~ \.php$
{
try_files $uri = 404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

Finally, we save and exit by pressing CTRL+X and confirm with Y.

Then we create and enter the application deployment directory /var/www:

mkdir /var/www
cd /var/www

After that, we test the configurations and restart Nginx for the chances to take effect:

nginx -t
service nginx restart

Deploying A Kohana Web-Application on Debian

Now let's see how our Support Engineers deploy Kohana.


This process comprises 2 main steps.

i. Uploading the code base to the server

ii. Modifying bootstrap.php to ensure it is set correctly.


1. Uploading the Code Base To The Server

Now, we need to transfer the file. So we can use SFTP or a graphical tool, such as FileZilla.

First, we download Kohana.

wget https://github.com/kohana/kohana/releases/download/v3.3.1/kohana-v3.3.1.zip

Next, we install *unzip* before extracting the files

aptitude install -y unzip

Then we unzip and extract the files

unzip kohana-v3.3.1.zip -d my_app

After that, we remove the zip package.

rm -v kohana-v3.3.1.zip

Then we enter the application directory

cd my_app

2. Bootstrapping the Deployment (Installation)

We run the following command to start editing the configuration file using nano:

nano application/bootstrap.php

Then we edit the timezone.

date_default_timezone_set('Europe/London');

After that, we set the locale.

setlocale(LC_ALL, 'en_UK.utf-8');

We find end edit the base_url to match the installation

Kohana::init(array(
'base_url' => '/',
));

Also, we make sure to enable all necessary modules:

# Find Kohana::modules and uncomment them
Kohana::modules(array(
'auth' => MODPATH.'auth', // Basic authentication
'cache' => MODPATH.'cache', // Caching with multiple backends
'codebench' => MODPATH.'codebench', // Benchmarking tool
'database' => MODPATH.'database', // Database access
'image' => MODPATH.'image', // Image manipulation
'orm' => MODPATH.'orm', // Object Relationship Mapping
'oauth' => MODPATH.'oauth', // OAuth authentication
'pagination' => MODPATH.'pagination', // Paging of results
'unittest' => MODPATH.'unittest', // Unit testing
'userguide' => MODPATH.'userguide', // User guide and API documentation
));

Finally, we save and exit by pressing CTRL+X and confirm with Y.


Also, we set cache and log directories writable:

sudo chmod -R a+rwx application/cache
sudo chmod -R a+rwx application/logs

That's it! Now we have our Kohana web application ready to run.


[Need urgent assistance with Debian related Installation? – We're available 24*7. ]



Conclusion

This article will guide you on how to deploy Kohana on #Debian. Kohana offers powerful event handling, multiple session drivers, simple database abstraction using #SQL helpers, and libraries that transparently handle external APIs. Its generous BSD license lets developers use and modify the framework to build commercial applications.

The #AppDynamics platform provides full, code-level visibility into the performance of your PHP application built on the Kohana framework. With rapid installation and the most scalable #architecture in the industry, AppDynamics solutions help you deploy your #applications more quickly and with more confidence.


For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com