1 | # How to setup a web server using Debian/Ubuntu and install LiteCart | 1 | # How to setup a minimal web server using Debian/Ubuntu and install LiteCart
|
---|
2 | | 2 |
|
---|
3 | This guide should work on other Linux dists to. The server is a basic Debian 11 minimal install (only SSH installed): | 3 | This is a guide for for setting up a web server on Debian or Debian based Linux distributions like Ubuntu.
|
---|
4 | | 4 |
|
---|
5 | ```bash | 5 | At the time of writing we used minimal install of Debian 12.
|
---|
6 | # Become root if not already | 6 |
|
---|
7 | su | 7 | ```bash
|
---|
8 | | 8 | # Become root (if not already)
|
---|
9 | # Make sure that the OS is up to date | 9 | # (If no password is set. Set a root password first by the command: sudo passwd root)
|
---|
10 | apt update apt upgrade | 10 | su
|
---|
11 | | 11 |
|
---|
12 | # Install some basic utils and software | 12 | # Make sure all sources and software on the device is up to date
|
---|
13 | apt install -y curl nano unzip apache2 libapache2-mod-php mariadb-server \ | 13 | apt update && apt -y full-upgrade && apt -y autoremove
|
---|
14 | php php-common php-cli php-fpm php-apcu php-curl php-dom php-gd php-imagick \ | 14 |
|
---|
15 | php-mysql php-simplexml php-mbstring php-intl php-zip php-xml | 15 | # Install some basic utils and software
|
---|
16 | | 16 | apt install -y 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
|
---|
17 | # Enable some required Apache modules | 17 |
|
---|
18 | a2enmod rewrite headers proxy_fcgi setenvif | 18 | # Enable some required Apache modules
|
---|
19 | | 19 | a2enmod proxy_fcgi rewrite headers setenvif ssl
|
---|
20 | # Secure your MySQL/MariaDB server (Recommend that you use the defaultoptions, just set the password) | 20 |
|
---|
21 | mysql_secure_installation | 21 | # Enable the PHP-FPM configuration for PHP 8.2
|
---|
22 | | 22 | a2enconf php8.2-fpm
|
---|
23 | # Alternatively run a handsfree command for securing MariaDB/MySQL | 23 |
|
---|
24 | mysql -uroot | 24 | # Secure your MySQL/MariaDB server
|
---|
| | 25 | # Alternatively run a handsfree command for securing MariaDB/MySQL:
|
---|
| | 26 | # mysql -uroot <<END
|
---|
| | 27 | # ALTER USER 'root'@'localhost' IDENTIFIED BY '{desired_root_password_here}';
|
---|
| | 28 | # GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
|
---|
| | 29 | # DROP USER IF EXISTS ''@'localhost';
|
---|
| | 30 | # DROP DATABASE IF EXISTS test;
|
---|
| | 31 | # FLUSH PRIVILEGES;
|
---|
| | 32 | # END
|
---|
| | 33 | mysql_secure_installation
|
---|
| | 34 |
|
---|
| | 35 | # Let's make som changes to the PHP configuration
|
---|
| | 36 | sed -ri 's/;?memory_limit\s*=\s*[^\s]*/memory_limit = 256M/' /etc/php/8.2/apache2/php.ini
|
---|
| | 37 | sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' /etc/php/8.2/apache2/php.ini
|
---|
| | 38 | sed -ri 's/;?date\.timezone\s*=\s*[^\s]*/date.timezone = Europe\/London/g' /etc/php/8.2/apache2/php.ini
|
---|
| | 39 | ```
|
---|
| | 40 |
|
---|
| | 41 | ## Install LiteCart
|
---|
| | 42 |
|
---|
| | 43 | ```bash
|
---|
| | 44 | # Create a directory for LiteCart
|
---|
| | 45 | mkdir /var/www/litecart
|
---|
| | 46 |
|
---|
| | 47 | # Create a MySQL database for LiteCart
|
---|
| | 48 | read -p "New database name: " newdb_name
|
---|
| | 49 | read -p "New database user: " newdb_user
|
---|
| | 50 | read -sp "Password for database user '$newdb_user': " newdb_password
|
---|
| | 51 |
|
---|
| | 52 | mysql -u root -p <<END
|
---|
| | 53 | CREATE DATABASE $newdb_name; \
|
---|
| | 54 | CREATE USER '$newdb_user'@'localhost' IDENTIFIED BY '$newdb_password'; \
|
---|
| | 55 | GRANT ALL PRIVILEGES ON $newdb_name.* TO '$newdb_user'@'localhost' WITH GRANT OPTION; \
|
---|
| | 56 | FLUSH PRIVILEGES;
|
---|
| | 57 | END
|
---|
| | 58 |
|
---|
| | 59 | # Create an Apache virtualhost configuration directive for mydomain.tld pointing to the folder of LiteCart
|
---|
| | 60 | cat <<EOL > /etc/apache2/sites-enabled/mydomain.tld.conf
|
---|
| | 61 | <VirtualHost *:80>
|
---|
| | 62 | ServerName mydomain.tld
|
---|
| | 63 | ServerAlias www.mydomain.tld
|
---|
| | 64 | ServerAdmin webmaster@mydomain.tld
|
---|
| | 65 | DocumentRoot /var/www/litecart
|
---|
| | 66 |
|
---|
| | 67 | ErrorLog \${APACHE_LOG_DIR}/error.log
|
---|
| | 68 | CustomLog \${APACHE_LOG_DIR}/access.log combined
|
---|
| | 69 |
|
---|
| | 70 | <Directory /var/www/litecart>
|
---|
| | 71 | Options FollowSymLinks
|
---|
| | 72 | AllowOverride All
|
---|
| | 73 | Require all granted
|
---|
| | 74 | </Directory>
|
---|
| | 75 | </VirtualHost>
|
---|
| | 76 | EOL
|
---|
| | 77 |
|
---|
| | 78 | # Go to the document root for your site
|
---|
| | 79 | cd /var/www/litecart
|
---|
| | 80 |
|
---|
| | 81 | # Install LiteCart
|
---|
| | 82 | bash -c "$(curl https://raw.githubusercontent.com/litecart/installer/master/cli/install.sh)"
|
---|
| | 83 |
|
---|
| | 84 | # When the LiteCart web installation is completed, do some cleanup:
|
---|
| | 85 | rm -Rf install/
|
---|
| | 86 | ```
|
---|
| | 87 |
|
---|
| | 88 | ## Install Let's Encrypt free SSL certificate
|
---|
| | 89 |
|
---|
| | 90 | ```sh
|
---|
| | 91 | # Install certbot
|
---|
| | 92 | apt install certbot python3-certbot-apache
|
---|
| | 93 |
|
---|
| | 94 | # Install an SSL Certificate using Let's Encrypt
|
---|
| | 95 | certbot --apache -w /var/www/litecart -d mydomain.tld
|
---|
| | 96 |
|
---|
| | 97 | # Install a virtualhost for HTTPS connections
|
---|
| | 98 | cat <<EOL > /etc/apache2/sites-enabled/mydomain.tld-ssl.conf
|
---|
| | 99 | <VirtualHost *:443>
|
---|
| | 100 | ServerName mydomain.tld
|
---|
| | 101 | ServerAlias www.mydomain.tld
|
---|
| | 102 | ServerAdmin webmaster@mydomain.tld
|
---|
| | 103 | DocumentRoot /var/www/litecart
|
---|
| | 104 |
|
---|
| | 105 | ErrorLog \${APACHE_LOG_DIR}/error.log
|
---|
| | 106 | CustomLog \${APACHE_LOG_DIR}/access.log combined
|
---|
| | 107 |
|
---|
| | 108 | <Directory /var/www/litecart>
|
---|
| | 109 | Options FollowSymLinks
|
---|
| | 110 | AllowOverride All
|
---|
| | 111 | Require all granted
|
---|
| | 112 | </Directory>
|
---|
| | 113 |
|
---|
| | 114 | # SSL Configuration
|
---|
| | 115 | SSLEngine on
|
---|
| | 116 | SSLCertificateFile /etc/letsencrypt/live/mydomain.tld/fullchain.pem
|
---|
| | 117 | SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.tld/privkey.pem
|
---|
| | 118 | </VirtualHost>
|
---|
| | 119 | EOL
|
---|
| | 120 |
|
---|
| | 121 | # Restart Apache web server for SSL
|
---|
| | 122 | systemctl restart apache2
|
---|
| | 123 | ```
|
---|
| | 124 |
|
---|
| | 125 | 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.
|
---|
| | 126 |
|
---|
| | 127 | Now you have LiteCart installed with SSL. Happy times. |
---|