How to setup LAMP/LEMP/WAMP for Magento 2

With the release of Magento 2.0, many developers started getting their hands dirty with Magento. The first hurdle was preparing a perfect developer machine with all required toolsets. I was one of them, and I faced a lot of trouble while just to run Magento 2 on my machine. So today I am going to show you, how to set up a perfect LAMP/LEMP (or WAMP for Windows users) environment on their machine.

I have divided this tutorial in three sections. I will start from scratch on every environment to give you the better understanding of how things works on each platforms.

1. Setup LAMP(Linux, Apache, MySQL, PHP) for Magento 2

For this I am using Ubuntu 14.04 machine. You can also follow this guide on a virtual machine from DigitalOcean or from your favourite provider. Open your terminal and get logged in as root user, we will install these apps/tools to set up our LAMP machine for Magento 2:

  • Apache 2.4.7
  • MySQL Server 5.6
  • PHP 5.6

First step is make sure that our system is up to date. Enter following command in terminal:

sudo apt-get -y update sudo apt-get -y upgrade

Install Apache2:

So as our system is ready, we can proceed to install Apache web server on our system.

sudo apt-get -y install apache2

This will install Apache 2.4 on your system. Also enable mod_rewrite module for Apache.

sudo a2enmod rewrite

Install MySQL Server 5.6:

Next, Let’s install MySQL server. Magento 2 requires MySQL 5.6 or higher, to install mysql server follow these commands.

sudo apt-get -y install mysql-server-5.6

To secure your mysql server enter the command given below. You should select “Yes” for most of the options it prompts:

sudo mysql_secure_installation

Install PHP 5.6:

Now it’s time to install PHP. Magento supports both 5.5 and 5.6 versions of PHP. To install PHP5.6 follow these commands:

sudo add-apt-repository ppa:ondrej/php5-5.6 sudo apt-get -y update sudo apt-get -y php5 php5-common php5-cli php5-mcrypt php5-gd php5-intl php5-xsl php5-curl php5-mysql

Don’t forget to enable php5-mcrypt extension.

sudo php5enmod mcrypt

Next let’s optimize php settings for Magento 2.

PHP Configurations:

In order to run Magento 2, we will need tweak some of our php configurations. So open php.ini in your favourite text editor:

sudo nano /etc/php5/apache2/php.ini

Change timezone to your timezone. Just uncomment line time zone lines. In my case in php.ini:

date.timezone = Asia/Kolkata

You can find your timezone here

Next we will tweak some performance settings. Find & set following values as in core PHP settings.

Also find the line always_populate_raw_post_data and uncomment it. And set it as below:

always_populate_raw_post_data = -1

Save your php.ini file & exit your text editor. In your terminal type this command to restart apache server.

sudo service apache2 restart

If you got message like “Could not reliably determine the server’s fully qualified domain name…”, then don’t worry just open the apache configuration file add this line at the end.

## Open Apache configuration file. 
sudo nano /etc/apache2/apache2.conf
## Add following line at the end. 
ServerName localhost
## Restart Apache server 
sudo service apache2 restart

And we are done with our PHP configurations. Time to relax!

Creating Virtual Hosts in Apache for Magento 2

If you prefer working your Magento project as instead of http://localhost/magento/ then this part is for you. So to create virtual hosts in apache follow the steps:

We will create a virtual domain pointing towards /var/www/magento2 directory. And open terminal type these commands:

sudo nano /etc/apache2/sites-available/

And paste following content.

Save the file by pressing Ctrl+o in terminal. Exit from nano editor using Ctrl+x. Enable site with this command:

sudo a2ensite

And restart the Apache server to take effect.

sudo service apache2 restart

Now you can start working on your Magento 2 project at /var/www/magento2 and you can access your project at

Next we will need to tell our system to point towards ip address So open terminal and type these commands:

sudo nano /etc/hosts

And this line at the end:

Save file & exit nano editor. That’s it! we are done with setting up LAMP for Magento 2. Now you can proceed for Magento 2 installation.

2. Setup LEMP(Linux, Nginx, MySQL, PHP) for Magento 2

In previous section, we used Apache as our web server. But there is a popular alternative for Apache, which performances high & has low memory usage. If you prefer Nginx over Apache2, then you have good news! Magento 2 also support Nginx web server.

We are using Ubuntu 14.04 (Trusty Tahir). You can also follow this guide on droplet(virtual server) from DigitalOcean. We will installing these apps/tools on our system:

  • Nginx 1.4.6
  • MySQL 5.6
  • PHP-fpm 5.5.9

So let’s update our system with latest updates.

sudo apt-get -y update sudo apt-get -y upgrade

Install Nginx web server:

Let’s install nginx server first.

sudo apt-get -y install nginx

Install MySQL Server:

After installing nginx, install MySQL server 5.6:

sudo apt-get install -y mysql-server-5.6 
## Secure your MySQL installation 
sudo mysql_secure_installation

Install PHP-fpm:

Now let’s install PHP. Nginx web server don’t have native support for php. So we have to use PHP-FPM which is called as “fastcgi process manager”. You can get information about php5-fpm on their website

So install php-fpm and other required extension by using this command:

sudo apt-get install -y php5-fpm php5-cli php5-mcrypt php5-gd php5-intl php5-xsl php5-curl php5-mysql

Also don’t forget to enable mcrypt extension:

sudo php5enmod mcrypt

PHP Configurations

It’s time to tweak some of our php setting to support Magento 2 installation. So open php.ini for php5-fpm in you favourite text editor.

sudo nano /etc/php5/fpm/php.ini

And change these settings in php.ini

