How to install Magento 2.3 and build a web server

IMPORTANT NOTICE: This tutorial has now been replaced with a new version for Magento 2.4.
See the new tutorial here

During this video, I’ll be showing you How to install Magento 2.3 and setup a web server. The video will be split into several chapters:

But before I start, I just want to acknowledge that this tutorial is not for everyone. The topics are aimed at nerds like myself who want to install Magento 2.3 from scratch. However, the tutorial has actually been designed for any skill level to follow.

If you’re interested in using Magento but would rather skip all of the nerdy stuff, then I would highly recommend the SIP-100 Package from Nexcess.net . They will build you a web server and install Magento 2.3 so you can just get straight on with setting up your store and adding your products. And if you ever run into any technical issues, you can always get in touch with their 24/7 support.

Note, that this video and article now replaces the previous article, called How to set up a web server for Magento 2.2.

About this article

This article will help you follow along with the video at your own pace. It will also contain any commands that I use so that you can easily copy and paste them. This means that you won’t have to keep squinting at your screen to see what I’m typing. To make it even easier, each of these steps will also contain a timestamp next to it so that you know exactly at what point in the video I’m using them.

Useful resources

Chapter 1: Build a basic server

As you can see, I have split my screen into 4 sections. We’ve got my web browser of choice (in this case Google Chrome), my SSH Client of choice (which is Putty for Windows – Available at Putty.org ), a breakdown of Chapters to help you quickly navigate through the video if you need to skip through it. And finally my notes, such as usernames and password that I’ll need to remember during the setup and installation.

On a side note, if you’re working from an Apple or Linux Operating System then you already have a built in SSH Client called Terminal.

So, let’s start building our Web Server so that we can install Magento 2.3. Don’t forget that you can follow along with me at your own pace by referring to this article that I wrote containing all of the commands that you’re going to see me use.

Create a Ubuntu Server

First things first, we need a web server. Personally, I use Digital Ocean for all of my Development Servers. The costs are reasonable and their services are spot-on. You can literally create a server in minutes. At the time of recording this, I have 8 servers running with them. If you do decide to try them, please consider using the link ( Digital Ocean ) as it goes towards supporting the channel. Plus it will also entitle you to some free credit. To be clear, you don’t have to use Digital Ocean – But beware that results may vary with another provider and it’s much easier to troubleshoot problems if we’re all using the same setup.

Create a new user

Now that we’ve logged in with the credentials that we’ve been emailed, we’ll be prompted again to reenter the password followed by a new one. This will be one of many passwords that you’ll want to take a note of for future reference.

With the new password in place, it’s time to create a new superuser that we can use instead of the root user to carry out our administrative tasks. This is a very common thing to do when building a new server as it adds to the security by minimising any brute force attacks. Plus, as a superuser you can’t accidently run root tasks without first prefixing your commands with “sudo”.

Important Tip
Once you copy the commands from this article, you can then paste them directly into Putty by right-clicking anywhere in the window

Create yourself a user [11:42]

adduser craig

Give this user ‘superuser’ (aka root) privileges by adding it to the ‘sudo’ group [12:28]

usermod -aG sudo craig

Now it’s time to logout as the root user and reconnect with our new user. From this point forward, you’ll notice me prefix most of my commands with “sudo” – This tells the operating system that you want to exercise your supervisor permissions in order to run an administrative task.

Disable the root user (for security)

Access config file to disable root user login [14:11]

sudo nano /etc/ssh/sshd_config

Use your Arrow or Page Up/Down keys to work your way down the file and find “PermitRootLogin yes”. You’ll want to replace the “yes” with a “no”. To save your changes, press Ctrl+X. Then you’ll be asked if you want to save your changes. Simply Type “Y” and then Enter to do so.

Now simply reload the SSH Service for the changes to take effect [15:37]

sudo systemctl reload sshd

Enable a basic firewall

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

sudo ufw allow ssh

Then turn on the firewall [16:42]

sudo ufw enable

You’ll get a warning, to make sure we’ve allowed SSH connections. So just type “Y” and hit Enter

Fantastic. So, just to quickly recap… We’ve built a server and carried out some very simple security practices. If this was your first time using SSH, I hope it wasn’t too intimidating for you. In a moment, we’re about to convert our Server into a Web Server that will support our Magento 2 installation.

digitalstartup-signup

Chapter 2: Convert to a web server for Magento 2.3

