How to Install PrestaShop on Ubuntu 18.04

Posted 

6 min read

PrestaShop is a free and open-source e-commerce platform. It is based on PHP and MySQL and can be extended with free and premium plugins and themes.

With features like intuitive administrative interface, multiple payment gateways, multi-lingual, analytic and reporting PrestaShop is a platform of choice for many online merchants.

In this tutorial, we will show you how to install PrestaShop on Ubuntu 18.04 server. We’ll be using Nginx as a web server, the latest PHP 7.2 and MySQL/MariaDB as a database server.

Prerequisites

Ensure that you have met the following prerequisites before continuing with this tutorial:

  • Have a domain name pointing to your public server IP. We will use example.com.
  • Nginx is installed on your Ubuntu server by following these instructions.
  • An SSL certificate installed for your domain to encrypt user’s information. You can install a free Let’s Encrypt SSL certificate by following these instructions.

Update the system packages to the latest versions and install the unzip utility:

sudo apt update && sudo apt upgrade
sudo apt install unzip

Creating MySQL database

PrestaShop stores its information in a MySQL database.

If you have MySQL or MariaDB installed on your server you can skip this step, if not you can install the MySQL 5.7 server package from the Ubuntu’s default repositories by typing:

sudo apt install mysql-server mysql-client
For fresh MySQL installations, it is recommended to run the mysql_secure_installation command to improve the security of your MySQL server.

To create a database, log in to the mysql shell:

sudo mysql

From within the MySQL shell, run the following SQL statement to create a new database named prestashop:

CREATE DATABASE prestashop;

Next, create a MySQL user account named prestashop and grant the necessary permissions to the user by running the following command:

GRANT ALL ON prestashop.* TO 'prestashop'@'localhost' IDENTIFIED BY 'change-with-strong-password';
Don’t forget to change change-with-strong-password with a strong password.

Once done, exit the mysql console by typing:

EXIT;

Installing and Configuring PHP

PHP 7.2 is the default PHP version in Ubuntu 18.04 and it is fully supported and recommended for PrestaShop.

Run the following command to install PHP and all required PHP modules:

sudo apt install php7.2-common php7.2-cli php7.2-fpm php7.2-opcache php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-xsl php7.2-mbstring php7.2-zip php7.2-bcmath php7.2-soap

The PHP-FPM service will automatically start once the installation process is complete. You can verify it by typing:

sudo systemctl status php7.2-fpm

The output should look something like this:

* php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-03-24 11:53:33 PDT; 14s ago
     Docs: man:php-fpm7.2(8)
 Main PID: 15853 (php-fpm7.2)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"

Run the following sed commands to set the recommended PHP options:

sudo sed -i "s/memory_limit = .*/memory_limit = 1024M/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 256M/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/zlib.output_compression = .*/zlib.output_compression = on/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/max_execution_time = .*/max_execution_time = 18000/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.2/fpm/php.ini
sudo sed -i "s/;opcache.save_comments.*/opcache.save_comments = 1/" /etc/php/7.2/fpm/php.ini

Downloading PrestaShop

At the time of writing this article, the latest stable version of PrestaShop is version 1.7.5.1.

Download the latest version of PrestaShop from the PrestaShop Downloads Page using the following wget command:

cd /tmp
wget https://download.prestashop.com/download/releases/prestashop_1.7.5.1.zip

When the download is complete, create a directory which will hold our PrestaShop files:

sudo mkdir -p /var/www/html/example.com

Next, extract the PrestaShop archive:

unzip prestashop_*.zip

This archive contains another zip file “prestashop.zip”, which contains all the PrestaShop files. Extract the files into the domain’s document root directory:

sudo unzip prestashop.zip -d /var/www/html/example.com

Set the correct permissions so that the web server can have full access to the site’s files and directories using the following chown command:

sudo chown -R www-data: /var/www/html

Configuring Nginx

By now, you should already have Nginx with SSL certificate installed on your Ubuntu server, if not check the prerequisites for this tutorial.

Open your text editor and create the following file:

sudo nano /etc/nginx/sites-available/example.com
/etc/nginx/sites-available/example.com
# Redirect HTTP -> HTTPS
server {
    listen 80;
    server_name www.example.com example.com;

    include snippets/letsencrypt.conf;
    return 301 https://example.com$request_uri;
}

# Redirect WWW -> NON WWW
server {
    listen 443 ssl http2;
    server_name www.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;

    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com;

    root /var/www/html/example.com;
    index index.php;

    # SSL parameters
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;
    include snippets/letsencrypt.conf;

    # log files
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        expires max;
        log_not_found off;
    }

}
Don’t forget to replace example.com with your PrestaShop domain and set the correct path to the SSL certificate files. The snippets used in this configuration are created in this guide.

Before restarting the Nginx service make a test to be sure that there are no syntax errors:

sudo nginx -t

If there are no errors the output should look like this:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally, restart the Nginx service by typing:

sudo systemctl restart nginx

Installing PrestaShop

Now that PrestaShop is downloaded and the server configuration is complete, you can finish the installation through the web interface.

Open your browser, type your domain and a screen similar to the following will appear:

Select the language you would like to use and click on the “Next” button.

On the next screen, you will be presented with the PrestaShop license agreement. Read the license and select “I agree to the above terms and conditions.” to continue:

Next, you will see the following information page:

Make sure all pre-installation requirements are met and your system is compatible with PrestaShop.

On the next screen, you’ll need to enter your store details. The email address is the username to access the PrestaShop administration backend.

Next, the setup wizard will ask you to enter your database connection details. Enter the MySQL user and database details you previously created:

Click on the “Next” button and the installation will start:

The installation may take a few minutes, once completed the following page will show, informing you that PrestaShop has been installed.

For security reasons, you’ll need to delete the installation directory. To do so, go back to the terminal and enter the following rm command:

sudo rm -rf /var/www/html/example.com/install

To access your PrestaShop administrative dashboard click on the “Manage your store” button. Enter your email and password and you will be redirected to the administration dashboard.

From here you can start customizing your PrestaShop installation and add new products.

Conclusion

You have successfully installed PrestaShop on your Ubuntu 18.04 server. PrestaShop Documentation is a good starting place to learn more about how to manage your PrestaShop installation.

If you have questions feel free to leave a comment below.