Save the file and exit your exit your editor. Open terminal & restart both Nginx & PHP5-FPM services.

sudo service php5-fpm restart sudo service nginx restart

And we are done with our PHP configurations. Next we will see how we can set up virtual host in Nginx for Magento 2.

Creating Virtual Hosts in Nginx for Magento 2

If you are working on Magento project on a Nginx web server, then you probably will want to set up to pointing towards your project path /var/www/magento2. We are going to do the same in upcoming steps.

Open your terminal and enter following command:

sudo nano /etc/nginx/sites-available/

It will open nano editor with blank file. Just paste the following content in that file.

Save and exit the nano editor. Now enable the site by creating a symbolic link.

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Next step in to restart both Nginx & PHP-FPM services.

sudo service nginx restart sudo service php5-fpm restart

After that, let’s point to local ip address Open terminal and enter this command to edit the hosts file.

sudo nano /etc/hosts

And paste this line at the end & save the file.

And we are finally done! Now we can proceed for Magento 2 Installation.

3. Setup WAMP (Windows, Apache, MySQL, PHP) for Magento 2

If you are a Windows user like me, you can also setup your Windows machine for Magento 2. We are going to AMPPS instead of WAMP, because AMPPS makes things a lot easy to set up. It also provide interface to create Virtual hosts like

So grab the installer for yourself from And install it like any regular Windows software. For this tutorial I am using AMPPS version 3.4.

PHP Configurations

After installing AMPPS, you will need to enable php_intl & php_xsl . They are PHP extensions required for Magento 2. To enable them, open AMPPS Control Panel and click PHP section.

Next, click on Php Extension to enable our php extensions. On clicking this option a select box with PHP extensions will popup.

Then select “php_intl” & “php_xsl” from the extension list. Also make sure that other extensions, which are required by Magento 2 are selected and hit Apply. After this we will need to restart Apache server. So to restart Apache server, again click on Control Panel and under Apache logo, click on restart button.

That’s it! We are finished with PHP configuration for AMPPS. Next we will see how to create virtual hosts in AMPPS.

Creating Virtual Hosts in AMPPS for Magento 2

It’s so easy to set up virtual hosts in AMPPS. Just open http://localhost/ampps/ in your favourite browser. And click on Add Domain icon.

Then add your virutal host info. and project path to your magento root.

And click on Add Domain. That’s it! no need to play with Apache configuration files. Next we will need to tell Windows to point domain to our local ip address

So find Notepad in start menu and Run it as Administrator. Open “hosts file located here at C:\Windows\System32\drivers\etc & add this line at the end in the file.

Save file and exit the editor. And we are finally done


Installing Magento 2

So that now, you are done with setting up your system for Magento 2, let’s get a quick overview on how to install Magento 2.

Install Composer

We are going to install Magento 2 using composer, which is an easy way to install Magento 2. If you don’t know about Composer yet, then let me tell you it is a PHP dependency manager. You can use it to manage PHP libraries for your project. You can get more information Composer on there official site

So to install Composer in your linux(Ubuntu) system, enter these two commands:

curl -sS | php 
sudo mv composer.phar /usr/local/bin/composer

Windows user can directly grab a msi installer from their official site After installing Composer it’s to install Git on our system.

Install Git

Git is version control system for your project. To install git on your system enter following command.

sudo apt-get install -y git

Windows users can grab a Wndows installer from After installing git let’s get back to installing Magento 2.

Install Magento 2

Before we start installing Magento 2 using Composer, please make sure that you have configured a swap partition on your system (Windows users don’t worry about swap partition). Check for swap partition like this:

free -m 
## It will show output like this 
total used free shared buffers cached
Mem: 2048 357 1690 0 0 237 -/+ buffers/cache: 119 1928
Swap: 0 0 0

If you find output like this (Swap: 0 0 0), then you will need to configure swap like this:

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

To install Magento 2, open your terminal & change current directory /var/www.

cd /var/www

Windows users should change their directory to C:\Program Files (x86)\Ampps\www.

And enter next command to install Magento 2 Community Edition using Composer.

composer create-project --repository-url= magento/project-community-edition <installation directory name>

It will ask you form authentication keys. Get your ones from Magento Connect Account from here

Also it will ask you to enter a token from Github, you can generate token for yourself from Your Account > Settings > Personal access tokens which is located here

This process will take some time depending on your internet connection. After the process is completed, Linux users will need to set up permissions for Magento 2 installation files.

Setting File Permissions

To set up file permissions, change your directory to the base directory of your Magento installation. Enter this command

cd /var/www/magento2

Then set up ownership for files using this command (Applies for Ubuntu users).

sudo chown -R :www-data .

Next setup file permissions using this command.

sudo find . -type d -exec chmod 770 {} \; && sudo find . -type f -exec chmod 660 {} \; && sudo chmod u+x bin/magento

And we are done! You can now continue installation by opening this address in the browser

Deploy static files

If you are intended to use Magento 2 in production mode (Checkout more on Magento modes), then you must deploy static view files to Magento’s filesystem using this command (Thanks to Talesh Seeparsan @_Talesh).

php bin/magento setup:static-content:deploy

You can find more information on deploying static view files here.


And that was another long tutorial on Magento 2. More are coming in upcoming days. I am still learning new things in Magento 2 & I will bring more articles on these as I will be exploring Magento 2. Please do send me your suggestions, also please ask me any question you have in the comments below. I will try my best to help you out.

Don’t forget to subscribe to my newsletter. There will be no spam, it’s my promise! Also follow me on Twitter @swapnil_bhavsar, tweet me your suggestions, questions… I will be happy to help you! Thanks


Originally published at on January 26, 2016.