Now is the time to take our basic server and convert it into a web server that is capable of installing Magento 2.3. There are many commands coming up in this chapter, so pay very close attention to each step.

Updating repositories

We’ll start first by updating our server repositories. This tells Ubuntu what is available to download when we ask it to install sometime. Kind of like enabling your phone to access the App Store.

Luckily, our server comes with many repositories built-in. So, we only need to add one. This will allow us to download PHP 7.2 later in the chapter [18:34]

sudo add-apt-repository ppa:ondrej/php

Now we need to tell Ubuntu to update it’s records from all of the connected repositories, including the one we just added [18:55]

sudo apt-get update

Install Apache and configure it specifically for Magento 2.3

Now we’re ready to install and configure Apache. Apache is the software that will ultimately convert our basic server into a web server.

Install Apache [19:38]

sudo apt-get install apache2 -y

Open Apache settings file to allow .htaccess file usage [20:15]

sudo nano /etc/apache2/sites-available/000-default.conf

Add the below to the file, then save and exit [20:34]

<Directory "/var/www/html">
    AllowOverride All
</Directory>

Open Apache settings file to set the Global ServerName [20:51]

sudo nano /etc/apache2/apache2.conf

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

ServerName <server_IP>

Check for any errors [21:53]

sudo apache2ctl configtest

Enable Apache rewrite [22:44]

sudo a2enmod rewrite

Restart Apache for any changes to take effect [23:05]

sudo systemctl restart apache2

Enable Apache through the firewall [23:26]

sudo ufw allow 'Apache Full'

Test Apache

To test that Apache is working, we can run a super-quick test. Just put the IP address of your server in your browser. You should see a test page similar to this one.

Install PHP and any extensions specifically for Magento 2.3

Now, we need to install PHP. PHP is a scripting language which allows web applications like Magento to supercharge normal HTML pages. It’s a bit more complicated than that, but needless to say it’s a requirement for Magento.

Let’s start by installing PHP and all of the PHP extensions required in order for Magento 2.3 to run [25:01]

Important Update
I’ve adjusted the below commands to specify 7.2

sudo apt-get install php7.2 libapache2-mod-php7.2 php7.2-mysql php7.2-soap php7.2-bcmath php7.2-xml php7.2-mbstring php7.2-gd php7.2-common php7.2-cli php7.2-curl php7.2-intl php7.2-zip zip unzip -y

Tell the web server to prefer PHP files (move index.php to front of the list) [25:41]

sudo nano /etc/apache2/mods-enabled/dir.conf

Restart apache for changes to take effect [26:46]

sudo systemctl restart apache2

Install MySQL and secure the installation

Important Tip
Make sure that your MySQL root password password is:

  • Longer than 16 characters
  • Contains numbers
  • Contains lower & uppercase characters
  • Contains special characters

Now, it’s time to install and configure MySQL. MySQL is a database management system that allows the web server to store information that can be accessed by Magento.

Install MySQL [27:34]

sudo apt-get install mysql-server -y

Run a MySQL security script that addresses some vulnerabilities [28:22]

sudo mysql_secure_installation

Install phpMyAdmin and secure the installation

Important Tip
Make sure that your phpmyadmin password password is:

  • Contains numbers
  • Contains lower & uppercase characters
  • Contains special characters

At this point, we’ve got our web server to a point that is capable of running Magento 2.3. What we’re doing now though is installing phpMyAdmin. This is not required, but makes like so much easier when interacting with our MySQL Databases. It essentially allows us to log into a web page and make adjustments with your mouse and keyboard. As opposed to using the Command Line Interface.

Install phpMyAdmin [30:12]

sudo apt-get install phpmyadmin php7.2-mbstring php7.2-gettext -y

Make sure that you select apache2 using your SPACE BAR before hitting ENTER to continue. Restart Apache for any changes to take effect [33:36]

sudo systemctl restart apache2

Test phpMyAdmin

To test that phpMyAdmin works, you can do a simple test. Just put your IP address into your browser followed by /phpmyadmin . For example, 123.123.123.123/phpmyadmin . If you’ve successfully followed the steps then you’ll see this login page.

Awesome, that’s the most difficult part out of the way. It actually get easier from here on in. So it’s time to take a quick break and get yourself a coffee.

digitalstartup-signup

Chapter 3: Download Magento 2.3 with Composer

We’re now at the point where we can think about installing Magento 2.3. Just like the rest of this video so far, you will want to pay very close attention. It’s especially important that you run commands as the correct user as you’ll see issues further down the road that may not be obvious straight away.

