In this tutorial we are going to provide you with step-by-step instructions on how to install PrestaShop with Nginx and PHP-FPM on an Ubuntu 16.04 VPS. PrestaShop is an open-source and easy to use shopping cart solution used to build professional e-commerce websites.
At the time of writing this tutorial, the latest stable version of PrestaShop is v1.7.1.2 and it requires:
- PHP >= 5.4 with the following PHP extensions enabled: cURL, GD, intl, Zip, PDO and OpenSSL. Also, using MemCached and mycrpt PHP extensions is highly recommended for better site performance;
- nginx or Apache web server;
- MySQL or MariaDB installed on your virtual server.
Make sure your package list and the OS packages are up to date by running the following commands:
sudo apt-get update sudo apt-get upgrade
To install the latest Nginx version from the official Nginx repository, edit the ‘/etc/apt/sources.list’ file:
sudo vi /etc/apt/sources.list
Add the following lines:
deb http://nginx.org/packages/ubuntu/ xenial nginx deb-src http://nginx.org/packages/ubuntu/ xenial nginx
Install MySQL:
sudo apt-get install mysql-server
Stop and remove Apache service, then install nginx your virtual server using the following commands:
sudo service apache2 stop sudo apt-get remove apache2 sudo apt-get autoremove sudo apt-get install nginx
Configure Nginx to start on boot:
sudo update-rc.d -f nginx defaults
Install PHP and PHP modules required by PrestaShop:
sudo apt-get install php7.0 php7.0-cli php7.0-fpm php7.0-curl php7.0-mbstring php7.0-mysql php7.0-gd php7.0-zip php7.0-intl php7.0-mcrypt libgd-tools libmcrypt-dev mcrypt php-pear libgd-dev
Start the PrestaShop installation procedure
Download the latest version of PrestaShop available at their official website to a directory of your virtual server (e.g. /var/www/html/prestashop) and extract it using the following commands:
sudo apt-get install wget unzip mkdir -p /var/www/html/prestashop cd /var/www/html/prestashop wget -O archive.zip https://download.prestashop.com/download/releases/prestashop_1.7.1.2.zip unzip archive.zip unzip -o prestashop.zip rm archive.zip prestashop.zip
Create a new Nginx configuration file and add the following virtual block for your domain name:
vi /etc/nginx/conf.d/your-domain.com.conf
Add the following lines:
server { listen 80; server_name your-domain.com; root /var/www/html/prestashop/; index index.php; access_log /var/log/nginx/your-domain.com-access.log; error_log /var/log/nginx/your-domain.com-error.log; charset en_us.UTF-8; location / { error_page 404 = @prestashop; } location @prestashop { rewrite ^(.*)$ /index.php?q=$1 last; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Do not forget to replace ‘your-domain.com’ with your actual domain name. Then, disable the ‘default’ Nginx configuration file:
rm /etc/nginx/sites-enabled/default
Open the ‘/etc/php/7.0/fpm/pool.d/www.conf’ file and change the ‘listen’ variable:
change:
listen = /run/php/php7.0-fpm.sock
to
listen = 127.0.0.1:9000;
Locate the PHP configuration file:
# php -i | grep -i php.ini Configuration File (php.ini) Path => /etc/php/7.0/cli Loaded Configuration File => /etc/php/7.0/cli/php.ini
Edit the ‘/etc/php/7.0/cli/php.ini’ configuration file:
vi /etc/php/7.0/cli/php.ini
Add/modify the following settings:
max_execution_time = 300 max_input_time = 600 memory_limit = 128M post_max_size = 64M upload_max_filesize = 64M
The web server user (www-data) needs to be able to write to files and directories inside the ‘/var/www/html/prestashop’ directory, so it can easily be accomplished by executing the following command:
sudo chown www-data:www-data -R /var/www/html/prestashop/
Test the nginx configuration:
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
If test is successful, restart php7.0-fpm and Nginx services for the changes to take effect:
sudo service php7.0-fpm restart sudo service nginx restart
PrestaShop requires a database to work as this is where data is saved, so create a new MySQL database:
mysql -u root -p mysql> create database prestashopdb; mysql> GRANT ALL PRIVILEGES ON prestashopdb.* TO 'prestashopuser'@'localhost' IDENTIFIED BY 'Y0UR-PASSW0RD'; mysql> flush privileges; mysql> quit
Open http://your-domain.com/ using your favorite web browser and follow the easy instructions. Once installed, log in to the administrator back-end and configure PrestaShop according to your needs.
After PrestaShop has successfuly been installed, do not forget to delete the ‘/var/www/html/prestashop/install/’ directory from your server:
rm -rf /var/www/html/prestashop/install/
That is it. PrestaShop installation is now complete.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.