How To Setup a Web Server Using Debian or Ubuntu and Install LiteCart
(For Debian 11, Debian 12, Debian 13, Ubuntu 22, Ubuntu 23, and Ubuntu 24.)
For this guide we will assume you have a minimal install of a Debian based server installation.
The following commands can be copy pasted to your SSH or Terminal window.
Please note: Depending on your Linux distribution the version of PHP might differ from this guide.
# Become root (or you will need to pass `sudo` before every command)
# (If a password is not previously set, first set a root password with the command: sudo passwd root)
su
# Set timezone (if not already)
timedatectl set-timezone Europe/London
# Make sure that the OS and software is up to date
sudo apt update && sudo apt full-upgrade -y
# Install some server software and components
apt install curl nano unzip apache2 libapache2-mod-php mariadb-server php php-common php-cli php-fpm php-apcu php-curl php-dom php-gd php-imagick php-mysql php-simplexml php-mbstring php-intl php-zip php-xml
# Install additional locales if missing (Example: language-pack-{language_code})
apt -y install language-pack-es language-pack-fr language-pack-de
# Grab installed PHP version
ENV PHP_VERSION=$(ls /etc/php/*/fpm/ | grep -o '[0-9]\+\.[0-9]\+' | head -n 1)
# Enable some required Apache modules
a2enmod proxy_fcgi rewrite headers setenvif ssl
# Enable the PHP-FPM configuration for PHP 8.3
a2enconf "php${PHP_VERSION}-fpm"
# Secure your MySQL/MariaDB server
# Alternatively run a handsfree command for securing MariaDB/MySQL:
# mysql -uroot <<END
# ALTER USER 'root'@'localhost' IDENTIFIED BY '{desired_root_password_here}';
# GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
# DROP USER IF EXISTS ''@'localhost';
# DROP DATABASE IF EXISTS test;
# FLUSH PRIVILEGES;
# END
mysql_secure_installation
# Let's make som changes to the PHP configuration
# Note: For Ubuntu 22 the config directory is /etc/php/8.1/
# Note: For Debian 12.9 it's /etc/php/8.3/
sed -ri 's/;?memory_limit\s*=\s*[^\s]*/memory_limit = 256M/' "/etc/php/${PHP_VERSION}/apache2/php.ini"
sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' "/etc/php/${PHP_VERSION}/apache2/php.ini"
sed -ri 's/;?date\.timezone\s*=\s*[^\s]*/date.timezone = Europe\/London/g' "/etc/php/${PHP_VERSION}/apache2/php.ini"
# Allow incoming HTTP traffic through the Firewall
ufw allow http https
# Make sure services are enabled, and start them
RUN systemctl enable "php${PHP_VERSION}-fpm" apache2 mariadb
RUN systemctl start "php${PHP_VERSION}-fpm" apache2 mariadb
Install LiteCart
Go to the document root for your site, remove default index page, download the LiteCart web installer and setting the correct permissions:
# Create a directory for LiteCart
mkdir /var/www/litecart
# Create a MySQL database for LiteCart
read -p "New database name: " newdb_name
read -p "New database user: " newdb_user
read -sp "Password for database user '$newdb_user': " newdb_password
mysql -u root -p <<END
CREATE DATABASE $newdb_name;
CREATE USER '$newdb_user'@'localhost' IDENTIFIED BY '$newdb_password';
GRANT ALL PRIVILEGES ON $newdb_name.* TO '$newdb_user'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
END
# Create an Apache virtualhost configuration directive for mydomain.tld pointing to the folder of LiteCart
cat <<EOL > /etc/apache2/sites-enabled/mydomain.tld.conf
<VirtualHost *:80>
ServerName mydomain.tld
ServerAlias www.mydomain.tld
ServerAdmin webmaster@mydomain.tld
DocumentRoot /var/www/litecart
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/litecart>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EOL
# Go to the document root for your site
cd /var/www/litecart
# Install LiteCart
bash -c "$(curl https://raw.githubusercontent.com/litecart/installer/master/cli/install.sh)"
# Change owner of the files to apache
chown -R www-data:www-data ./
# When the LiteCart web installation is completed, do some cleanup:
rm -Rf install/
Install Let's Encrypt free SSL certificate
# Install certbot
apt install certbot python3-certbot-apache
# Install an SSL Certificate using Let's Encrypt
certbot --apache -w /var/www/litecart -d mydomain.tld
# Install a virtualhost for HTTPS connections
cat <<EOL > /etc/apache2/sites-enabled/mydomain.tld-ssl.conf
<VirtualHost *:443>
ServerName mydomain.tld
ServerAlias www.mydomain.tld
ServerAdmin webmaster@mydomain.tld
DocumentRoot /var/www/litecart
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/litecart>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# SSL Configuration
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/mydomain.tld/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.tld/privkey.pem
</VirtualHost>
EOL
# Restart Apache web server for SSL
systemctl restart apache2
Now you have LiteCart installed with SSL. Happy times.
Install additional PHP versions
# Install Ondrej/PHP PPA: This PPA provides newer PHP versions
add-apt-repository ppa:ondrej/php && apt update
# Install PHP 8.3
apt install -y php8.3 php8.3-common php8.3-cli php8.3-fpm php8.3-apcu php8.3-curl php8.3-dom php8.3-gd php8.3-imagick php8.3-mysql php8.3-simplexml php8.3-mbstring php8.3-intl php8.3-zip php8.3-xml
# Install PHP 8.4
apt install -y php8.4 php8.4-common php8.4-cli php8.4-fpm php8.4-apcu php8.4-curl php8.4-dom php8.4-gd php8.4-imagick php8.4-mysql php8.4-simplexml php8.4-mbstring php8.4-intl php8.4-zip php8.4-xml
# Set the default PHP version
update-alternatives --config php
update-alternatives --config php-cli
# Disable PHP 8.2 Apache module
a2disconf php8.3-fpm
# Enable apache module for PHP 8.4
a2enconf php8.4-fpm
# Restart apache
systemctl restart apache2
Troubleshoot Problems
See if there are any problems logged.
journalctl --since "1 hour ago"