1 | | 1 | # How to setup an OpenLiteSpeed webserver running LiteCart
|
---|
| | 2 |
|
---|
| | 3 | 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.
|
---|
| | 4 |
|
---|
| | 5 | ```bash
|
---|
| | 6 | # Become root (or you will need to pass `sudo` before every command)
|
---|
| | 7 | # (If a password is not previously set, first set a root password with the command: sudo passwd root)
|
---|
| | 8 | su
|
---|
| | 9 |
|
---|
| | 10 | # Set timezone (if not already)
|
---|
| | 11 | timedatectl set-timezone Europe/London
|
---|
| | 12 |
|
---|
| | 13 | # Make sure that the OS and software is up to date
|
---|
| | 14 | apt update && apt full-upgrade -y
|
---|
| | 15 |
|
---|
| | 16 | # Install some server components
|
---|
| | 17 | apt install curl nano unzip
|
---|
| | 18 |
|
---|
| | 19 | # Install OpenLiteSpeed repository
|
---|
| | 20 | bash -c "$(curl https://repo.litespeed.sh)"
|
---|
| | 21 |
|
---|
| | 22 | # Install OpenLiteSpeed, MariaDB and PHP 8.3
|
---|
| | 23 | apt install -y openlitespeed mariadb-server lsphp83 lsphp83-common lsphp83-apcu lsphp83-curl lsphp83-imagick lsphp83-mysql lsphp83-intl
|
---|
| | 24 |
|
---|
| | 25 | # List which PHP modules for LiteSpeed that are installed
|
---|
| | 26 | /usr/local/lsws/lsphp83/bin/php -m
|
---|
| | 27 |
|
---|
| | 28 | # List additional php modules that can be installed
|
---|
| | 29 | apt search lsphp |more
|
---|
| | 30 |
|
---|
| | 31 | # Install additional locales if missing (Example: language-pack-{language_code})
|
---|
| | 32 | apt -y install language-pack-es language-pack-fr language-pack-de
|
---|
| | 33 |
|
---|
| | 34 | # Set admin password for OpenLiteSpeed
|
---|
| | 35 | /usr/local/lsws/admin/misc/admpass.sh
|
---|
| | 36 |
|
---|
| | 37 | # Make LiteSpeed listen to incoming traffic on port 80 instead of 8080
|
---|
| | 38 | sed -ri 's/\*:8088/*:80/' "/usr/local/lsws/conf/httpd_config.conf"
|
---|
| | 39 |
|
---|
| | 40 | # Let's make som changes to the PHP configuration
|
---|
| | 41 | sed -ri 's/;?memory_limit\s*=\s*[^\s]*/memory_limit = 256M/' "/usr/local/lsws/lsphp83/etc/php/8.3/litespeed/php.ini"
|
---|
| | 42 | sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' "/usr/local/lsws/lsphp83/etc/php/8.3/litespeed/php.ini"
|
---|
| | 43 | sed -ri 's/;?date\.timezone\s*=\s*[^\s]*/date.timezone = Europe\/London/g' "/usr/local/lsws/lsphp83/etc/php/8.3/litespeed/php.ini"
|
---|
| | 44 |
|
---|
| | 45 | # Start MariaDB database service and enable autostart after reboot
|
---|
| | 46 | systemctl start mariadb
|
---|
| | 47 | systemctl enable mariadb
|
---|
| | 48 |
|
---|
| | 49 | # Secure your MySQL/MariaDB server
|
---|
| | 50 | # Alternatively run a handsfree command for securing MariaDB/MySQL:
|
---|
| | 51 | # mysql -uroot <<END
|
---|
| | 52 | # ALTER USER 'root'@'localhost' IDENTIFIED BY '{desired_root_password_here}';
|
---|
| | 53 | # GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
|
---|
| | 54 | # DROP USER IF EXISTS ''@'localhost';
|
---|
| | 55 | # DROP DATABASE IF EXISTS test;
|
---|
| | 56 | # FLUSH PRIVILEGES;
|
---|
| | 57 | # END
|
---|
| | 58 | mysql_secure_installation
|
---|
| | 59 |
|
---|
| | 60 | # Start web server service and enable autostart after reboot
|
---|
| | 61 | systemctl start lshttpd
|
---|
| | 62 | systemctl enable lshttpd
|
---|
| | 63 |
|
---|
| | 64 | # If you have the UFW firewall installed, allow some incoming traffic
|
---|
| | 65 | ufw allow ssh http https 7080/tcp
|
---|
| | 66 |
|
---|
| | 67 | # Connect to http://your-server-ip:7080/ using your web browser to access the OpenLiteSpeed's web admin interface
|
---|
| | 68 | # From there you can setup your virtual host configurations
|
---|
| | 69 | ```
|
---|
| | 70 |
|
---|
| | 71 | # Setup a New Website
|
---|
| | 72 |
|
---|
| | 73 | ```bash
|
---|
| | 74 | # Add the domain name to the hosts file for local resolving
|
---|
| | 75 | # (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.)
|
---|
| | 76 | cat <<EOF | tee -a /etc/hosts > /dev/null
|
---|
| | 77 | 127.0.0.1 mywebsite.tld
|
---|
| | 78 | 127.0.0.1 www.mywebsite.tld
|
---|
| | 79 | EOF
|
---|
| | 80 |
|
---|
| | 81 | # Create some necessary directories for your website
|
---|
| | 82 | mkdir -p /var/www/mywebsite.tld/public_html
|
---|
| | 83 | mkdir /var/www/mywebsite.tld/logs
|
---|
| | 84 | mkdir /usr/local/lsws/conf/vhosts/mywebsite.tld
|
---|
| | 85 |
|
---|
| | 86 | # Create a virtualhost configuration
|
---|
| | 87 | cat <<EOF > /usr/local/lsws/conf/vhosts/mywebsite.tld/vhconf.conf
|
---|
| | 88 | docRoot /var/www/mywebsite.tld/public_html
|
---|
| | 89 | vhDomain mywebsite.tld
|
---|
| | 90 | vhAliases www.mywebsite.tld
|
---|
| | 91 | adminEmails webmaster@mywebsite.tld
|
---|
| | 92 | enableGzip 1
|
---|
| | 93 |
|
---|
| | 94 | errorlog /var/www/mywebsite.tld/logs/error.log {
|
---|
| | 95 | useServer 1
|
---|
| | 96 | logLevel ERROR
|
---|
| | 97 | rollingSize 10M
|
---|
| | 98 | keepDays 30
|
---|
| | 99 | }
|
---|
| | 100 |
|
---|
| | 101 | accesslog /var/www/mywebsite.tld/logs/access.log {
|
---|
| | 102 | useServer 1
|
---|
| | 103 | rollingSize 10M
|
---|
| | 104 | }
|
---|
| | 105 |
|
---|
| | 106 | rewrite {
|
---|
| | 107 | enable 1
|
---|
| | 108 | autoLoadHtaccess 1
|
---|
| | 109 | }
|
---|
| | 110 |
|
---|
| | 111 | context / {
|
---|
| | 112 | location $DOC_ROOT/
|
---|
| | 113 | allowBrowse 0
|
---|
| | 114 | indexFiles index.html, index.php
|
---|
| | 115 | }
|
---|
| | 116 | EOF
|
---|
| | 117 |
|
---|
| | 118 | # Set owner and permissions for configurations
|
---|
| | 119 | chown -R lsadm:nogroup /usr/local/lsws/conf/vhosts/mywebsite.tld/
|
---|
| | 120 | chmod -R 0750 /usr/local/lsws/conf/vhosts/mywebsite.tld/
|
---|
| | 121 |
|
---|
| | 122 | # Add a mapping of the virtualhost config to main config
|
---|
| | 123 | cat <<EOF >> /usr/local/lsws/conf/httpd_config.conf
|
---|
| | 124 | virtualhost mywebsite.tld {
|
---|
| | 125 | vhRoot /usr/local/lsws/conf/vhosts/mywebsite.tld/
|
---|
| | 126 | configFile /usr/local/lsws/conf/vhosts/mywebsite.tld/vhconf.conf
|
---|
| | 127 | }
|
---|
| | 128 | EOF
|
---|
| | 129 |
|
---|
| | 130 | # Add virtualhost to mapping of listening ports
|
---|
| | 131 | cat <<EOF >> /usr/local/lsws/conf/httpd_config.conf
|
---|
| | 132 | listener Mywebsite80 {
|
---|
| | 133 | address mywebsite.tld:80, mywebsite.tld:80
|
---|
| | 134 | secure 0
|
---|
| | 135 | map mywebsite.tld mywebsite.tld
|
---|
| | 136 | }
|
---|
| | 137 | EOF
|
---|
| | 138 |
|
---|
| | 139 | # Restart web server
|
---|
| | 140 | systemctl restart lsws
|
---|
| | 141 |
|
---|
| | 142 | # Download LiteCart's web installer to the document root of your virtualhost directory
|
---|
| | 143 | curl --output /var/www/mywebsite.tld/public_html/index.php https://raw.githubusercontent.com/litecart/installer/master/web/index.php
|
---|
| | 144 |
|
---|
| | 145 | # Set file permissions to LiteSpeed's web user
|
---|
| | 146 | chown -R nobody:nogroup /var/www/mywebsite.tld/public_html
|
---|
| | 147 |
|
---|
| | 148 | # Now try accessing your website using your browser, and you should see the LiteCart Installer
|
---|
| | 149 | # Example: https:///mywebsite.tld/
|
---|
| | 150 | ```
|
---|
| | 151 |
|
---|
| | 152 | # Enable Secure HTTPS and Create a Certificate
|
---|
| | 153 |
|
---|
| | 154 | ```bash
|
---|
| | 155 | # Install certbot
|
---|
| | 156 | apt install certbot python3-certbot-apache
|
---|
| | 157 |
|
---|
| | 158 | # Generate an SSL Certificate using Let's Encrypt
|
---|
| | 159 | certbot certonly --webroot -w /var/www/mywebsite.tld -d mywebsite.tld
|
---|
| | 160 |
|
---|
| | 161 | # Make LiteSpeed listen to incoming secure traffic on port 443
|
---|
| | 162 | cat <<EOF >> /usr/local/lsws/conf/httpd_config.conf
|
---|
| | 163 | listener Mywebsite443 {
|
---|
| | 164 | address mywebsite.tld:443, mywebsite.tld:443,
|
---|
| | 165 | secure 1
|
---|
| | 166 | keyFile /etc/letsencrypt/live/mywebsite.tld/privkey.pem
|
---|
| | 167 | certFile /etc/letsencrypt/live/mywebsite.tld/fullchain.pem
|
---|
| | 168 | map mywebsite.tld mywebsite.tld
|
---|
| | 169 | }
|
---|
| | 170 | EOF
|
---|
| | 171 |
|
---|
| | 172 | # Restart Apache web server for SSL
|
---|
| | 173 | systemctl restart lsws
|
---|
| | 174 | ``` |
---|