How to setup an OpenLiteSpeed webserver running LiteCart

LiteSpeed web server is a high performance drop in replacement for Apache2. This article will guide you into setting up a webserver running LiteCart with OpenLiteSpeed.

# 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
apt update && apt full-upgrade -y

# Install some server components
apt install curl nano unzip

# Install OpenLiteSpeed repository
bash -c "$(curl https://repo.litespeed.sh)"

# Install OpenLiteSpeed, MariaDB and PHP 8.3
apt install -y openlitespeed mariadb-server lsphp83 lsphp83-common lsphp83-apcu lsphp83-curl lsphp83-imagick lsphp83-mysql lsphp83-intl

# List which PHP modules for LiteSpeed that are installed
/usr/local/lsws/lsphp83/bin/php -m

# List additional php modules that can be installed
apt search lsphp |more

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

# Set admin password for OpenLiteSpeed
/usr/local/lsws/admin/misc/admpass.sh

# Make LiteSpeed listen to incoming traffic on port 80 instead of 8080
sed -ri 's/\*:8088/*:80/' "/usr/local/lsws/conf/httpd_config.conf"

# Let's make som changes to the PHP configuration
sed -ri 's/;?memory_limit\s*=\s*[^\s]*/memory_limit = 256M/' "/usr/local/lsws/lsphp83/etc/php/8.3/litespeed/php.ini"
sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' "/usr/local/lsws/lsphp83/etc/php/8.3/litespeed/php.ini"
sed -ri 's/;?date\.timezone\s*=\s*[^\s]*/date.timezone = Europe\/London/g' "/usr/local/lsws/lsphp83/etc/php/8.3/litespeed/php.ini"

# Start MariaDB database service and enable autostart after reboot
systemctl start mariadb
systemctl enable mariadb

# 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

# Start web server service and enable autostart after reboot
systemctl start lshttpd
systemctl enable lshttpd

# If you have the UFW firewall installed, allow some incoming traffic
ufw allow ssh
ufw allow http
ufw allow https
ufw allow 7080/tcp

# Connect to http://your-server-ip:7080/ using your web browser to access the OpenLiteSpeed's web admin interface
# From there you can setup your virtual host configurations

Setup a New Website

# Add the domain name to the hosts file for local resolving
# (For other machines and for the world to discover this website a public DNS record is required pointing the domain name to your machine's public WAN IP.)
cat <<EOF | tee -a /etc/hosts > /dev/null
127.0.0.1   mywebsite.tld
127.0.0.1   www.mywebsite.tld
EOF

# Create some necessary directories for your website
mkdir -p /var/www/mywebsite.tld/public_html
mkdir /var/www/mywebsite.tld/logs
mkdir /usr/local/lsws/conf/vhosts/mywebsite.tld

# Create a virtualhost configuration
cat <<EOF > /usr/local/lsws/conf/vhosts/mywebsite.tld/vhconf.conf
docRoot                   /var/www/mywebsite.tld/public_html
vhDomain                  mywebsite.tld
vhAliases                 www.mywebsite.tld
adminEmails               webmaster@mywebsite.tld
enableGzip                1

errorlog /var/www/mywebsite.tld/logs/error.log {
  useServer               1
  logLevel                ERROR
  rollingSize             10M
  keepDays                30
}

accesslog /var/www/mywebsite.tld/logs/access.log {
  useServer               1
  rollingSize             10M
}

rewrite  {
  enable                  1
  autoLoadHtaccess        1
}

context / {
  location                $DOC_ROOT/
  allowBrowse             0
  indexFiles              index.html, index.php
}
EOF

# Set owner and permissions for configurations
chown -R lsadm:nogroup /usr/local/lsws/conf/vhosts/mywebsite.tld/
chmod -R 0750 /usr/local/lsws/conf/vhosts/mywebsite.tld/

# Add a mapping of the virtualhost config to main config
cat <<EOF >> /usr/local/lsws/conf/httpd_config.conf
virtualhost mywebsite.tld {
    vhRoot /usr/local/lsws/conf/vhosts/mywebsite.tld/
    configFile /usr/local/lsws/conf/vhosts/mywebsite.tld/vhconf.conf
}
EOF

# Add virtualhost to mapping of listening ports
cat <<EOF >> /usr/local/lsws/conf/httpd_config.conf
listener Mywebsite80 {
    address mywebsite.tld:80, mywebsite.tld:80
    secure 0
    map mywebsite.tld mywebsite.tld
}
EOF

# Restart web server
systemctl restart lsws

# Download LiteCart's web installer to the document root of your virtualhost directory
curl --output /var/www/mywebsite.tld/public_html/index.php https://raw.githubusercontent.com/litecart/installer/master/web/index.php

# Set file permissions to LiteSpeed's web user
chown -R nobody:nogroup /var/www/mywebsite.tld/public_html

# Now try accessing your website using your browser, and you should see the LiteCart Installer
#  Example: https:///mywebsite.tld/

Enable Secure HTTPS and Create a Certificate

# Install certbot
apt install certbot python3-certbot-apache

# Generate an SSL Certificate using Let's Encrypt
certbot certonly --webroot -w /var/www/mywebsite.tld -d mywebsite.tld

# Make LiteSpeed listen to incoming secure traffic on port 443
cat <<EOF >> /usr/local/lsws/conf/httpd_config.conf
listener Mywebsite443 {
    address mywebsite.tld:443, mywebsite.tld:443, 
    secure 1
    keyFile /etc/letsencrypt/live/mywebsite.tld/privkey.pem
    certFile /etc/letsencrypt/live/mywebsite.tld/fullchain.pem
    map mywebsite.tld mywebsite.tld
}
EOF

# Restart Apache web server for SSL
systemctl restart lsws

Revisions

Recently Edited Articles
This website uses no cookies and no third party tracking technology. We think we can do better than others and really think about your privacy.