Sohaib's Tech Blog

Something for every one

NGINX Configuration for CS-Cart — 2013

NGINX Configuration for CS-Cart

I have spend a lot of times configuring CS-Cart to work with NGINX server , bottom line is to cache static content and have speed at the same time.

This is my step by step tutorial to install NGINX server and run CS-Cart so here it is :—–

In my environment I am using Ubuntu Precise Edition – which you can grab from Ubuntu website its 12.04 edition, obviously run the following steps once you are done with your UBUNTU installation.

NGINX Installation procedure:

Open Terminal. Open the Sources file for aptitude using vi. If you are not familiar with vi, open the file in nano or gedit.

sudo gedit /etc/apt/sources.list

If you are looking for ways to upgrade or install NGINX in Ubuntu or Debian systems, you are in right place. You can install them easily using the aptitude or apt-get command.The process only takes couple of minutes and requires minimal Linux knowledge.

NGINX Installation procedure:

Open Terminal. Open the Sources file for aptitude using vi. If you are not familiar with vi, open the file in nano or gedit.

sudo gedit /etc/apt/sources.list

If you are using Debian Squeeze (version 6.x),

deb http://nginx.org/packages/debian/ squeeze nginx
deb-src http://nginx.org/packages/debian/ squeeze nginx

If you are using Ubuntu, select the respective lines from below,

For Ubuntu Lucid (Version 10.04),

deb http://nginx.org/packages/ubuntu/ lucid nginx 
deb-src http://nginx.org/packages/ubuntu/ lucid nginx

For Ubuntu Oneiric (Version 11.10),

deb http://nginx.org/packages/ubuntu/ oneiric nginx 
deb-src http://nginx.org/packages/ubuntu/ oneiric nginx

For Ubuntu Precise (Version 12.04),

deb http://nginx.org/packages/ubuntu/ precise nginx
deb-src http://nginx.org/packages/ubuntu/ precise nginx

Add the lines applicable to you in the sources.list file. Now save and close the file.

In order to authenticate the repository and to avoid warnings about missing gpg key during installation of the nginx package, it is advised to add the key used to sign the nginx packages and repository to the apt program keyring.

Run the following commands in the terminal,

wget http://nginx.org/keys/nginx_signing.key
cat nginx_signing.key | sudo apt-key add -

Once added, update the aptitude with new repository,

sudo apt-get update

Now to install NGINX in Ubuntu or Debian systems, run the following command in terminal,

sudo apt-get install nginx

Once NGINX is installed now – will install database and php and configure them properly – In my installation I decided to go with Percona its faster and for what I need I prefer to go with that so here is the next step

But wait here before you install Percona we need to get the repo in Ubuntu

wget https://repo.percona.com/apt/percona-release_0.1-3.$(lsb_release -sc)_all.deb
dpkg -i percona-release_0.1-3.$(lsb_release -sc)_all.deb

Remember to update the local cache:

$ apt-get update

After that you can install the server and client packages

apt-get install percona-server-server-5.6  percona-server-client-5.6 -y

During installation it will ask you to set your mysql ROOT password so please go head and setup your password but DONT FORGET THAT 

Once above is installed now we need to install the major chunk

apt-get install memcached php5-cli php5-fpm php5-mysql php5-curl php5-gd php5-imagick php5-mcrypt php5-memcached

Once above step is completed – I will prefer if you can reboot your server so everything is normal and not acting UP :), once your server is up we need to make sure NGINX is stop and not working, please run the following command.

$ service nginx stop

 

NGINX CONFIGURATION FOR CS-CART Starts HERE remove all contents from nginx.conf file located at /etc/nginx/nginx.conf

user www-data;
worker_processes 8;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;

keepalive_timeout 65;
server_tokens off;
gzip on;
gzip_vary on;
gzip_disable "msie6";
gzip_http_version 1.0;
gzip_comp_level 8;
gzip_proxied any;
gzip_types text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
client_body_temp_path /tmp/client_temp;
# proxy_temp_path /tmp/proxy_temp;
# proxy_cache_path /var/cache/nginx/proxy_cache levels=2 keys_zone=nginx:100m inactive=200m max_size=5000m;
include /etc/nginx/conf.d/*.conf;
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=cache:10m max_size=1000m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

}

After that goto your cd /etc/nginx/conf.d/httpd.conf

server {
listen 80;
listen 443 default ssl;
ssl_certificate /etc/nginx/certs/server.crt;
ssl_certificate_key /etc/nginx/certs/server.key;

server_name www.YOURDOMAIN.com YOURDOMAIN.com;

location / {
root /var/www/YOURDOMAIN/public_html;
index index.php;
try_files $uri $uri/ /index.php?sef_rewrite=1&$args;

}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~ .php$ {
root /var/www/YOURDOMAIN/public_html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/YOURDOMAIN/public_html$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_cache_valid 200 302 10m;
fastcgi_cache_valid 301 1h;
fastcgi_cache_valid any 1m;
}
location ~* .(css|js|jpg|jpeg|png|swf|gif|svg|ttf|eot)$ {
root /var/www/YOURDOMAIN/public_html;
try_files $uri http://backend$1;
expires max;
add_header X-CDN "WCWS INTERNET";
add_header ETag "";
log_not_found off;
add_header Cache-Control "public";
add_header Last-Modified "Sat, 30 Mar 2013 21:47:15 GMT";
}

location ~ /.ht {
deny all;
}
}

Please remember to change YOURDOMAIN with your domain name – Last thing you need to do if you have SSL enable shopping cart you need to add the following cert to your /etc/nginx/certs folder if that folder is not created then please create one and upload your .key and .crt for your SSL.

ssl_certificate /etc/nginx/certs/server.crt;
ssl_certificate_key /etc/nginx/certs/server.key;

test your configuration by using the following command

nginx -t

if everything is good with no error – now simply run

service nginx restart

upload your files to /var/www/YOURDOMAIN/public_html

change your database settings in config.local.php in cs-cart folder once thats done now its time to create MYSQL DB

root@localhost:~# mysql -u root -p

mysql> CREATE DATABASE cs-cart;

GRANT ALL PRIVILEGES ON cs-cart.* TO root@localhost IDENTIFIED BY 'YOURPASS';

If you dont already have your cs-cart Database file you can run the installation.

The file must be in .sql format. It can not be compressed in a .zip or .tar.gz file.

  1. Upload the SQL file to the server.Type this this command:
  2. mysql -p -u username database_name < file.sql

     To Export MYSQL DB

mysqldump -p -u username database_name > dbname.sql
Advertisements