Install PrestaShop on Ubuntu 16.04 LTS with Nginx, MariaDB, PHP 7.1 and Let’s Encrypt free SSL/TLS
Like Magento, PrestaShop allows anyone build an online store using its simple interface… If you’re looking for a open source eCommerce platform to sell your products online, make sure to include PrestaShop in your decision…
PrestaShop is a popular and widely used open source and free eCommerce platform based on PHP. It has comprehensive product features for small, medium and large businesses to create and manage their online stores for free.
If you’re looking for a functional, high performance eCommerce platform to manage your online store front that’s 100% free, you’ll find PrestaShop to be useful. This brief tutorial is going to show students and new users how to install PrestaShop on Ubuntu 17.04 | 17.10 with Nginx, MariaDB and PHP support.
This post covers installing the latest version of PrestaShop, which at the time of writing was at version 1.7.2.4
To get started with installing PrestaShop, follow the steps below:
Step 1: Install Nginx
PrestaShop requires a webserver and the second most popular webserver in use today is Nginx. So, go and install Apache2 on Ubuntu by running the commands below:
sudo apt install nginx
Next, run the commands below to stop, start and enable Nginx service to always start up with the server boots.
sudo systemctl stop nginx.service sudo systemctl start nginx.service sudo systemctl enable nginx.service
Step 2: Install MariaDB
PrestaShop also requires a database server… and MariaDB database server is a great place to start. To install it run the commands below.
sudo apt-get install mariadb-server mariadb-client
After installing, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.
sudo systemctl stop mysql.service sudo systemctl start mysql.service sudo systemctl enable mysql.service
After that, run the commands below to secure MariaDB server.
sudo mysql_secure_installation
When prompted, answer the questions below by following the guide.
- Enter current password for root (enter for none): Just press the Enter
- Set root password? [Y/n]: Y
- New password: Enter password
- Re-enter new password: Repeat 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
Restart MariaDB server
sudo systemctl restart mysql.service
Step 3: Install PHP 7.1-FPM and Related Modules
PHP 7.1 isn’t available on Ubuntu default repositories… in order to install it, you will have to get it from third-party repositories.
Run the commands below to add the below third party repository to upgrade to PHP 7.1
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php
Then update and upgrade to PHP 7.1
sudo apt update
Run the commands below to install PHP 7.1 and related modules.
sudo apt install php7.1-fpm php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-gd php7.1-xml php7.1-intl php7.1-mysql php7.1-cli php7.1-mcrypt php7.1-ldap php7.1-zip php7.1-curl
After install PHP, run the commands below to open PHP-FPM default file.
sudo nano /etc/php/7.1/fpm/php.ini
Then make the change the following lines below in the file and save.
file_uploads = On allow_url_fopen = On memory_limit = 256M upload_max_filesize = 64M max_execution_time = 360 cgi.fix_pathinfo = 0 date.timezone = America/Chicago
Step 4: Create PrestaShop Database
Now that you’ve install all the packages that are required, continue below to start configuring the servers. First run the commands below to create PrestaShop database.
Run the commands below to logon to the database server. When prompted for a password, type the root password you created above.
sudo mysql -u root -p
Then create a database called prestashop
CREATE DATABASE prestashop;
Create a database user called prestashopuser with new password
CREATE USER 'prestashopuser'@'localhost' IDENTIFIED BY 'new_password_here';
Then grant the user full access to the database.
GRANT ALL ON prestashop.* TO 'prestashopuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
Finally, save your changes and exit.
FLUSH PRIVILEGES; EXIT;
Step 5: Download PrestaShop Latest Release
Next, visit PrestaShop site and register for a free account. You must register before you’re allowed to download a copy. The community edition is what you’ll want to download.
After downloading, run the commands below to extract the download file into Nginx root directory.
cd /tmp && curl -O https://download.prestashop.com/download/releases/prestashop_1.7.2.4.zip unzip prestashop_1.7.2.4.zip sudo mkdir -p /var/www/html/prestashop sudo unzip prestapshop.zip -d /var/www/html/prestashop/
Then run the commands below to set the correct permissions for PrestaShop to function.
sudo chown -R www-data:www-data /var/www/html/prestashop/ sudo chmod -R 755 /var/www/html/prestashop/
Step 6: Configure Nginx
Finally, configure Nginx site configuration file for PrestaShop. This file will control how users access PrestaShop content. Run the commands below to create a new configuration file called prestashop
sudo nano /etc/nginx/sites-available/prestashop
Then copy and paste the content below into the file and save it. Replace the highlighted line with your own domain name and directory root location.
server {
listen 80;
listen [::]:80;
root /var/www/html/prestashop;
index index.php index.html index.htm;
server_name example.com www.example.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;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Save the file and exit.
Step 7: Enable the PrestaShop Site
After configuring the VirtualHost above, enable it by running the commands below
sudo ln -s /etc/nginx/sites-available/prestashop /etc/nginx/sites-enabled/
STEP 8: OBTAIN AND CONFIGURE LET’S ENCRYPT SSL CERTIFICATES
Now that the PrestaShop configuration is done, continue below to get Let’s Encrypt installed and configured. Let’s Encrypt now provides a Nginx module to automate this process. To get the client/module installed on Ubuntu, run the commands below
sudo add-apt-repository ppa:certbot/certbot sudo apt-get update sudo apt-get install python-certbot-nginx
After that run the commands below to obtain your free Let’s Encrypt SSL/TLS certificate for your site.
sudo certbot --nginx -m admin@example.com -d example.com -d www.example.com
After running the above commands, you should get prompted to accept the licensing terms. If everything is checked, the client should automatically install the free SSL/TLS certificate and configure the Nginx site to use the certs.
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-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A
Choose Yes ( Y ) to share your email address
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 EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
This is how easy is it to obtain your free SSL/TLS certificate for your Nginx powered website.
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
Pick option 2 to redirect all traffic over HTTPS. This is important!
After that, the SSL client should install the cert and configure your website to redirect all traffic over HTTPS.
Congratulations! You have successfully enabled https://example.com and https://www.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=example.com https://www.ssllabs.com/ssltest/analyze.html?d=www.example.com ------------------------------------------------------------------------------- IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2018-02-24. 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
The highlighted code block should be added to your Nginx PrestaShop site configuration file automatically by Let’s Encrypt certbot. Your PrestaShop site is ready to be used over HTTPS.
listen 80; listen [::]:80; root /var/www/html/prestashop; index index.php index.html index.htm; server_name example.com www.example.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; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot if ($scheme != "https") { return 301 https://$host$request_uri; } # managed by Certbot # Redirect non-https traffic to https # if ($scheme != "https") { # return 301 https://$host$request_uri; # } # managed by Certbot }
Step 9 : Restart Nginx
To load all the settings above, restart Nginx by running the commands below.
sudo systemctl restart nginx.service
Then open your browser and browse to the server domain name followed by install. You should see PrestaShop setup wizard to complete. Please follow the wizard carefully.

Follow the onscreen wizard until you’ve successfully installed PrestaShop

Enter the database connection info and connect.

If everything is right, you should be able to connect and install PrestaShop.
After installing, run the commands below to delete the install folder.
sudo rm -rf /var/www/html/prestashop/install/
Congratulations! You’ve successfully installed PrestaShop.
To setup a process to automatically renew the certificates, add a cron job to execute the renewal process.
sudo crontab -e
Then add the line below and save.
0 1 * * * /usr/bin/certbot renew & > /dev/null
The cron job will attempt to renew 30 days before expiring
Enjoy!
You may also like the post below:
Thx, man!! \o;/
Such a great article. Thank you for take your time to share this info. Just to add that, according to the certbot documentation, the cron job is not needed, the certbot installation already creates a cron job to do that.
This is actually the best (& only to my knowledge) guide to setup a fully working prestashop on an Ubuntu 16.04 VPS !
AWESOME work dude !
Thank you for taking the time to write everything up, I love the fact that you SPECIFIED the use of php7.1-fpm all the way through -> your nginx virtual host config is FLAWLESS ^^
I was able to transfer a fully working prestashop 1.6 from a shared hosted environment (using MariaDB ^^) to a virgin Ubuntu VPS using only your guide.
(Although I had to add some minor tweaks to the php.ini file to get a PhPMyAdmin environment working alongside + set up PhPmail + an opcache to optimize everything xD).
-> Anyway with your guide and some minor tricks I was able to speed up by 70% the overall speed of that website that used to be hosted on a very expensive shared hosting !!
Again many many thanks :)
*some french dude
Hi ,
Would you share your phpmyadmin & phpmail solution
with us?
Thank you
Regarding intl.so install on centos7 with nginx and php7.0
All instruction I found were incorrect
Finally worked by trying install with dependencies using yumdownloader:
I used a local install but remote may work as well.
yumdownloader –resolve –destdir=/var/cache/yum/x86_64/7/downloadonly/ php70-php-intl
yum –nogpgcheck localinstall /var/cache/yum/x86_64/7/downloadonly/ php70-php-intl-7.0.32-1.el7.remi.x86_64.rpm
cp -vn /opt/remi/php70/root/usr/lib64/php/modules/intl.so /usr/lib64/php/modules/intl.so
Restart the whole server
Note: “php70-php-intl” is the
Note: localpath above is specific to my server .
Ok, so I set up a new VPS w/ Ubuntu 18 following these institutions, got https going and everything seemed to install ok.
Admin dashboard logs in ok … BUT clickin any page gives error:
“The page isn’t redirecting properly”
Same issue with storefront!
Im stumped, help!!!!