How To Setup a Web Server Using Debian or Ubuntu and Install LiteCart
Pealkiri
Muudatusi polePermalink
Muudatusi poleSisukord
Old | New | ||
---|---|---|---|
5 | For this guide we will assume you have a minimal install of a *Debian* based server installation. | 5 | For this guide we will assume you have a minimal install of a *Debian* based server installation. |
6 | The following commands can be copy pasted to your SSH or Terminal window. | 6 | The following commands can be copy pasted to your SSH or Terminal window. |
7 | 7 | ||
8 | Please 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) | ||
10 | su | 13 | su |
11 | 14 | ||
12 | # Set timezone (if not already) | 15 | # Set timezone (if not already) |
13 | timedatectl set-timezone Europe/London | 16 | timedatectl 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 |
16 | apt update | 19 | sudo apt update && sudo apt full-upgrade -y |
17 | apt upgrade | ||
18 | 20 | ||
19 | # Install some basic utilities (in case we don't have it) | 21 | # Install some server software and components |
20 | apt -y install curl nano unzip | 22 | apt 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 | ||
23 | 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 | ||
24 | 23 | ||
25 | # Install additional locales if missing (Example: language-pack-{language_code}) | 24 | # Install additional locales if missing (Example: language-pack-{language_code}) |
26 | apt -y install language-pack-es language-pack-fr language-pack-de | 25 | apt -y install language-pack-es language-pack-fr language-pack-de |
27 | 26 | ||
27 | # Grab installed PHP version | ||
28 | ENV 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 |
29 | a2enmod | 31 | a2enmod 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 |
34 | a2enconf "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 | ||
32 | mysql_secure_installation | 45 | mysql_secure_installation |
33 | 46 | ||
34 | # Alternatively run a handsfree command for securing MariaDB/MySQL | 47 | # Let's make som changes to the PHP configuration |
35 | mysql -uroot <<END | ||
36 | ALTER USER 'root'@'localhost' IDENTIFIED BY '{desired_root_password_here}'; | ||
37 | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION; | ||
38 | DROP USER IF EXISTS ''@'localhost'; | ||
39 | DROP DATABASE IF EXISTS test; | ||
40 | FLUSH PRIVILEGES; | ||
41 | END | ||
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/ |
45 | sed -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/ |
46 | sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' /etc/php/8.3/apache2/php.ini | 50 | sed -ri 's/;?memory_limit\s*=\s*[^\s]*/memory_limit = 256M/' "/etc/php/${PHP_VERSION}/apache2/php.ini" |
47 | sed -ri 's/;?date\.timezone\s*=\s*[^\s]*/date.timezone = Europe\/Stockholm/g' /etc/php/8.3/apache2/php.ini | 51 | sed -ri 's/;?upload_max_filesize\s*=\s*[^\s]*/upload_max_filesize = 64M/' "/etc/php/${PHP_VERSION}/apache2/php.ini" |
48 | 52 | sed -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 | ||
51 | nano /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 |
54 | ufw allow http | 55 | ufw allow http https |
55 | ufw allow https | ||
56 | 56 | ||
57 | # Restart Apache to apply all changes | 57 | # Make sure services are enabled, and start them |
58 | systemctl restart apache2 | 58 | RUN systemctl enable "php${PHP_VERSION}-fpm" apache2 mariadb |
59 | RUN systemctl start "php${PHP_VERSION}-fpm" apache2 mariadb | ||
59 | ``` | 60 | ``` |
60 | 61 | ||
61 | ## Install LiteCart | 62 | ## Install LiteCart |
63 | Go to the document root for your site, remove default index page, download the LiteCart web installer and setting the correct permissions: | 64 | Go 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 |
68 | mkdir /var/www/litecart | ||
69 | |||
70 | # Create a MySQL database for LiteCart | ||
67 | read -p "New database name: " newdb_name | 71 | read -p "New database name: " newdb_name |
68 | read -p "New database user: " newdb_user | 72 | read -p "New database user: " newdb_user |
69 | read -sp "Password for database user '$newdb_user': " newdb_password | 73 | read -sp "Password for database user '$newdb_user': " newdb_password |
70 | 74 | ||
71 | mysql -u root -p -e "CREATE DATABASE $newdb_name; \ | 75 | mysql -u root -p <<END |
72 | CREATE USER '$newdb_user'@'localhost' IDENTIFIED BY '$newdb_password'; \ | 76 | CREATE DATABASE $newdb_name; |
73 | GRANT ALL PRIVILEGES ON $newdb_name.* TO '$newdb_user'@'localhost' WITH GRANT OPTION; \ | 77 | CREATE USER '$newdb_user'@'localhost' IDENTIFIED BY '$newdb_password'; |
74 | FLUSH PRIVILEGES;" | 78 | GRANT ALL PRIVILEGES ON $newdb_name.* TO '$newdb_user'@'localhost' WITH GRANT OPTION; |
79 | FLUSH PRIVILEGES; | ||
80 | END | ||
81 | |||
82 | |||
83 | # Create an Apache virtualhost configuration directive for mydomain.tld pointing to the folder of LiteCart | ||
84 | cat <<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> | ||
100 | EOL | ||
75 | 101 | ||
76 | # Go to the document root for your site | 102 | # Go to the document root for your site |
77 | cd /var/www/ | 103 | cd /var/www/litecart |
78 | 104 | ||
79 | # Remove the default index page | 105 | # Install LiteCart |
80 | rm index.html | 106 | bash -c "$(curl https://raw.githubusercontent.com/litecart/installer/master/cli/install.sh)" |
81 | |||
82 | # Download the LiteCart web installer | ||
83 | curl --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 |
86 | chown -R www-data:www-data ./ | 109 | chown -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: |
94 | rm -Rf install/ | 112 | rm -Rf install/ |
95 | ``` | 113 | ``` |
96 | 114 | ||
97 | ## Install Let's Encrypt free SSL certificate | 115 | ## Install Let's Encrypt free SSL certificate |
98 | 116 | ||
99 | ```sh | 117 | ```sh |
100 | # Install | 118 | # Install certbot |
101 | apt install certbot python3-certbot-apache | 119 | apt 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 |
104 | certbot --apache -d myvirtualhost.tld | 122 | certbot --apache -w /var/www/litecart -d mydomain.tld |
123 | |||
124 | # Install a virtualhost for HTTPS connections | ||
125 | cat <<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> | ||
146 | EOL | ||
147 | |||
148 | # Restart Apache web server for SSL | ||
149 | systemctl restart apache2 | ||
105 | ``` | 150 | ``` |
106 | |||
107 | 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. | ||
108 | 151 | ||
109 | Now you have LiteCart installed with SSL. Happy times. | 152 | Now you have LiteCart installed with SSL. Happy times. |
110 | 153 | ||
111 | ## | 154 | ## Install additional PHP versions |
112 | 155 | ||
156 | ```bash | ||
157 | # Install Ondrej/PHP PPA: This PPA provides newer PHP versions | ||
158 | add-apt-repository ppa:ondrej/php && apt update | ||
113 | 159 | ||
114 | ### PHP Configuration | 160 | # Install PHP 8.3 |
161 | apt 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 | ||
116 | Note: LiteCart doesn't need a lot of memory, but image resampling does. | 163 | # Install PHP 8.4 |
164 | apt 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 | 167 | update-alternatives --config php |
168 | update-alternatives --config php-cli | ||
120 | 169 | ||
121 | ... | 170 | # Disable PHP 8.2 Apache module |
122 | memory_limit = 256M | 171 | a2disconf php8.3-fpm |
123 | ... | 172 | |
124 | upload_max_filesize = 64M | 173 | # Enable apache module for PHP 8.4 |
125 | ... | 174 | a2enconf php8.4-fpm |
126 | date.timezone = Europe/London | 175 | |
127 | ... | 176 | # Restart apache |
177 | systemctl restart apache2 | ||
128 | ``` | 178 | ``` |
129 | 179 | ||
130 | 180 | Troubleshoot Problems | |
131 | 181 | ||
132 | **/etc/apache2/sites-enabled/000-default.conf:** | 182 | ```bash |
133 | ```conf | 183 | journalctl --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