How to Install Prestashop with Apache and Let's Encrypt SSL on Debian 11

PrestaShop is a free, open-source, efficient, and innovative e-commerce solution that helps you to sell your products online. It is a powerful and adaptable e-commerce CMS that provides all features needed to create an online store. With PrestaShop, you can manage inventory, product catalogs, shipping, invoicing, and many more. It provides 5000+ modules, themes, and supports many different payment gateway systems like PayPal, Google Checkout, etc.

In this post, we will show you how to install PrestaShop with Apache web server and Let's Encrypt SSL on Debian 11.

Prerequisites

  • A server running Debian 11.
  • A valid domain name is pointed to your server IP.
  • A root password is configured on the server.

Install Apache, MariaDB, and PHP

First, you will need to install the Apache, MariaDB, PHP and other PHP extensions to your server. You can install all of them with the following command:

apt-get install apache2 mariadb-server libapache2-mod-php php php-gd php-mbstring php-mysql php-curl php-xml php-cli php-intl php-zip unzip -y

Once all the packages are installed, edit the php.ini file and tweak some settings:

nano /etc/php/7.4/apache2/php.ini

Change the following lines:

memory_limit = 256M
post_max_size = 64M
upload_max_filesize = 32M
date.timezone = UTC

Save and close the file then restart the Apache service to apply the changes:

systemctl restart apache2

Create a Database for PrestaShop

First, you will need to secure the MariaDB installation and set a MariaDB root password. You can do it by running the mysql_secure_installation script:

mysql_secure_installation

Answer all the questions as shown below:

Enter current password for root (enter for none): 
Switch to unix_socket authentication [Y/n] Y
Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Next, log in to the MariaDB shell with the following command:

mysql -u root -p

Provide your MariaDB root password then create a user and database for PrestaShop using the following command:

MariaDB [(none)]> CREATE DATABASE prestadb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON prestadb.* TO 'prestauser'@'localhost' IDENTIFIED BY 'yourpass';

Next, flush the privileges and exit from the MariaDB with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Download PrestaShop

Next, go to the PrestaShop website and download the latest version of PrestaShop using the following command:

wget https://download.prestashop.com/download/releases/prestashop_1.7.7.7.zip

Once the download is completed, unzip the downloaded file with the following command:

unzip prestashop_1.7.7.7.zip

Next, unzip the PrestaShop again inside the Apache web root directory using the following command:

unzip prestashop.zip -d /var/www/html/prestashop

Next, set proper ownership and permissions to the PrestaShop directory:

chown -R www-data:www-data /var/www/html/prestashop/ 
chmod -R 755 /var/www/html/prestashop

Once you are finished, you can proceed to the next step.

Configure Apache for PrestaShop

Next, you will need to create an Apache virtual host configuration file for PrestaShop. You can create it with the following command:

nano /etc/apache2/sites-available/prestashop.conf

Add the following lines:

<VirtualHost *:80>
      ServerAdmin [email protected]
      ServerName presta.example.com
      DocumentRoot /var/www/html/prestashop


     <Directory /var/www/html/prestashop>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/your-domain.com_error.log
     CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined

</VirtualHost>

Save and close the file then enable the Apache rewrite module and activate the Apache virtual host using the following command:

a2enmod rewrite
a2ensite prestashop

Finally, restart the Apache service to apply the changes:

systemctl restart apache2

You can also check the Apache service with the following command:

systemctl status apache2

You should get the following output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-08-27 06:15:23 UTC; 5min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 17540 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
   Main PID: 14330 (apache2)
      Tasks: 6 (limit: 2341)
     Memory: 16.5M
        CPU: 332ms
     CGroup: /system.slice/apache2.service
             ??14330 /usr/sbin/apache2 -k start
             ??17544 /usr/sbin/apache2 -k start
             ??17545 /usr/sbin/apache2 -k start
             ??17546 /usr/sbin/apache2 -k start
             ??17547 /usr/sbin/apache2 -k start
             ??17548 /usr/sbin/apache2 -k start

Aug 27 06:15:23 debian11 systemd[1]: Starting The Apache HTTP Server...

Access PrestaShop Web UI

At this point, PrestaShop is installed and configured. You can now access it using the URL http://presta.example.com. You should see the following page:

Select your language and click on the Next button. You should see the following page:

Accept the terms and conditions then click on the Next button. You should see the following page:

Provide your store name, admin account details, and click on the Next button. You should see the following page:

Provide your database settings and click on the Next button to start the installation. Once the installation has been completed, you should see the following page:

Click on the Manage your store button. You should see the following page:

Next, open your terminal and remove the installation folder:

rm -rf /var/www/html/prestashop/install

Now, access the PrestaShop admin interface using the URL shown in the previous screen. You should see the PrestaShop login screen:

Provide your admin username, password and click on the Log in button. You should see the PrestaShop dashboard on the following page:

Secure PrestaShop with Let's Encrypt SSL

First, you will need to install the Certbot Let's Encrypt client to download and install the SSL certificate for your domain.

You can install it with the following command:

apt-get install python3-certbot-apache -y

Once installed, you can run the following command to install the Let's Encrypt Certificate for your domain prestashop.example.com.

certbot --apache -d presta.example.com

Durring the installation, you will be asked to provide your email address and accept the term of service as shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for prestashop.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/prestashop-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/prestashop-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/prestashop-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Next, type 2 and hit Enter to download and install a free SSL certificate for your domain. Once the installation has been completed successfully. You should get the following output:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/prestashop.conf to ssl vhost in /etc/apache2/sites-available/
prestashop-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://prestashop.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=prestashop.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Conclusion

In the above guide, we explained how to install PrestaShop with Apache and Let's Encrypt SSL certificate on Debian 11. You can now host your online store easily with PrestaShop. Feel free to ask me if you have any questions.

Share this page:

Suggested articles

0 Comment(s)

Add comment