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

This is a guide for for setting up a web server on Debian or Debian based Linux distributions like Ubuntu.

At the time of writing we used minimal install of Debian 12.

# Become root (or you will need to pass `sudo` before every command)
# (If this is not enabled. Set a root password first by the command: sudo passwd root)
su

# Make sure all sources and software on the device is up to date
apt update && apt -y full-upgrade && apt -y autoremove

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

# Enable some required Apache modules
a2enmod proxy_fcgi rewrite headers setenvif ssl

# Enable the PHP-FPM configuration for PHP 8.2
a2enconf php8.2-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
sed -ri 's/;?memory_limit\s*=\s*[^\s]*/memory_limit = 256M/' /etc/php/8.2/apache2/php.ini
sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' /etc/php/8.2/apache2/php.ini
sed -ri 's/;?date\.timezone\s*=\s*[^\s]*/date.timezone = Europe\/London/g' /etc/php/8.2/apache2/php.ini

Install LiteCart

# 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)"

# 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

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.

Revisioni

Articoli modificati di recente
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.