How To Setup a Minimal Debian Web Server

Tytuł

OldNew
1How To Install Litecart Debian 11 Minimal1How To Setup a Minimal Debian Web Server

Bezpośrednie łącze

OldNew
1how_to_install_litecart_debian_11_minimal1how_to_install_litecart_on_debian_ubuntu

zawartość

OldNew
1# How to setup a web server using Debian/Ubuntu and install LiteCart1# How to setup a minimal web server using Debian/Ubuntu and install LiteCart
22
3This guide should work on other Linux dists to. The server is a basic Debian 11 minimal install (only SSH installed):3This is a guide for for setting up a web server on Debian or Debian based Linux distributions like Ubuntu.
44
5```bash5At the time of writing we used minimal install of Debian 12.
6# Become root if not already6
7su7```bash
88# Become root (if not already)
9# Make sure that the OS is up to date9# (If no password is set. Set a root password first by the command: sudo passwd root)
10apt update apt upgrade10su
1111
12# Install some basic utils and software12# Make sure all sources and software on the device is up to date
13apt install -y curl nano unzip apache2 libapache2-mod-php mariadb-server \13apt 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-xml15# Install some basic utils and software
1616apt 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 modules17
18a2enmod rewrite headers proxy_fcgi setenvif18# Enable some required Apache modules
1919a2enmod proxy_fcgi rewrite headers setenvif ssl
20# Secure your MySQL/MariaDB server (Recommend that you use the defaultoptions, just set the password)20
21mysql_secure_installation21# Enable the PHP-FPM configuration for PHP 8.2
2222a2enconf php8.2-fpm
23# Alternatively run a handsfree command for securing MariaDB/MySQL23
24mysql -uroot24# 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
33mysql_secure_installation
34
35# Let's make som changes to the PHP configuration
36sed -ri 's/;?memory_limit\s*=\s*[^\s]*/memory_limit = 256M/' /etc/php/8.2/apache2/php.ini
37sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' /etc/php/8.2/apache2/php.ini
38sed -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
45mkdir /var/www/litecart
46
47# Create a MySQL database for LiteCart
48read -p "New database name: " newdb_name
49read -p "New database user: " newdb_user
50read -sp "Password for database user '$newdb_user': " newdb_password
51
52mysql -u root -p <<END
53CREATE DATABASE $newdb_name; \
54CREATE USER '$newdb_user'@'localhost' IDENTIFIED BY '$newdb_password'; \
55GRANT ALL PRIVILEGES ON $newdb_name.* TO '$newdb_user'@'localhost' WITH GRANT OPTION; \
56FLUSH PRIVILEGES;
57END
58
59# Create an Apache virtualhost configuration directive for mydomain.tld pointing to the folder of LiteCart
60cat <<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>
76EOL
77
78# Go to the document root for your site
79cd /var/www/litecart
80
81# Install LiteCart
82bash -c "$(curl https://raw.githubusercontent.com/litecart/installer/master/cli/install.sh)"
83
84# When the LiteCart web installation is completed, do some cleanup:
85rm -Rf install/
86```
87
88## Install Let's Encrypt free SSL certificate
89
90```sh
91# Install certbot
92apt install certbot python3-certbot-apache
93
94# Install an SSL Certificate using Let's Encrypt
95certbot --apache -w /var/www/litecart -d mydomain.tld
96
97# Install a virtualhost for HTTPS connections
98cat <<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>
119EOL
120
121# Restart Apache web server for SSL
122systemctl restart apache2
123```
124
125NOTE: 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
127Now you have LiteCart installed with SSL. Happy times.

Edytowane przez tim w 20 lut 2025 o 00:25

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.