keepcalculator

06 Numbers and Powers

How to Install Zen Cart on a VPS with Apache/Nginx

Card No. 06·46444 · Updated · Standard formula, shown below

This guide walks you through installing Zen Cart on a Virtual Private Server (VPS) with either Apache or Nginx as the web server, a MySQL/MariaDB database, and essential security hardening. By the end, you’ll have a functional online store ready for configuration.

What You’ll Need

  • A VPS running a Linux distribution (Ubuntu 22.04/24.04, Debian 11/12, or CentOS/Rocky Linux 9) with root or sudo access.
  • A domain name pointed to your server’s IP address (optional but recommended for production).
  • SSH client (e.g., PuTTY on Windows, Terminal on macOS/Linux).
  • Basic familiarity with the command line.

Step-by-Step

  1. Update the server
    Log in via SSH and update the package lists and existing packages:
    sudo apt update && sudo apt upgrade -y (Debian/Ubuntu) or sudo dnf update -y (RHEL/Rocky).
  2. Install a web server
    Choose one:
    Apache: sudo apt install apache2 -y
    Nginx: sudo apt install nginx -y
    Enable the service to start on boot: sudo systemctl enable apache2 or sudo systemctl enable nginx.
  3. Install PHP and required extensions
    Zen Cart requires PHP 7.4 or newer (8.0+ recommended). Install PHP along with common extensions:
    sudo apt install php php-cli php-fpm php-mysql php-gd php-curl php-zip php-xml php-mbstring php-intl php-bcmath -y
    For Apache, also install libapache2-mod-php.
  4. Install MySQL/MariaDB
    sudo apt install mariadb-server -y
    Secure the installation: sudo mysql_secure_installation – set a root password, remove anonymous users, disallow remote root login, and remove test databases.
  5. Create a database and user
    Log into MySQL: sudo mysql
    Run:
    CREATE DATABASE zencart;
    CREATE USER 'zencartuser'@'localhost' IDENTIFIED BY 'StrongPasswordHere';
    GRANT ALL PRIVILEGES ON zencart.* TO 'zencartuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
  6. Download Zen Cart
    Navigate to your web root (e.g., /var/www/html for Apache, /usr/share/nginx/html for Nginx, or better a dedicated directory like /var/www/zencart).
    Download the latest release from the official Zen Cart GitHub repository:
    cd /var/www
    sudo git clone https://github.com/zencart/zencart.git zencart
    Or download a stable ZIP from the official site and extract it.
  7. Set permissions
    Zen Cart needs write access to certain directories. Set ownership to the web server user (www-data for Apache, nginx for Nginx) and set permissions:
    sudo chown -R www-data:www-data /var/www/zencart
    sudo chmod -R 755 /var/www/zencart
    Make the cache and logs directories writable: sudo chmod -R 777 /var/www/zencart/cache /var/www/zencart/logs (temporary, tighten later).
  8. Configure the web server
    Apache: Create a virtual host file /etc/apache2/sites-available/zencart.conf with a DocumentRoot pointing to /var/www/zencart. Enable mod_rewrite and the site:
    sudo a2enmod rewrite
    sudo a2ensite zencart
    sudo systemctl reload apache2
    Nginx: Create a server block in /etc/nginx/sites-available/zencart with root /var/www/zencart, index index.php, and a location block for PHP-FPM (socket or TCP). Enable it and reload Nginx:
    sudo ln -s /etc/nginx/sites-available/zencart /etc/nginx/sites-enabled/
    sudo systemctl reload nginx
  9. Run the installer
    Open your browser and go to http://your-domain.com/zc_install (or the appropriate path). Follow the on-screen steps: accept license, check server requirements, enter database details (host: localhost, user: zencartuser, password: your password, database: zencart), and set admin credentials. Complete the installation.
  10. Secure the installation
    After installation, delete the zc_install directory: sudo rm -rf /var/www/zencart/zc_install. Also remove or rename the docs directory if present.
  11. Enable HTTPS (SSL/TLS)
    Install Certbot:
    sudo apt install certbot python3-certbot-apache (or -nginx)
    Obtain a free certificate: sudo certbot --apache or sudo certbot --nginx – follow the prompts. This automatically configures HTTPS and auto-renewal.
  12. Additional security hardening
    Set strict file permissions: sudo chmod 644 /var/www/zencart/*.php and sudo chmod 755 /var/www/zencart for directories. Ensure the cache and logs directories are not writable by the web server after installation (change to 755). Configure a firewall (UFW) to allow only SSH, HTTP, and HTTPS: sudo ufw allow 22,80,443/tcp then sudo ufw enable.

Common Mistakes

  • Using the wrong PHP version – Zen Cart may not work on PHP 8.3+ if extensions are missing.
  • Forgetting to enable the mod_rewrite module in Apache, causing 404 errors on product pages.
  • Not setting correct file ownership – the web server user must own the files, not root.
  • Leaving the zc_install directory accessible – a serious security risk.
  • Using a weak database password.

Tips

  • Use a dedicated subdomain like store.yourdomain.com for easier management.
  • Set up a regular backup cron job for the database and files.
  • Enable OPcache in PHP for better performance.
  • Use a strong admin password and change it periodically.
  • Keep Zen Cart and PHP updated regularly.

Troubleshooting

Blank page after installation – Check PHP error logs (/var/log/apache2/error.log or /var/log/nginx/error.log). Often a missing PHP extension or a permissions issue.

404 errors on product pages – For Apache, ensure mod_rewrite is enabled and the .htaccess file exists in the Zen Cart root. For Nginx, you need to add a rewrite rule to the server block: location / { try_files $uri $uri/ /index.php?$args; }

Cannot connect to database – Verify the database host is localhost and the user has privileges. Test with mysql -u zencartuser -p.

HTTPS not working – Check that your firewall allows port 443 and that the SSL certificate is valid. Run sudo certbot certificates to see status.

Admin login redirects to HTTP – Update the configure.php files in /includes and /admin/includes to use HTTPS URLs.

Frequently Asked Questions

Can I use SQLite instead of MySQL?

No, Zen Cart requires MySQL or MariaDB. SQLite is not supported.

What PHP version is best for Zen Cart?

PHP 8.0 to 8.2 is recommended. PHP 8.3 may work but test thoroughly.

How do I change the admin directory name?

Rename the admin folder to something unique (e.g., admin_secret) and update the DIR_WS_ADMIN constant in admin/includes/configure.php.

Is it safe to use the default ‘admin’ username?

No, create a unique admin username during installation to reduce brute-force risk.

How do I back up my store?

Use mysqldump for the database and tar for files. Example: mysqldump -u root -p zencart > backup.sql and tar -czf zencart_files.tar.gz /var/www/zencart.

Why is my site slow?

Enable caching in Zen Cart (Admin > Configuration > Cache), enable OPcache, and consider using a CDN for static assets.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →