This step by step tutorial will show you how to install Zen Cart with Nginx on a Debian 8 VPS. Zen Cart is an open source PHP based shopping cart software. This tutorial was tested and written for a Debian 8 VPS, but it should work on any Debian based Linux distribution.
Make sure your package list and the OS packages are up to date by running the following commands:
sudo apt-get update sudo apt-get upgrade
Stop and remove Apache2 service:
sudo service apache2 stop sudo apt-get remove apache2 sudo apt-get autoremove
Install Nginx on your virtual server:
sudo apt-get update sudo apt-get install nginx
Configure nginx to start on boot:
sudo update-rc.d -f nginx defaults
Install PHP and PHP modules required by Zen Cart:
sudo apt-get install php5 php5-cli php5-fpm php5-mysql php5-gd php5-mcrypt sudo php5enmod mcrypt
Download the latest version of Zen Cart at https://www.zen-cart.com/getit and upload it to the /opt directory on your server:
cd /opt/ wget http://downloads.sourceforge.net/project/zencart/CURRENT%20-%20Zen%20Cart%201.5.x%20Series/zen-cart-v1.5.4-12302014.zip unzip zen-cart-v1.5.4-12302014.zip mv zen-cart-v1.5.4-12302014 /var/www/zen-cart/
Order an SSL certificate for your e-commerce website. Save the SSL certificate and its private key to files named ‘file.crt’ and ‘private.key’ respectively and upload them to /etc/nginx directory.
Remove the default Nginx server block, create a new Nginx configuration file and add the following virtual block for your domain name:
rm /etc/nginx/sites-enabled/default
vi /etc/nginx/sites-available/your-domain.com.conf
and add the following lines:
server {
listen 80;
# If you have an SSL certificate, uncomment the 3 lines below:
# listen 443 ssl;
# ssl_certificate /etc/nginx/file.crt;
# ssl_certificate_key /etc/nginx/private.key;
server_name your-domain.com www.your-domain.com;
root /var/www/your-domain.com;
index index.html index.htm index.php index.cgi index.pl index.xhtml;
error_page 400 /error/400.html;
error_page 401 /error/401.html;
error_page 403 /error/403.html;
error_page 404 /error/404.html;
error_page 405 /error/405.html;
error_page 500 /error/500.html;
error_page 502 /error/502.html;
error_page 503 /error/503.html;
access_log /var/log/nginx/your-domain.com-access.log;
error_log /var/log/nginx/your-domain.com-error.log;
charset en_us.UTF-8;
## Disable .htaccess and other hidden files
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
# expires max on static content
location ~* ^.+\.(jpg|jpeg|gif)$ {
access_log off;
expires 30d;
}
# Inaccessible locations
location ~ /includes/.*\.php$ { return 403; }
location ~ /backups { return 403; }
location ~ /download { return 403; }
location ~ /email { return 403; }
location ~ /media { return 403; }
location ~ /logs { return 403; }
# Locations only images should be served from
location ~ /sqld { try_files nothing.txt @imagesonly; location ~ \.php$ { return 403; } }
location ~ /images { try_files nothing.txt @imagesonly; location ~ \.php$ { return 403; } }
location ~ /editors { try_files nothing.txt @imagesonly; location ~ \.php$ { return 403; } }
location @imagesonly {
types {
image/gif gif;
image/jpeg jpeg jpg;
image/png png;
}
default_type application/octet-stream;
}
location /shop/
{
location ~ -p-(?<id>[0-9]+)\.html$ { rewrite ^ /shop/index.php?main_page=product_info&products_id=$id; }
location ~ -c-(?<id>.*).html$ { rewrite ^ /shop/index.php?main_page=index&cPath=$id; }
location ~ -m-(?<id>[0-9]+).html$ { rewrite ^ /shop/index.php?main_page=index&manufacturers_id=$id; }
location ~ -pi-(?<id>[0-9]+).html$ { rewrite ^ /shop/index.php?main_page=popup_image&pID=$id; }
location ~ -pr-(?<id>[0-9]+).html$ { rewrite ^ /shop/index.php?main_page=product_reviews&products_id=$id; }
location ~ -pri-(?<id>[0-9]+).html$ { rewrite ^ /shop/index.php?main_page=product_reviews_info&products_id=$id; }
location ~ -ezp-(?<id>[0-9]+).html$ { rewrite ^ /shop/index.php?main_page=page&id=$id; }
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}
}
Do not forget to replace your-domain.com with your actual domain name.
Enable the new Nginx configuration file:
ln -sf /etc/nginx/sites-available/your-domain.com.conf /etc/nginx/sites-enabled/
Open the /etc/php5/fpm/pool.d/www.conf file and change the ‘listen’ variable from:
listen = /var/run/php5-fpm.sock
to
listen = 127.0.0.1:9000;
Test the nginx configuration:
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Then, restart php5-fpm and Nginx services for the changes to take effect:
sudo service php5-fpm restart sudo service nginx restart
Set the proper permissions:
sudo chown www-data:www-data -R /var/www/your-domain.com/
Create a new MySQL database:
mysql -u root -p mysql> create database zencartdb; mysql> GRANT ALL PRIVILEGES ON zencartdb.* TO 'zencart'@'localhost' IDENTIFIED BY 'Y0UR-PASSW0RD'; mysql> flush privileges; mysql> quit
Open http://your-domain.com/zc_install/index.php using a web browser and follow the easy instructions: confirm your acceptance of the license terms , enter MySQL database username , password and database name, select ‘Enable SSL’ and ‘Enable SSL in Admin Area’ , click ‘Save System Settings’, enter store information, click ‘Save Store Settings’ and enter administrator username and password.
Reset permissions on ‘configure.php’ files located in the /admin/includes/ and /includes/ directories back to read-only mode:
chmod 440 /var/www/your-domain.com/admin/includes/configure.php chmod 440 /var/www/your-domain.com/includes/configure.php
Remove the /zc_install directory:
rm -rf /var/www/your-domain.com/zc_install
Also, rename the ‘admin’ directory to a name less likely to be ‘guessed’ by someone probing your website for illegitimate access.
That is it. The Zan Cart installation is complete.
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 Zen Cart with Nginx 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.