How to setup a RHEL web server and install LiteCart

For this tutorial we are assuming you already made a clean minimum installation of a RHEL 9.x OS (i.e. Red Hat Enterprise, Fedora, CentOS Stream, Alma Linux, or Rocky Linux).

Configure the Server

# Become root (or you will need to pass `sudo` before every command)
# (If a password is not previously set, first set a root password with the command: sudo passwd root)
su

# Make sure system and components are up to date
dnf upgrade --refresh -y && sudo dnf autoremove -y

# Install repository for extra packages like php-imagick
dnf -y install epel-release

# Install some server software and components
dnf -y install nano unzip httpd mod_ssl mariadb-server php php-bcmath php-intl php-apcu php-gd php-imagick php-json php-mysqlnd php-simplexml php-zip

# Install locales (Example: glibc-langpack-{language_code})
dnf -y install glibc-langpack-es
dnf -y install glibc-langpack-fr

# Change PHP distribution to version 8.3
dnf module switch-to php:8.3

# Start our new services
systemctl enable php-fpm httpd mariadb
systemctl start php-fpm httpd mariadb

# 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

# Allow outgoing traffic for the web server (SELinux)
setsebool -P httpd_can_network_connect 1
setsebool -P httpd_unified 1

# Allow incoming connections to the webserver through the firewall
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --list-all
firewall-cmd --reload

# Create a MySQL user, database, and grant privileges
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 -e "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;"

Install LiteCart

Go to the document root for your site, remove default index page, download the LiteCart web installer and setting the correct permissions:

# 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/httpd/conf.d/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)"

# Change owner of the files to apache
chown -R apache:apache ./

# When the LiteCart web installation is completed, do some cleanup:
rm -Rf install/

systemctl restart httpd

Install Let's Encrypt free SSL certificate


# Install certbot
dnf install certbot python3-certbot-apache -y

# Install an SSL Certificate using Let's Encrypt
certbot --apache -w /var/www/litecart -d mydomain.tld

# Append to virtualhost configuration to listen for HTTPS connections
cat <<EOL >> /etc/httpd/conf.d/mydomain.tld.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 httpd

Revisions

Recently Edited Articles
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.