Jump to content

[Tutorial] Installing LEMP stack (Linux, NGINX, PHP, MySQL) manually to host Prestashop

Recommended Posts

Welcome to the PrestaShop Forum,


In this tutorial, we will be taking a fresh installed Ubuntu VPS or dedicated server and transform it to a webserver that will be ready to host Prestashop.


The benefit of running a manually installed and configured LEMP stack is the avoidance of control panels such as cPanels and such. In addition, the RAM memory of your server would be less consumed. At the end, you are saving money and resources.


Please note that at the time of this article, the versions of software were the following:


Ubuntu 14.04



This does not mean that this lesson will not work with other versions, but keep in mind compatibility issues.



Please have the most common Ubuntu repositories added to your repositories list.


Step 1:

Login into your freshly installed Ubuntu as root or as the user you created during installation.


Step 2:

Follow the following instructions carefully. Please be advised that the instructions are chronological in order. The parts in red are what needs to be changed by you.



# Update Server

sudo apt-get update && time sudo apt-get dist-upgrade

sudo apt-get install unzip


# nginx installation & upgrade

sudo apt-get install nginx

sudo service nginx stop

sudo aptitude install python-software-properties

sudo add-apt-repository ppa:nginx/stable

sudo aptitude update

sudo aptitude safe-upgrade

sudo apt-get upgrade nginx

sudo service nginx restart

nginx -v


# MySQL Installation

sudo apt-get install mysql-server

sudo mysql_install_db

sudo mysql_secure_installation // follow instructions and delete any temporary databases then say yes to reflush privileges


# PHP installation

sudo apt-get install php5-fpm php5-mysql php5-curl php5-cli php5-mcrypt

// upgrade to latest stable version. Choose whatever version suits you
sudo apt-add-repository ppa:ondrej/php5-oldstable // to add php 5.4 versions repository
sudo apt-add-repository ppa:ondrej/php5 // to add php 5.5 versions repository
sudo apt-add-repository ppa:ondrej/php5-5.6 // to add php 5.6 versions repository

// reinstall php (this will upgrade it to latest version)
sudo apt-get install php5 // setup will ask you whether to replace existing php.ini file and keep the current. That's up to you.

// edit the php.ini file in case you chose "replace the current"
sudo nano /etc/php5/fpm/php.ini

Ctrl + W = cgi.fix_pathinfo // uncomment and then set to 0
Ctrl + W = max_filesize // set it to 50 MB
Ctrl + W = post_max // set it to 50 MB
Ctrl + W = memory_limit // set it to 128 MB

Ctrl + W = max_input_vars // uncomment and then set it to 10000
Ctrl + W = expose_php // set to off

sudo service php5-fpm restart


# General & Security Configurations

sudo mkdir -p /var/www // to create the folder www

sudo find * -type d -print0 | xargs -0 chmod 0755 // to set 755 permission for folders
sudo find . -type f -print0 | xargs -0 chmod 0644 // to set 644 permission for files

sudo nano /var/www/info.php // this will create an empty file, copy and paste the code inside and the hit Ctrl + x to save and exit


http://domain.com/info.php // to test if php is running

sudo mkdir -p /var/www/nginx-logs/domain.com // Create logs directory
sudo chmod -R 700 /var/www/nginx-logs // restrict permission to root only

sudo rm /etc/nginx/sites-available/default // remove the default host file
sudo rm /etc/nginx/sites-enabled/default // remove the default host file

sudo nano /etc/nginx/sites-available/domain.com   // Create PrestaShop host file and paste configuration. WARNING: nginx configuration file codes are at the end of the article
sudo ln -s /etc/nginx/sites-available/domain.com  /etc/nginx/sites-enabled/domain.com

// remove nginx version from http headers
cd /etc/nginx/nginx.conf
server_tokens off; // uncomment this line by removing the #

// while still in nginx.conf file, uncomment  all of these to enable gzip
gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_prox ied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

sudo chown www-data:www-data -R /var/www/  #apply this command to give nginx user www-data the freedom to write and read in the www folder. Important!!!
sudo service nginx restart // to restart nginx service and load new configurations

// Change default port of ssh to that of Windows RDP for spoofing, remember to reconnect to port 3389 or whatever you set next time
cd /etc/ssh/sshd_config
Ctrl + W = port 22 // set it to 3389 or whatever you like
sudo service ssh restart


# PHPMyAdmin

sudo apt-get update
sudo apt-get install phpmyadmin // in configuration, when it asks for httpd or apache, hit TAB in the keyboard to choose neither then Enter
cd /usr/share // browse the directory where phpmyadmin is at
ls -l // list all file in directory to make sure phpmyadmin exist
sudo mv phpmyadmin sqlinterface // renaming the folder
ls -l // list all files again to make sure renaming was successful
sudo ln -s /usr/share/sqlinterface /var/www // Create a symbolic link to your root folder
sudo php5enmod mcrypt // phpmyadmin relies on mycrypt addon
sudo service php5-fpm restart
http://domain.com/sqlinterface // browse to test


# Remoting

Download WinSCP for windows.
Connect using SCP protocol by typing the IP address of your server and the port you specified earlier.
The SCP protocol is much better and faster than FTP.
Never install or setup FTP.


# Install linux dash

cd /var/www
sudo apt-get install git
sudo git clone https://github.com/afaqurk/linux-dash.git
// don't forget to rename the folder to whatever name you like and match it up with that in nginx host file

# Securing
# Install Apache Utils to create a username and password for linux dash
sudo apt-get install apache2-utils

# Create a user and pass
cd /etc/nginx/
sudo htpasswd -b -c htpasswd Username Password


Congratulation! You are now ready to install Prestashop.


Step 3:

Attached, are the host file. Copy the lines inside of them and paste into the host file you created above in "# General & Security Configurations". The following configuration supports http only. If you want to enable https, uncomment the ssl lines and tweak them up properly.


For non-www to www redirection:


Look for attachments.

For www to non-www redirection:


Look for attachments.


That's all for today!


Please remember to give back to the community. This lesson took weeks to become what it is right now.


Any suggestions and ideas in the scope of this article are welcome. For moderators, you are welcome to fix, add and reformat any part of this article.


- Phil

Host files.zip

Edited by PhilCorleone (see edit history)
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...