How To Setup a Web Server Using Debian or Ubuntu and Install LiteCart

Pealkiri

Muudatusi pole

Permalink

Muudatusi pole

Sisukord

OldNew
5For this guide we will assume you have a minimal install of a *Debian* based server installation. 5For this guide we will assume you have a minimal install of a *Debian* based server installation.
6The following commands can be copy pasted to your SSH or Terminal window. 6The following commands can be copy pasted to your SSH or Terminal window.
7 7
8Please note: Depending on your Linux distribution the version of PHP might differ from this guide.
9
8```sh 10```sh
9# Become root (if not already) 11# Become root (or you will need to pass `sudo` before every command)
12# (If a password is not previously set, first set a root password with the command: sudo passwd root)
10su 13su
11 14
12# Set timezone (if not already) 15# Set timezone (if not already)
13timedatectl set-timezone Europe/London 16timedatectl set-timezone Europe/London
14 17
15# Make sure that the OS is up to date 18# Make sure that the OS and software is up to date
16apt update 19sudo apt update && sudo apt full-upgrade -y
17apt upgrade
18 20
19# Install some basic utilities (in case we don't have it) 21# Install some server software and components
20apt -y install curl nano unzip 22apt install 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
21
22# Install the server software
23apache2 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
24 23
25# Install additional locales if missing (Example: language-pack-{language_code}) 24# Install additional locales if missing (Example: language-pack-{language_code})
26apt -y install language-pack-es language-pack-fr language-pack-de 25apt -y install language-pack-es language-pack-fr language-pack-de
27 26
27# Grab installed PHP version
28ENV PHP_VERSION=$(ls /etc/php/*/fpm/ | grep -o '[0-9]\+\.[0-9]\+' | head -n 1)
29
28# Enable some required Apache modules 30# Enable some required Apache modules
29a2enmod rewrite headers setenvif 31a2enmod proxy_fcgi rewrite headers setenvif ssl
30 32
31# Secure your MySQL/MariaDB server (Recommend that you use the default options, just set the password) 33# Enable the PHP-FPM configuration for PHP 8.3
34a2enconf "php${PHP_VERSION}-fpm"
35
36# Secure your MySQL/MariaDB server
37# Alternatively run a handsfree command for securing MariaDB/MySQL:
38# mysql -uroot <<END
39# ALTER USER 'root'@'localhost' IDENTIFIED BY '{desired_root_password_here}';
40# GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
41# DROP USER IF EXISTS ''@'localhost';
42# DROP DATABASE IF EXISTS test;
43# FLUSH PRIVILEGES;
44# END
32mysql_secure_installation 45mysql_secure_installation
33 46
34# Alternatively run a handsfree command for securing MariaDB/MySQL 47# Let's make som changes to the PHP configuration
35mysql -uroot <<END
36ALTER USER 'root'@'localhost' IDENTIFIED BY '{desired_root_password_here}';
37GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
38DROP USER IF EXISTS ''@'localhost';
39DROP DATABASE IF EXISTS test;
40FLUSH PRIVILEGES;
41END
42
43# Let's make som changes to the PHP configuration (See appendix PHP Configuration)
44# Note: For Ubuntu 22 the config directory is /etc/php/8.1/ 48# Note: For Ubuntu 22 the config directory is /etc/php/8.1/
45sed -ri 's/;?memory_limit\s*=\s*[^\s]*/memory_limit = 256M/' /etc/php/8.3/apache2/php.ini 49# Note: For Debian 12.9 it's /etc/php/8.3/
46sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' /etc/php/8.3/apache2/php.ini 50sed -ri 's/;?memory_limit\s*=\s*[^\s]*/memory_limit = 256M/' "/etc/php/${PHP_VERSION}/apache2/php.ini"
47sed -ri 's/;?date\.timezone\s*=\s*[^\s]*/date.timezone = Europe\/Stockholm/g' /etc/php/8.3/apache2/php.ini 51sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' "/etc/php/${PHP_VERSION}/apache2/php.ini"
48 52sed -ri 's/;?date\.timezone\s*=\s*[^\s]*/date.timezone = Europe\/London/g' "/etc/php/${PHP_VERSION}/apache2/php.ini"
49# Edit edit the default apache virtualhost configuration (or create a new one e.g. mydomain.tld.conf)
50# Refer to Appendix: Virtual Host Configuration
51nano /etc/apache2/sites-enabled/000-default.conf
52 53
53# Allow incoming HTTP traffic through the Firewall 54# Allow incoming HTTP traffic through the Firewall
54ufw allow http 55ufw allow http https
55ufw allow https
56 56
57# Restart Apache to apply all changes 57# Make sure services are enabled, and start them
58systemctl restart apache2 58RUN systemctl enable "php${PHP_VERSION}-fpm" apache2 mariadb
59RUN systemctl start "php${PHP_VERSION}-fpm" apache2 mariadb
59``` 60```
60 61
61## Install LiteCart 62## Install LiteCart
63Go to the document root for your site, remove default index page, download the LiteCart web installer and setting the correct permissions: 64Go to the document root for your site, remove default index page, download the LiteCart web installer and setting the correct permissions:
64 65
65```sh 66```sh
66# Create the LiteCart database in MariaDB/MySQL 67# Create a directory for LiteCart
68mkdir /var/www/litecart
69
70# Create a MySQL database for LiteCart
67read -p "New database name: " newdb_name 71read -p "New database name: " newdb_name
68read -p "New database user: " newdb_user 72read -p "New database user: " newdb_user
69read -sp "Password for database user '$newdb_user': " newdb_password 73read -sp "Password for database user '$newdb_user': " newdb_password
70 74
71mysql -u root -p -e "CREATE DATABASE $newdb_name; \ 75mysql -u root -p <<END
72CREATE USER '$newdb_user'@'localhost' IDENTIFIED BY '$newdb_password'; \ 76CREATE DATABASE $newdb_name;
73GRANT ALL PRIVILEGES ON $newdb_name.* TO '$newdb_user'@'localhost' WITH GRANT OPTION; \ 77CREATE USER '$newdb_user'@'localhost' IDENTIFIED BY '$newdb_password';
74FLUSH PRIVILEGES;" 78GRANT ALL PRIVILEGES ON $newdb_name.* TO '$newdb_user'@'localhost' WITH GRANT OPTION;
79FLUSH PRIVILEGES;
80END
81
82
83# Create an Apache virtualhost configuration directive for mydomain.tld pointing to the folder of LiteCart
84cat <<EOL > /etc/apache2/sites-enabled/mydomain.tld.conf
85<VirtualHost *:80>
86 ServerName mydomain.tld
87 ServerAlias www.mydomain.tld
88 ServerAdmin webmaster@mydomain.tld
89 DocumentRoot /var/www/litecart
90
91 ErrorLog \${APACHE_LOG_DIR}/error.log
92 CustomLog \${APACHE_LOG_DIR}/access.log combined
93
94 <Directory /var/www/litecart>
95 Options FollowSymLinks
96 AllowOverride All
97 Require all granted
98 </Directory>
99</VirtualHost>
100EOL
75 101
76# Go to the document root for your site 102# Go to the document root for your site
77cd /var/www/html 103cd /var/www/litecart
78 104
79# Remove the default index page 105# Install LiteCart
80rm index.html 106bash -c "$(curl https://raw.githubusercontent.com/litecart/installer/master/cli/install.sh)"
81
82# Download the LiteCart web installer
83curl --output index.php https://raw.githubusercontent.com/litecart/installer/master/web/index.php
84 107
85# Change owner of the files to apache 108# Change owner of the files to apache
86chown -R www-data:www-data ./ 109chown -R www-data:www-data ./
87
88##########################################################################
89# Open your browser and visit your website to begin installing LiteCart. #
90# https://myvirtualhost.tld/ #
91##########################################################################
92 110
93# When the LiteCart web installation is completed, do some cleanup: 111# When the LiteCart web installation is completed, do some cleanup:
94rm -Rf install/ 112rm -Rf install/
95``` 113```
96 114
97## Install Let's Encrypt free SSL certificates 115## Install Let's Encrypt free SSL certificate
98 116
99```sh 117```sh
100# Install snapd package installer (in case we don't have it) 118# Install certbot
101apt install certbot python3-certbot-apache 119apt install certbot python3-certbot-apache
102 120
103# To issue a SSL certificate run the following: 121# Install an SSL Certificate using Let's Encrypt
104certbot --apache -d myvirtualhost.tld 122certbot --apache -w /var/www/litecart -d mydomain.tld
123
124# Install a virtualhost for HTTPS connections
125cat <<EOL > /etc/apache2/sites-enabled/mydomain.tld-ssl.conf
126<VirtualHost *:443>
127 ServerName mydomain.tld
128 ServerAlias www.mydomain.tld
129 ServerAdmin webmaster@mydomain.tld
130 DocumentRoot /var/www/litecart
131
132 ErrorLog \${APACHE_LOG_DIR}/error.log
133 CustomLog \${APACHE_LOG_DIR}/access.log combined
134
135 <Directory /var/www/litecart>
136 Options FollowSymLinks
137 AllowOverride All
138 Require all granted
139 </Directory>
140
141 # SSL Configuration
142 SSLEngine on
143 SSLCertificateFile /etc/letsencrypt/live/mydomain.tld/fullchain.pem
144 SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.tld/privkey.pem
145</VirtualHost>
146EOL
147
148# Restart Apache web server for SSL
149systemctl restart apache2
105``` 150```
106
107NOTE: 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.
108 151
109Now you have LiteCart installed with SSL. Happy times. 152Now you have LiteCart installed with SSL. Happy times.
110 153
111## Appendixes 154## Install additional PHP versions
112 155
156```bash
157# Install Ondrej/PHP PPA: This PPA provides newer PHP versions
158add-apt-repository ppa:ondrej/php && apt update
113 159
114### PHP Configuration 160# Install PHP 8.3
161apt install -y php8.3 php8.3-common php8.3-cli php8.3-fpm php8.3-apcu php8.3-curl php8.3-dom php8.3-gd php8.3-imagick php8.3-mysql php8.3-simplexml php8.3-mbstring php8.3-intl php8.3-zip php8.3-xml
115 162
116Note: LiteCart doesn't need a lot of memory, but image resampling does. 163# Install PHP 8.4
164apt install -y php8.4 php8.4-common php8.4-cli php8.4-fpm php8.4-apcu php8.4-curl php8.4-dom php8.4-gd php8.4-imagick php8.4-mysql php8.4-simplexml php8.4-mbstring php8.4-intl php8.4-zip php8.4-xml
117 165
118**/etc/php/8.1/apache2/php.ini:** 166# Set the default PHP version
119```ini 167update-alternatives --config php
168update-alternatives --config php-cli
120 169
121... 170# Disable PHP 8.2 Apache module
122memory_limit = 256M 171a2disconf php8.3-fpm
123... 172
124upload_max_filesize = 64M 173# Enable apache module for PHP 8.4
125... 174a2enconf php8.4-fpm
126date.timezone = Europe/London 175
127... 176# Restart apache
177systemctl restart apache2
128``` 178```
129 179
130### Virtual Host Configuration 180Troubleshoot Problems
131 181
132**/etc/apache2/sites-enabled/000-default.conf:** 182```bash
133```conf 183journalctl --since "1 hour ago"
134
135<VirtualHost *:80>
136 ServerName myvirtualhost.tld;
137 ServerAdmin webmaster@localhost
138 DocumentRoot /var/www/html
139
140 ErrorLog ${APACHE_LOG_DIR}/error.log
141 CustomLog ${APACHE_LOG_DIR}/access.log combined
142
143 <Directory /var/www/html>
144 Options FollowSymLinks
145 AllowOverride All
146 Require all granted
147 </Directory>
148</VirtualHost>
149```184```

Edited by tim on 30 märts 2025 at 21:42

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.