Create a Magento user

So, let’s start by creating a Magento user. The reason for creating a new 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. This user will also be who you log in as to upload and download your files via FTP.

Add the user (I’ve called my user “magento”) [35:47]

sudo adduser magento

Make the web server group the primary group for the new user [36:25]

sudo usermod -g www-data magento

Folder permissions

When we installed Apache in Chapter 2, it automatically created a web directory to store own web files. However, it will have created this under the default user known as www-data. So, we just need to update the folder permissions for the directory that we’ll be installing Magento. This will allow our new Magento user to operate correctly.

Update the root file ownership to coincide with our new web user [37:20]

sudo chown magento:www-data /var/www/html/

Obtain your Magento Access Keys

Before you do anything else, be sure to visit https://marketplace.magento.com and create an account. Then you can generate a set of access keys that will allow you to download from the Magento repository via Composer.

Install Composer

Now that we have our keys, we’re ready to install Composer. Composer is an application that allows us to access and download packaged files from various repositories. Not only can we access and download Magento, but many 3rd party developers will recommend installing their extensions this way – As opposed to traditionally downloading a zip file and uploading it via FTP.

Install Composer by downloading the file direct from their website [40:14]

sudo curl -sS https://getcomposer.org/installer | php

Move composer file to the required directory [41:04]

sudo mv composer.phar /usr/local/bin/composer

Download Magento 2.3 via Composer

Now, it’s time to use composer to download Magento 2.3.

We first need to navigate to the web directory of our web server [41:38]

cd /var/www/html

Now, we need to switch from out superuser to the magento user that we created a few moments ago [42:01]

su magento

In order for Composer to work, it needs to be ran from within an empty directory – Otherwise it’ll create an error. However, the web directory we’re now sitting in isn’t empty because when we installed apache, it created a test file in the web directory called index.hml. This is the same file that we saw in Chapter 2 when we tested that Apache was working.

We can verify this by listing all file and folder inside the directory [42:47]

ls -la

So let’s delete that test file [42:58]

rm index.html

So, let’s not tell composer to install the latest copy of Magento – Which happens to be 2.3 at the time of creating this video. Make sure you don’t miss the Period at the end of the command. This insignificant looking dot tells composer to install it in the same directory from where we are running the command from. Missing this dot will cause Magento to install somewhere else [43:42]

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.3.0 .

During the setup, you will be asked for a Username and a Password. Just to be clear, Username = Public Key and Password = Private Key what we created on the Magento website. This process will take roughly 5 minutes to complete – So I will skip forward…

Set pre-installation permissions

You should now see a screen similar to this, where Putty is waiting for my next command. This is when we want to take a moment to set the necessary file permission in order for Magento to run correctly. It’s common to see an Error 500 message when trying to access Magento before doing this, so make sure not to miss this step.

This next command looks like a long one, but it is in fact 4 commands strung together – This will save us putting each command in one at a time [45:37]

find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chown -R :www-data . && chmod u+x bin/magento

Fantastic, we’re halfway there. You’ll probably be pleased to learn that we get to use the mouse a bit more during these next 2 chapters. If you’re new to the Digital Startup YouTube Channel , come and say hello in the Digital Startup Forum . You can share things you’ve learned, ask questions if you get stuck or simply help others who may need help. I’m very active over there, and it’s much easier to have a conversation on the forum that it is over the YouTube comments. I’ve dropped a link in the description if you’d like to say Hi.

Chapter 4: Create a database for installing Magento 2.3

This Chapter is super-easy and quick. We’ll just be logging into phpMyAdmin (that we installed in Chapter 2) and creating a Magento user and database.

Important Tip
Make sure that your MySQL magento password password is:

  • Longer than 16 characters
  • Contains numbers
  • Contains lower & uppercase characters
  • Contains special characters

Set up a user & database

  1. So visit HTTP://<your_server>/phpmyadmin
  2. Log in with your MySQL root credentials
  3. Once logged in, click User Accounts
  4. Then click Add user account
  5. Enter a username – I’ll call mine magento-master
  6. Change Host name to Local
  7. Generate a password and write it down safe
  8. Click the box below labelled “Create database with same name and grant all privileges.”, which will conveniently create a database for us at the same time as creating the user.
  9. Now hit Go at the bottom-right of the page

You’ve now successfully set up an isolated MySQL User than only has access to one specific database that it owns. A database that Magento will use to store all kinds of data such as settings, products details, customer details, sales and so on… I told you it would be a super-easy chapter.

