How to Install PrestaShop on Almalinux 9

how to install prestashop on almalinux 9

Prestashop is a flexible and scalable eCommerce platform. Prestashop is one of the best open-source eCommerce CMS with out-of-the-box features.

The platform itself is written in PHP and released under Open Software License (OSL). People are using Prestashop mainly for their store, and the number of Prestashop users is growing.

In this tutorial, we will walk you through the Prestashop installation on Almalinux 9.

Prerequisites

  • An Almalinux 9 VPS
  • SSH root access or regular system user with sudo privileges

Step 1: Log in to your server via SSH

First, you will need to log in to your AlmaLinux 9 VPS via SSH as the root user:

ssh root@IP_Address -p Port_number

You must replace ‘IP_Address’ and ‘Port_number’ with your server’s respective IP address and SSH port number. Additionally, replace ‘root’ with the username of the system user with sudo privileges.

You can check whether you have the proper AlmaLinux version installed on your server with the following command:

# cat /etc/almalinux-release

It will return an output like this.

AlmaLinux release 9.1 (Lime Lynx)

Step 2. Install and Configure Nginx

We will use nginx as the web server, and the installation is easy.

# dnf install nginx -y

Then, create an nginx server block for our Prestashop website. Make sure to replace prestashop.yourdomain.com with your actual domain/subdomain name pointing to your server IP address.

# nano /etc/nginx/conf.d/prestashop.conf

Copy and paste the following into the file.

server {
    listen 80;
    root /var/www/html/prestashop;
    index  index.php index.html index.htm;
    server_name  prestashop.yourdomain.com;

    location / {
    rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
    rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
    rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
    rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
    rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1.jpg last;
    rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
    try_files $uri $uri/ /index.php?$args;
    }

    rewrite ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 last;

    rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;

    rewrite ^(/install(?:-dev)?/sandbox)/(.*) /$1/test.php last;

    #Change this block to your admin folder
    location /admin_CHANGE_ME {
        if (!-e $request_filename) {
            rewrite ^/.*$ /admin_CHANGE_ME/index.php last;
        }
    }

    # Source code directories
    location ~ ^/(app|bin|cache|classes|config|controllers|docs|localization|override|src|tests|tools|translations|travis-scripts|vendor|var)/ {
        deny all;
    }
    # Prevent exposing other sensitive files
    location ~ \.(yml|log|tpl|twig|sass)$ {
        deny all;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Save the file and exit.

Step 3. Install MariaDB and Create a Database

In this step, we are going to install the MariaDB server from the default Almalinux repository. To install the MariaDB server, execute this command:

# dnf install mariadb-server

Once installed, let’s run the MariaDB server and enable it to run on boot.

# systemctl enable --now mariadb

Now, we can proceed with creating a new database and database user for our Prestashop website.

mysql -e "create database prestashop"
mysql -e "grant all privileges on prestashop.* to prestashop@localhost identified by 'm0d1fyth15'"

Make sure you create a stronger database password; replace m0d1fyth15 in the command above with a stronger password.

Step 4. Install PHP

Since Prestashop 8 supports PHP 8.0 and the said PHP version is shipped with AlmaLinux 9, we can install it directly from the default repository. Let’s run this command below to install PHP and its extensions.

# dnf install php-{curl,fpm,gd,imagick,intl,mbstring,mysqlnd,xml,zip}

Once completed, the PHP-FPM service will be running automatically. We are not going to edit the PHP-FPM configuration; we will use the default PHP-FPM www.conf file. To ensure PHP-FPM is running, you can verify it with this command:

# systemctl status php-fpm

And make sure to run it on boot.

# systemctl enable php-fpm

Step 5. Install SSL Certificate

This step is optional but highly recommended to complete. This step will walk you through SSL installation from Let’s Encrypt using certbot.

# apt install python3-certbot-nginx

Now, we are ready to install the SSL certificate, run this command:

# certbot

Follow or answer the prompts; you need to provide your email address, accept the Let’s Encrypt TOS, and whether you want to share your email address with the Electronic Frontier Foundation.

Then, you need to choose which domain/subdomain name you would like to activate HTTPS for. Choose your Prestashop website by typing the number and hitting ENTER. Let’s encrypt will install the certificate, and it will ask you whether to configure HTTP to HTTPS redirection or not; you can choose redirect, then certbot will create the redirection and reload nginx if everything is okay.

After running the ‘certbot’ command, you will get an output like this:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): you@yourdomain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.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: n
Account registered.

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: prestashop.yourdomain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Requesting a certificate for prestashop.yourdomain.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/prestashop.yourdomain.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/prestashop.yourdomain.com/privkey.pem
This certificate expires on 2023-07-18.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for prestashop.yourdomain.com to /etc/nginx/sites-enabled/prestashop.conf
Congratulations! You have successfully enabled HTTPS on https://prestashop.yourdomain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Step 6. Install Prestashop

Finally, we get to the final and main step. In this step, we will download the Prestashop source file and extract it.

# cd /tmp
# wget https://assets.prestashop3.com/dst/edition/corporate/8.0.2/prestashop_edition_basic_version_8.0.2.zip -O prestashop8.zip
# unzip prestashop8.zip

After extracting it, you will get prestashop.zip containing all Prestashop files. Let’s unzip it and store the files on our PrestaShop website’s document root.

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

Once finished, we need to correct the permission. The files and directory should be owned by user ‘apache’ because PHP-FPM also uses user ‘apache’.

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

Go to http://prestashop.yourdomain.com to complete the installation

Please note for security reasons; you need to delete the ‘install’ directory inside your Prestashop document root after the installation is completed.

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

Then, you will see an admin_RANDOMSTRING in your /var/www/html/prestashop directory. Please edit your nginx server block and make sure “admin_CHANGE_ME” points to the correct admin directory, like this:

#Change this block to your admin folder
location /admin2023xhty {
    if (!-e $request_filename) {
    rewrite ^/.*$ /admin2023xhty/index.php last;
    }
}

Save the file, then exit. Do not forget to restart nginx to apply the changes. Then, you should be able to access your Prestashop backend using the login credentials you created during the installation.

Congratulation! You have successfully installed Prestashop on Almalinux 9, and now you can start using it, then build and customize it.

If you are one of our web hosting customers and use our managed Linux Hosting, you don’t have to follow this tutorial and install Prestashop on Almalinux 9 yourself; our Linux admins will set up and configure a Prestashop VPS for you. They are available 24×7 and will take care of your request immediately, and all you need to do is to submit a ticket; you can count on our support team.

PS. If you liked this post, please share it with your friends on social networks or simply leave a reply below. Thanks.

Leave a Comment