How to set up a web server for Magento 2.2

How to set up a web server for Magento 2 Reading Time: 7 minutes
Share on Pinterest

Important update: This tutorial was originally created for Magento 2.1.5, but Magento 2.2.2 requires some minor changes to the instructions to make these instructions work. Please, pay extra attention to any instructions marked in red as they will differ slightly from the original videos.

As a reminder, these instructions are for a clean Ubuntu server. If you’re using a pre-existing web server or using WHM/cPanel/Plesk then your results may vary.

Before I start, I just want to let you know that this series isn’t going to be for everyone. You might want to stick around if you’re interested to know how to create a web server for Magento 2 – for the purposes of curiosity or development.

But if technology scares you, I recommend setting up Magento 2 using a one-click installation method. I highly recommend if you are looking for a simple method to get a Production Web Server up and running for Magento 2.

This article is best used in conjunction with the provided videos because I have timestamped the commands that I use so that they correlate with the video. This should make is easier for you to follow along.

What this article will cover

Like most things in life, there is more than one way of doing them. For this article, I have decided to use Ubuntu as my chosen Operating System, running Apache, MySQL and PHP 7. And then using Composer as my method to download Magento 2. These are the sections you will find as you scroll down:

Newsletter Subscription

How to create a Ubuntu Server

In order to create our web server for Magento 2, we need to use a server. One option is to use a Virtual Machine but for the purpose of this article, we will use service provided by Click this link will entitle you to $10 free credit to spend on your server.

How to start a Ubuntu 16.04 Server on DigitalOceon

Once you have registered with Digital Ocean, simply Create a Droplet. You only have to select:

  • The server type (Ubuntu)
  • The Size ($10/mo Package)
  • The Datacenter Region (The closest to your country)

And then you have hit ‘Create’. It takes 1-2 minutes to the server to be created, but once it has you will receive an Email with your SSH Root Login Credentials.

How to connect to your new server

Now that you have a server, you will need a way of connecting to it. In this article, I am working on a Windows machine so I will need to download Putty from

Once installed, you only need to enter the IP Address of your new server into the ‘Host Name (or IP address)’ Field and click ‘Open’.

How to create a new user – and grant it superuser privileges

Once you have successfully logged into your server using Putty, enter the following commands.

Create yourself a user [04:23]

Give this user ‘superuser’ or root privileges by adding it to the ‘sudo’ group [05:06]

How to disable the root user (for security)

**Before disabling root access completely, log out as the root user and relog as the new user. Once logged in as the new user, check that your ‘superuser’ access works. You can check this by switching to the root user and back again. If you followed the steps carefully, then you will not see an error

Access config file to disable root user login** [06:18]

Change the below line, then save and exit [06:32]

Reload the SSH Service for changes to take effect [06:58]

How to enable a basic firewall

First, you must allow SSH connections to your web server. This is the connection we are currently using. [07:58]

Then we turn on the firewall [08:26]

How to create a LAMP stack on Ubuntu

How to install Apache and configure it for Magento 2

Download the package lists from pre-selected repositories and update them on our web server. [01:32]

Install Apache [01:46]

Open Apache settings file to allow .htaccess file usage [02:38]

Add the below to the file, then save and exit [03:00]

Open Apache settings file to set the Global ServerName [03:24]

Add this line at the end of the file, then save and exit [03:35]

Check for any errors [04:02]

Enable Apache rewrite [04:40]

Restart Apache for any changes to take effect [04:52]

Enable Apache through the firewall [05:28]

How to install MySQL and secure the installation

MySQL is a database management system that allows the web server to store information that can be accessed by Magento. [06:22]

Run a MySQL security script that addresses some vulnerabilities [07:08]

How to install PHP and any extensions needed for Magento 2

PHP allows the web server to process code, run scripts and display dynamic content that Magento 2 uses. [08:36]

Important Update: Added php7.0-soap to command

Tell the webserver to prefer PHP files (move index.php to front of the list) [08:50]

Install PHP Modules for use with Magento 2 [09:52]

Restart apache for changes to take effect [10:08]

How to install phpMyAdmin and secure the installation

phpMyAdmin allows us to manage MySQL Databases using a Graphical User Interface, rather than having to use a Command Line Interface.

Install phpMyAdmin [Warning: Press space to select ‘apache2’ before hitting Enter to continue] [10:56]

Make sure that you select apache2 using your SPACE BAR before hitting ENTER to continue

Enable 2 phpMyAdmin required extensions [11:42]

Restart Apache for any changes to take effect [12:12]

phpMyAdmin Checks

Visit the phpMyAdmin portal you’ve just created via a web browser to ensure the page loads HTTP://<your_server>/phpmyadmin

How to set file system permissions

How to create a new web user

