How to install Magento 2 the easy way

Time to Read: 30 minutes Difficulty Level: Intermediate
Tools Needed: access to your hosting control panel (Plesk) Last Updated: 10/03/2020

Install Magento 2 - the easy way

This guide shows you the easiest way to install Magento 2 on your server. On the other hand, if you would like us to install Magento 2 for you then we’ll be happy to provide you with a quote for the work.

Let’s get started:

Magento 2 PHP Hosting Requirements
Using Installatron
Configure SSH access
Adding Crons
Securing Magento 2

Magento 2 PHP Hosting Requirements

1) Create your domain in Plesk by adding a new subscription and select it from the Domains option in the left-hand sidebar.

2) Make sure you’re using PHP 7.0.25 or 7.1.11 for your domain. We provide multiple PHP versions in your control panel, so it’s important you select the right one, otherwise you’ll have issues. Click the PHP Settings tool in your Domains dashboard in Plesk.

3) Select PHP Support then pick either PHP version 7.0.25 or 7.1.11 from the drop-down menu.

4) You will also need to update the value for open_basedir in this menu. You’ll find open_basedir under Common settings. Edit it so that it reads as follows:

{WEBSPACEROOT}{/}{:}{TMP}{/}{:}/etc/pki

Now scroll to the bottom of the page and select OK.

Using Installatron

Now onto installation. Using the Installatron 1-click installer is the quickest way to get up and running. Browse to Installatron Application installer in the left-hand sidebar of your hosting control panel.

Select Applications Browser then enter Magento into the search box and hit enter.

You can then select Install this Application

You’ll then need to fill in the relevant domain from the drop-down menu. Careful: this field may automatically select one of your domains and it may not be where you want your Magento 2 installation! You can choose whether or not you would like your Magento store to use HTTPS by default (although you’ll need to ensure you have a SSL in place for a HTTPS connection to the site to work). You can also specify a subdirectory for your store to reside at – in this example, I’ve chosen to install my new Magento store at magento2.com/shop.

You can then select which version of Magento you require. The most recent version available should be auto-selected (Magento 2.2.1 in this example).

You can also choose whether you want to install Magento 2 with or without the sample data. In this example, we’ve decided to use a clean Magento install and add our own products later.

Next it’s time to specify your admin username, password and associated email address. Installatron will automatically generate a random complex password for you but you’ll need to make sure you record these for use later on.

Next, click on Install.

Now sit back and watch Installatron do its work! It’s about time for a coffee anyway, isn’t it?

All done! Before clicking away from this page, note the 2nd URL: that’s your Magento login URL so you’ll want to bookmark it and maybe add to your password management tool too. To log into our example shop, we would need to browse to the following URL:

http://www.magento2.com/shop/index.php/s3j3olkp

If you do lose this URL, you can find the path you’ll need from the env.php file which resides at httpdocs/app/etc (assuming you didn’t specify a subdirectory for installing Magento 2 like I have in this example). The code you’ll want is directly after the line of code containing ’frontName’ =>.

Configure SSH access

The next step is to configure SSH access for your Magento store. This is necessary for the crons we’ll set up soon, but also required if you’re going to take advantage of Magento 2’s powerful command line interface.

Browse back to your domain in your Plesk control panel, then select the Web Hosting Access tool.

From the drop-down menu for Access to the server over SSH, change the setting from Forbidden to /bin/bash.

Click on OK to confirm the change.

As you may have noticed, other shells are available from the drop-down menu. There’s nothing wrong with using these for other sites if you prefer, but you’ll need the the bash shell specifically for the crons Magento 2 requires.

Now you’re ready to add cron jobs for your Magento 2 site.

Adding Crons

​Select the Scheduled Tasks menu from the right-hand sidebar. A Scheduled Task is simply Plesk’s term for a cron job.

Click on the Add Task button to create a new scheduled task.

The default setting will be to Run a command. There’s no need to change this so enter the following into the Command field:

/var/www/vhosts/your-domain.com/httpdocs/cron.sh

You should replace your-domain.com with your actual domain name. This command assumes that you’ve installed Magento to your web root folder (ie: httpdocs) and not into a sub-directory. In this example, I would need to update my command as follows because my Magento was installed in the /shop sub-directory:

/var/www/vhosts/your-domain.com/httpdocs/shop/cron.sh

Next select the drop-down menu for Run to update Daily to Cron style. Magento advise that these crons should run daily, every minute of the day, so enter the following:

* * * * *

You can then test your cron by selecting Run Now or just click OK to finish adding the cron.

In the next screen, you should be able to see the cron you’ve just added. The cron won’t function as expected just yet though: we’ve essentially told it to call a bash script (cron.sh) which isn’t currently present. We’ve devised our own updated cron.sh script which wraps around Magento 2’s core crons and is NOT provided as part of a standard Magento 2 install. Accordingly, you will need to create a file called cron.sh inside your webroot directory (usually httpdocs) and enter the following code:

#!/bin/bash
#Adapted from Magento cron.sh
#Ergo:
# NOTICE OF LICENSE
#
# This source file is subject to the Open Software License (OSL 3.0)
# that is bundled with this package in the file LICENSE.txt.
# It is also available through the world-wide-web at this URL:
# http://opensource.org/licenses/osl-3.0.php
# If you did not receive a copy of the license and are unable to
# obtain it through the world-wide-web, please send an email
# to [email protected] so we can send you a copy immediately.
#
# location of the php binary should be in the PATH, so we just need the path
# The cron commands are all hardcoded.
source ~/.bashrc
PHP_BIN=`which php`
 
# absolute path to magento installation
INSTALLDIR=`echo $0 | sed 's/cron\.sh//g'`
 
if [[ ! -f ${INSTALLDIR}var/.maintenance.flag ]];
then
  #Cron 1
  if  ! ps uxwww | grep " [c]ron:run" | grep "$INSTALLDIR" 1>/dev/null 2>/dev/null ; then
        $PHP_BIN $INSTALLDIR/bin/magento cron:run | sed '/Ran jobs by schedule/d' &
  fi
fi
#Component and Upgrade crons run always
#Cron 2
if  ! ps uxwww | grep "setup:[c]ron:run" | grep "$INSTALLDIR" 1>/dev/null 2>/dev/null ; then
  $PHP_BIN $INSTALLDIR/bin/magento setup:cron:run &
fi
#Cron 3
if  ! ps uxwww | grep "update/cron.php" | grep "$INSTALLDIR" 1>/dev/null 2>/dev/null ; then
  $PHP_BIN $INSTALLDIR/update/cron.php &
fi

​You’ll also need to ensure that the above is executable for its owner (ie: the domain’s default FTP user). If you are not sure how to do this, please contact our Support team.

Finally you can test the cron from within Scheduled Tasks by selecting Run Now.

Securing Magento 2

The final step is now to properly secure your Magento 2 installation. Magento 2 has a great security feature whereby all files which are required to be web-accessible are in the /pub folder. The files in this folder are just the files needed to present the store to users. By making the /pub folder the webroot for your domain’s webspace, you massively reduce the surface area for potential attacks against your Magento install. To do this, log into your Plesk control panel. Browse to your domain then select the Hosting Settings tool. From here you can update your document root to httpdocs/pub or the relevant subdirectory. In this example I’m setting mine to httpdocs/shop/pub.

You’ll need to select OK to confirm the change you’ve made. Please note that this is only one step in securing your store: it’s a great start but should not be your one and only security concern!