How to install PrestaShop with Apache and encrypt SSL on CentOS 8

How to install PrestaShop with Apache and encrypt SSL on CentOS 8

PrestaShop is an open source shopping cart written in PHP to create and manage your online business. It provides a simple and easy-to-use interface that can help you launch your online store in the shortest possible time. It provides many features, including a user-friendly interface, multiple payment gateways (PayPal, Google Checkout), mobile responsive design, free support, multiple languages, analysis, reports, etc.

In this article, we will show you how to install PrestaShop with Apache and free Let’s Encrypt SSL certificate on Apache CentOS 8.

prerequisites

  • Server running CentOS 8.
  • A valid domain name pointing to the server IP.
  • A root password is configured on your server.

Install LAMP server

Before starting, the LAMP server must be installed in your server. If it is not installed, you can use the following command to install it along with other PHP extensions:

dnf install httpd mariadb-server php php-cli php-bcmath php-mysqli php-gd php-pdo php-xmlrpc php-intl php-posix php-json php-curl php-zip unzip -y

After installing all the necessary packages, edit the php.ini file and change some default settings:

nano /etc/php.ini

Change the following line:

max_input_vars = 3000
post_max_size = 64M
upload_max_filesize = 64M
max_execution_time = 600
memory_limit = 256M
date.timezone = Asia/Kolkata

Save and close the file, then start the Apache and MariaDB services and enable them to start when the system reboots:

systemctl start httpdsystemctl start mariadbsystemctl enable httpdsystemctl enable mariadb

At this point, the LAMP server has been installed in your server.

Create a database for PrestaShop

PrestaShop uses MySQL/MariaDB database to store its data. Therefore, you will need to create a database and suer for PrestaShop.

First, log in to MariaDB using the following command:

mysql

After logging in, use the following commands to create the database and user:

MariaDB [(none)]> CREATE DATABASE prestashopdb;MariaDB [(none)]> CREATE USER 'prestashopuser'@'localhost' IDENTIFIED BY 'securepassword';

Next, use the following command to grant all privileges to prestashopdb:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON prestashopdb. * TO 'prestashopuser'@'localhost';

Next, refresh the privileges and exit from MariaDB using the following command:

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

Once completed, you can proceed to the next step.

Install PrestaShop

Next, you need to download the latest version of PrestaShop from its official download page. You can download it with the following command:

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

After the download is complete, use the following command to extract the downloaded file to the Apache Web root directory:

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

Next, use the following command to set the proper ownership to the prestashop directory:

chown -R apache:apache /var/www/html/prestashop

Once completed, 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/httpd/conf.d/prestashop.conf

Add the following line:

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

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

    ErrorLog /var/log/httpd/prestashop-error_log
    CustomLog /var/log/httpd/prestashop-access_log common
</VirtualHost>

When finished, save and close the file. Next, restart the Apache service to apply the changes:

systemctl restart httpd

Next, use the following command to verify the status of the Apache service:

systemctl status httpd

You should get the following output:

? httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           ??php-fpm.conf
   Active: active (running) since Wed 2021-04-07 01:04:19 EDT; 2h 2min ago
     Docs: man:httpd.service(8)
 Main PID: 47841 (httpd)
   Status: "Total requests: 313; Idle/Busy workers 100/0;Requests/sec: 0.0425; Bytes served/sec: 1.2KB/sec"
    Tasks: 278 (limit: 12524)
   Memory: 35.9M
   CGroup: /system.slice/httpd.service
           ??47841 /usr/sbin/httpd -DFOREGROUND
           ??47843 /usr/sbin/httpd -DFOREGROUND
           ??47844 /usr/sbin/httpd -DFOREGROUND
           ??47845 /usr/sbin/httpd -DFOREGROUND
           ??47846 /usr/sbin/httpd -DFOREGROUND
           ??48061 /usr/sbin/httpd -DFOREGROUND

Apr 07 01:04:19 centos8 systemd[1]: Stopped The Apache HTTP Server.
Apr 07 01:04:19 centos8 systemd[1]: Starting The Apache HTTP Server...

Once completed, you can proceed to the next step.

Configure firewall

Next, you will need to allow ports 80 and 443 to pass through the firewall. You can allow them with the following command:

firewall-cmd --zone=public --permanent --add-service=httpfirewall-cmd --zone=public --permanent --add-service=https

Next, reload the firewall to apply the changes:

firewall-cmd --reload

Once completed, you can proceed to the next step.

Enter PrestaShop

Now, open your web browser and use the URL to access the PrestaShop web interface. https://prestashop.example.com. You will be redirected to the following page:

Choose a language

Choose your language and click Next Button. You should see the following page:

agreement

Agree to the license agreement and click Next Button. You should see the following page:

Shop details

Administrator account

Provide your store name, country/region information, account information, and click Next Button.You should see the following page: Ads

Database configuration

Provide your database name, database user name, password, and click Next Button. After the installation is complete, you should see the following page:

Prestashop installation completed successfully

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

Remove installer

Now, delete the installation folder using the following command:

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

Next, click PrestaShop administrator URL. You should see the following page:

Prestashop administrator login

Provide your administrator username and password, and click log in Button. You should see the PrestaShop dashboard in the following page:

Prestashop dashboard

Let’s encrypt SSL to protect PrestaShop

Next, you will need to install the Certbot client to install “Let’s Encrypt SSL” for PrestaShop. You can use the following command to install:

dnf install letsencrypt python3-certbot-apache

Next, use the following command to obtain and install an SSL certificate for your let domain:

certbot --apache -d prestashop.example.com

You will be asked to provide your email address and accept the terms of service:

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. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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
Account registered.
Requesting a certificate for prestashop.example.com
Performing the following challenges:
http-01 challenge for prestashop.example.com
Waiting for verification.
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/httpd/conf.d/prestashop.conf
Redirecting all traffic on port 80 to ssl in /etc/httpd/conf.d/prestashop.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://prestashop.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email: [email protected]).


IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/prestashop.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/prestashop.example.com/privkey.pem
   Your certificate will expire on 2021-06-09. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again with the "certonly" option. To non-interactively
   renew *all* of your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

You can now use the URL to safely visit your website https://prestashop.example.com.

in conclusion

Congratulations! You have successfully installed PrestaShop and Let’s Encrypt SSL on CentOS 8 on Apache. Now you can add products to PrestaShop and start selling online. If you have any questions, please feel free to ask me.

Related Posts