The reason for creating a new web user is for added security. The main user that we created (e.g. ‘craig’) has the ability to run superuser commands if required, where the web user would never need such privileges. Also, having a dedicated web user on the server means not having to keep updating folder/file permissions whenever you add or move files.

Add the user (I’ve called my user ‘magento’) [01:38]

How to add the user to the web servers primary group

Make the web server group the primary group for the new user [02:30]

How to set folder permissions

Update the root file ownership to coincide with our new web user [03:12]

How to install Composer and download Magento 2

Where to obtain our Magento Access Keys

Before you do anything, be sure to visit and create an account. Then you can generate a set of access keys that will allow you to download from the Magento reporistory.

How to install Composer

To install composer, complete the 2 commands [01:56]

How to download Magento 2 via Composer

Move to the web directory [02:35]

Switch to the ‘magento’ user [02:58]

Be sure to empty the web directory before running the below command (I forgot to do this in the video). User rm index.html to clear out the Ubuntu Default Page.

Run the command to download Magento 2 from the marketplace repository [03:26]

Remember that Username = Public Key and Password = Private Key

Set pre-installation permissions

Update the directory permissions [05:42]

Important Update: Added generated to command

Update the file permissions [05:44]

How to set pre-installation permissions

Update ownership execution permissions [05:46]

How to create a database ready for installing Magento 2

How to create a user and database for Magento 2

Luckily are no commands to reference in this video.

How to install Magento 2 via the Setup Wizard

How to install Magento using the Setup Wizard

This part of the video doesn’t refer to any commands

How to setup the post-installation Folder Permissions

The last folder we have to modify here (run whilst still logged in as ‘magento’ user) [06:12]

How to setup Cron Jobs

If you get a prompt asking which editor to use when running the below command, select option 2 (nano). That’s the text editor we’ve been using throughout these videos.

Open our crontab in order to add commands that can be run to automate Magento tasks [06:40]

At the bottom of the file, simply add these 3 lines [07:00]

Summary on how to create a web server for Magento 2

I hope that you found the video and article useful. Remember, that this article is not to be used without watching the videos. Let me know in the comments below how you get on.

Leave a comment below


Craig Nammontri

Craig Nammontri

I've spent a chunk of my career working in eCommerce for a FTSE 100 company where I've worked in Web Development/Design, SEO and assisted in running an eCommerce business. If I can help anyone out, then I'll try my best.
Craig Nammontri

Latest posts by Craig Nammontri (see all)

Related Post

Share on Pinterest


  1. Daniel

    Hi this is super.
    only thing i cant fix is this permission check i have installed magento 2.2.2

    File Permission Check
    1 file permission not met. Hide detail

    The best way to resolve this is to allow write permissions for files in the following Magento directories and subdirectories. The exact fix depends on your server, your host, and other system variables.
    For help, see our File Permission Help or call your hosting provider.

    “/var/www/html/app/etc” – Writable.
    “/var/www/html/var” – Writable.
    “/var/www/html/pub/media” – Writable.
    “/var/www/html/pub/static” – Writable.
    “/var/www/html/generated” – Not writable, change the permissions. Show details
    * – In some cases, you might have two PHP configuration files: one for the PHP command line and for the web server. If so, make the change in both php.ini files. For details, see the php.ini reference.

    1. Craig Post author

      Thanks for sharing that. Depending on how you set up your users, your cron user must be the same as the file owner. In this guide, the cron is run as www-data and the file/folder owners are also www-data.

      This guide uses the two users setup. Check step 5 in the Official Magento DevDocs to ensure folders and permissions are correct.

  2. Remco

    Thank you for this tutorial. I managed to setup a test server.
    Some minor issues though. Some plugins for PHP were missing (Curl, intl and zip). I was able to install them with “sudo apt install php-missing_plugin”
    And opening the webbrowser on my server ip lead me to a white web page.
    I needed to open “my-server-ip/setup” to start the setup wizard.
    Again thanks for the tutorial.

    1. Remco

      small add-on:
      the map “generated” needed to change to the correct permissions as well.

    2. Craig Post author

      Thank you for the information. I’ll be going through these steps again soon as a lot seems to have changed since I wrote this for v2.1.5. I really appreciate you sharing this with myself and the community.

  3. Spike

    great article.
    I ‘ve engage an cosmetic issue during composer installation says missing extension of PHP-soap
    by adding sudo apt-get install php7.0-soap and reinstall the issue was resolved,

    1. Craig Post author

      Hi Spike. I appreciate you sharing this information. Thank you

  4. Ömür Yanıkoğlu


    Your training really helped me. I have never encountered an error. There’s just one thing. The current version is 2.2.0 but the theme I want to use is compatible with 2.1.9. For this reason, I needed to use the following code:

    composer create-project –repository-url= magento/project-community-edition=2.1.9 .

    Thank you so much.

Your email address will not be published. Required fields are marked *