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 https://github.com/yiisoft/yii/releases/latest to the server:

cd /root
wget https://github.com/yiisoft/yii/releases/download/1.1.15/yii-1.1.15.022a51.tar.gz
mkdir -p /var/www/{your-domain.com,your-domain.com/yii}

Extract the tar archive, rename ‘yii-1.1.15.022a51’ directory to ‘yii’ and move it to the ‘/var/www/your-domain.com’ directory using the following commands:

tar -xvf yii-1.1.15.022a51.tar.gz -C /var/www/your-domain.com/
mv /var/www/your-domain.com/yii-1.1.15.022a51 /var/www/your-domain.com/yii
chown www-data:www-data -R /var/www/your-domain.com/yii

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/your-domain.com

and add the following lines:

server {
	listen 80;
	server_name your-domain.com;
	root /var/www/your-domain.com/yii/;
	index index.php index.html;
	access_log /var/log/nginx/your-domain.com-access.log;
	error_log /var/log/nginx/your-domain.com-error.log;
	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:

ln -s /etc/nginx/sites-available/your-domain.com /etc/nginx/sites-enabled/your-domain.com

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/your-domain.com/yii/example
chown www-data:www-data /var/www/your-domain.com/yii/example

and execute the following command:

php /var/www/your-domain.com/yii/framework/yiic.php webapp /var/www/your-domain.com/yii/example
Create a Web application under '/var/www/your-domain.com/yii/example'? (yes|no) [no]:yes

Now test the new project by navigating to http://your-domain.com/example 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.

    Reply

Leave a Comment