How to setup a web server using Debian/Ubuntu and install LiteCart

For this guide we will assume you have a minimal install of a Debian 11 or Ubuntu 22.x based server installation. The following commands can be copy pasted to your SSH or Terminal window.

# Become root if not already
su

# Make sure that the OS is up to date
apt update
apt upgrade

# Install additional locales if missing (Example: language-pack-{language_code})
apt -y install language-pack-es language-pack-fr language-pack-de

# Install some basic utils and software
apt -y 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

# Enable some required Apache modules
a2enmod rewrite headers proxy_fcgi setenvif

# Secure your MySQL/MariaDB server (Recommend that you use the default options, just set the password)
mysql_secure_installation

# 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

# Let's make som changes to the PHP configuration (See appendix PHP Configuration)
sed -ri 's/;?memory_limit\s*=\s*[^\s]*/memory_limit = 256M/' /etc/php/8.1/apache2/php.ini
sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' /etc/php/8.1/apache2/php.ini
sed -ri 's/;?date\.timezone\s*=\s*[^\s]*/date.timezone = Europe\/Stockholm/g' /etc/php/8.1/apache2/php.ini

# Create the LiteCart database in MariaDB/MySQL
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 -e "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;"

# Edit edit the default apache virtualhost configuration (or create a new one e.g. mydomain.tld.conf)
# Refer to Appendix: Virtual Host Configuration
nano /etc/apache2/sites-enabled/000-default.conf

# Restart Apache to apply all changes
systemctl restart apache2

Install LiteCart

Go to the document root for your site, remove default index page, download the LiteCart web installer and setting the correct permissions:

# Go to the document root for your site
cd /var/www/html

# Remove the default index page
rm index.html

# Download the LiteCart web installer
curl --output index.php https://raw.githubusercontent.com/litecart/installer/master/web/index.php

# Change owner of the files to apache
chown -R www-data:www-data ./

##########################################################################
# Open your browser and visit your website to begin installing LiteCart. #
# https://myvirtualhost.tld/                                              #
##########################################################################

# When the LiteCart web installation is completed, do some cleanup:
rm -Rf install/

Install Let's Encrypt free SSL certificates

# Install snapd package installer
apt install -y snapd
snap install core

# Makes sure that you got the latest snap core:
snap refresh core

# Now we install certbot
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot

# To issue a SSL certificate run the following:
certbot --apache -d shop.mydomain.se

NOTE: You need to have a hostname configured in the Apache conf and the host record pointing to your server in the DNSes, otherwise it will fail.

Now you have LiteCart installed with SSL. Happy times.

Appendixes

PHP Configuration

Note: LiteCart doesn't need a lot of memory, but image resampling does.

/etc/php/8.1/apache2/php.ini:


...
memory_limit = 256M
...
upload_max_filesize = 64M 
...
date.timezone = Europe/Stockholm
...

Virtual Host Configuration

/etc/apache2/sites-enabled/000-default.conf:


<VirtualHost *:80>
    ServerName mydomain.tld;
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/html>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Revisions

Recently Edited Articles