Important Note: Refer to this post it you’re having issues with MySQL Authentication: Cannot log into phpMyAdmin as root user

digitalstartup-signup

Chapter 5: Install Magento 2.3 via the Setup Wizard

This is the point, where we get to load up Magento in our web browser for the first time. If for whatever reason you see an Error 500 message display when you try to load the web page, then go back and double check that you’ve completed the PHP sections and Folder permissions sections correctly.

Run Setup Wizard

  1. So, let’s load up Web Setup Wizard
  2. HTTP://<your_server>/setup
  3. Hit the orange button to proceed
  4. …continue to follow the prompts…

So, let’s make sure we can load our Frontend and Backend successfully. It’s normal for everything to run slow at first. The most regular issue you might come across is the pages not loading correctly. Anything from images and styling not loading on the frontend and the backend resulting in a 404. In almost all cases, this is down to Apache rewrites not being enabled. So revisit Install Apache and configure it specifically for Magento 2.3 section in Chapter 2.

Update memory_limit

Before you get too excited and start playing with Magento, we will want to increase our PHP memory_limit. By default, Magento will be using 756MB of your web servers available memory. This will commonly make Magento slow and result in some errors.

Open our .htaccess file [52:56]

nano .htaccess

Use your Arrow or Page Up/Down keys to work your way down the file and find a line containing memory_limit. You’ll actually find 2 instances in the file, one under PHP 5 and one under PHP 7. Just go ahead and change the instance under PHP 7. [54:01]

Replace 756MB with 2G

To save your changes, press Ctrl+X. Then you’ll be asked if you want to save your changes. Simply Type “Y” and then Enter to do so.

Install cron tasks

Next we need to set up our cron tasks. These are scheduled tasks that are required to run in the background. They assist with tasks like Indexing, Backups, Updates and so forth.

Luckily, this can now be setup by running one command [54:53]

bin/magento cron:install

Congratulations – You’ve just built a Web Server and installed Magento 2.3. If you ran into any problems along the way, feel free to reach out for help either:

  1. In the YouTube video comments
  2. In the article comments below
  3. On the Digital Startup Forum . You’ll probably get the best answers on the Forum, because we can hold a good conversation on there and share screen prints etc…

As we’ve come this far, I figured I’d throw in a bonus chapter to show you how to install Sample Data into Magento 2. This is useful if you’ve never used Magento before as it shows you what a standard setup looks like.

digitalstartup-signup

Chapter 6: Bonus – Install Sample Data

Switch to Developer Mode

Now that you’ve backed up your work, it’s time to switch Magento to Developer Mode. Magento has 3 modes, all designed to use optimal settings based on your usage. In Developer Mode, you can access more tools in the backend of Magento than any other mode. I’ll cover these Modes in more depth in a later video. [56:37]

bin/magento deploy:mode:set developer

Clear the cached generated folders [56:55]

rm -rf generated/metadata/* generated/code/*

Clear the remaining cache [57:08]

bin/magento c:c

Back your installation

It would be a shame to have spent all of this time building your web server and installing Magento 2.3, just to fill it with Sample Data. So, I would recommend creating a backup of your installation or your web server before doing anything else.

You could achieve this by backing up your Magento installation via the Web Setup Wizard. Alternatively, you could create a snapshot of your web server. This is one of the features I absolutely love about Digital Ocean.

Download Sample Data via Composer

Magento has a really useful command for installing all of the sample data from the Magento Repository via Composer. This step can normally take a couple of minutes to complete. At times, it may appear that nothing is happening, but just give it time.

Download the same data [01:01:10]

bin/magento sampledata:deploy

It’s been a couple of minutes and now Putty is awaiting our next command. All we need to tell Magento to do now is install the latest changes we’ve just made [01:01:56]

bin/magento setup:upgrade

Important Update
For some reason the 2 steps to install Sample Data result in all Caches being disabled. This has a huge performance impact on your web server. Therefore, I have added the following command to quickly re-enable the cache: bin/magento cache:enable

Now, when we refresh the Frontend and Backend, you can see what Magento now looks like with Sample Data.

Final words

Thank you again for sticking with the tutorial. I truly hope this video gave you the knowledge and the confidence to try this out for yourself. Don’t forget to like and subscribe if you found this video useful. And don’t forget to come visit the forum to share your experience, ask for help or even offer it. And until next time, take care.

5 Likes