How to Install Yii Framework on a Debian VPS with Nginx

yii vpsYii is an open source, high performance PHP framework used for developing web 2.0  applications.
In this step-by-step tutorial, we will show you how to easily install Yii framework on your Debian based virtual server.


At the time of writing this tutorial, the latest stable version is Yii 1.1.15 and it requires:

  • Web server (Apache, Nginx etc.) installed on your Linux virtual server.
  • PHP 5.1 or higher (the php5-fpm package is required for Nginx servers)

If you have Apache installed on your server, stop the Apache service and remove Apache packages:

/etc/init.d/apache2 stop
apt-get remove apache2*

Make sure your Debian VPS is fully up to date by using the following commands:

apt-get update
apt-get upgrade

In order to install Nginx, PHP-FPM and MySQL on your server, execute the following command:

apt-get install nginx php5-fpm php5-cli php5-mcrypt php5-gd mysql-client-5.5 mysql-server-5.5 mysql-server-core-5.5

Download the latest version of YII framework available at to the server:

cd /root
mkdir -p /var/www/{,}

Extract the tar archive, rename ‘yii-’ directory to ‘yii’ and move it to the ‘/var/www/’ directory using the following commands:

tar -xvf yii- -C /var/www/
mv /var/www/ /var/www/
chown www-data:www-data -R /var/www/

Locate the PHP configuration file using the following command:

php5-fpm -i | grep php.ini
Configuration File (php.ini) Path => /etc/php5/fpm
Loaded Configuration File => /etc/php5/fpm/php.ini

Edit the /etc/php5/fpm/php.ini configuration file using the following command:

vi /etc/php5/fpm/php.ini

and add/modify the following lines:

memory_limit = 128M
cgi.fix_pathinfo = 0
safe_mode = Off
max_execution_time = 60
max_input_time = 60

Execute the following command to restart the php5-fpm service:

/etc/init.d/php5-fpm restart

For performance reasons, our recommendation is to run php5-fpm in SOCKET mode, instead of accessing via <IP_address>:PORT.

Create a new Nginx configuration file:

vi /etc/nginx/sites-available/

and add the following lines:

server {
	listen 80;
	root /var/www/;
	index index.php index.html;
	access_log /var/log/nginx/;
	error_log /var/log/nginx/;
	set $yii_bootstrap "index.php";
	charset utf-8;

location / {
        index  index.html $yii_bootstrap;
        try_files $uri $uri/ /$yii_bootstrap?$args;

location ~ ^/(protected|framework|themes/\w+/views) {
        deny  all;

location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        try_files $uri =404;

location ~ \.php {
	fastcgi_index index.php;
	fastcgi_split_path_info ^(.+\.php)(.*)$;
	set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
	include /etc/nginx/fastcgi_params;
	fastcgi_pass unix:/var/run/php5-fpm.sock;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;

Create a symbolic link using the following command:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer

Now just $43 .99

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

and restart the Nginx web server for the changes to take effect:

/etc/init.d/nginx restart

Create a directory named ‘example’ inside the ‘yii’ directory:

mkdir -p /var/www/
chown www-data:www-data /var/www/

and execute the following command:

php /var/www/ webapp /var/www/
Create a Web application under '/var/www/'? (yes|no) [no]:yes

Now test the new project by navigating to using a web browser.

Yii framework has been installed now.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Yii PHP Framework for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.


1 thought on “How to Install Yii Framework on a Debian VPS with Nginx”

  1. Yii framework is my first choice. I created my most of the websites with the help of Yii framework. It is easy to install Yii in ubuntu. But I am not clear about the process of how to install Yii framework o a Debian VPS with Nginx. Steps you shared here are very useful to understand and perform.


Leave a Comment