How to Install PrestaShop with Apache and Let's Encrypt SSL on CentOS 8
PrestaShop is an open-source shopping cart written in the PHP used to create and manage your online business. It provides a simple and easy-to-use interface that helps you to launch your online store in a minimal time. It provides a lot of features including, a user-friendly interface, multiple payment gateways (PayPal, Google Checkout), mobile-responsive design, free support, multi-lingual, analytic, reporting and more.
In this post, we will show you how to install PrestaShop with Apache and a free Let's Encrypt SSL certificate on CentOS 8.
Prerequisites
- A server running CentOS 8.
- A valid domain name pointed with your 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 not installed you can install it with other PHP extensions using the following command:
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 required packages, edit the php.ini file and change some default settings:
nano /etc/php.ini
Change the following lines:
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 service and enable them to start at system reboot:
systemctl start httpd
systemctl start mariadb
systemctl enable httpd
systemctl enable mariadb
At this point, the LAMP server is installed in your server.
Create a Database for PrestaShop
PrestaShop uses a MySQL/MariaDB database to store their data. So you will need to create a database and suer for PrestaShop.
First, log in to MariaDB with the following command:
mysql
Once login, create a database and user with the following command:
MariaDB [(none)]> CREATE DATABASE prestashopdb;
MariaDB [(none)]> CREATE USER 'prestashopuser'@'localhost' IDENTIFIED BY 'securepassword';
Next, grant all the privileges to the prestashopdb with the following command:
MariaDB [(none)]> GRANT ALL PRIVILEGES ON prestashopdb. * TO 'prestashopuser'@'localhost';
Next, flush the privileges and exit from the MariaDB with the following command:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Once you are finished, you can proceed to the next step.
Install PrestaShop
Next, you will need to download the latest version of PrestaShop from their official download page. You can download it with the following command:
wget https://download.prestashop.com/download/releases/prestashop_1.7.7.3.zip
Once the download is completed, unzip the downloaded file to the Apache web root directory using the following command:
unzip prestashop_1.7.7.3.zip -d /var/www/html/prestashop
Next, set proper ownership to the prestashop directory using the following command:
chown -R apache:apache /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/httpd/conf.d/prestashop.conf
Add the following lines:
<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>
Save and close the file when you are done. Next, restart the Apache service to apply the changes:
systemctl restart httpd
Next, verify the status of the Apache service using the following command:
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 you are finished, you can proceed to the next step.
Configure Firewall
Next, you will need to allow ports 80 and 443 through firewall. You can allow them with the following command:
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
Next, reload the firewall to apply the changes:
firewall-cmd --reload
Once you are finished, you can proceed to the next step.
Access PrestaShop
Now, open your web browser and access the PrestaShop web interface using the URL http://prestashop.example.com. You will be redirected to the following page:
Select your language and click on the Next button. You should see the following page:
Agree the License agreement and click on the Next button. You should see the following page:
Provide your shop name, country information, account information and click on the Next button. You should see the following page:
Provide your database name, database username, password and click on the Next button. Once the installation has been finished, you should see the following page:
Click on the Manage your store button. You should see the following page:
Now, remove the installation folder with the following command:
rm -rf /var/www/html/prestashop/install
Next, click on the PrestaShop admin URL. You should see the following page:
Provide your admin username, password and click on the LOG IN button. You should see the PrestaShop dashboard in the following page:
Secure PrestaShop with Let's Encrypt SSL
Next, you will need to install the Certbot client to install the Let's Encrypt SSL for PrestaShop. You can install it with the following command:
dnf install letsencrypt python3-certbot-apache
Next, obtain and install an SSL certificate for your lets domain with the following command:
certbot --apache -d prestashop.example.com
You will be asked to provide your email address and accept the term 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 access your website securely using the URL https://prestashop.example.com. If you like to do redirects by device, have a look here.
Conclusion
Congratulations! you have successfully installed PrestaShop with Apache and Let's Encrypt SSL on CentOS 8. You can now add your product to PrestaShop and start selling online. Feel free to ask me if you have any questions.