How to install Magento2

Hello everyone, in this tutorial , we'll see how to install Magento2 !

For this tutorial, I suppose you are under Linux (here Ubuntu) but if you are on Windows or Mac the principles remain the same, you just need to adapt.
As editor, I used vim (but you can also do it with any text editor). If you want to install it, use the following command:


apt-get install vim

Of course, we also assume for this tutorial that you have already installed apache2, php with the recommendations of magento (php_curl, activate url rewrite ...). If this can help, I create a docker container that will help you run this tutorial here: https://github.com/pierrefay/docker-apache2php7mysql

Minimum system requirements for installing magento2:

In order to install magento2 you will need: - Being on Linux (Ubuntu, RHEL, CentOS, Debian ...)
- Have installed Apache (2.2 or 2.4)
- Have installed MySQL 5.6 or higher (Oracle and MS SQL Server is possible too)
- Have installed PHP 5.6 (minimum)

This is the minimum , prefer a good php7 and recent versions of apache and mysql;) With the following extensions:
PDO / MySQL, MySQLi, mbstring, mcrypt, mhash, simplexml, DOM, curl, gd2 or / and ImageMagick 6.3.7 (or higher) soap

- Have installed an SMTP server or a Mail Transfer Agent (MTA)
personally i like exim4

Now that everything is ok on your machine, let's get to the heart of the matter ...

Install the www.magento2.lan domain name and create my vhost:

Point your domain name to your local, add the domain name in your hosts file

vim /etc/hosts

And add the following line : (here my domain name is www.magento2.lan)

127.0.0.1 www.magento2.lan

Add the virtualHost :

vim /etc/apache2/sites-available/magento2

Edit your vhost file like this :

<VirtualHost *:80>
    ServerName www.magento2.lan
    ServerAlias magento2.lan
    DocumentRoot /var/www/magento2
    <Directory /var/www/magento2>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/magento2_error.log

    # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/magento2_access.log combined
</VirtualHost>

Then activate your vhost and reboot (or reload with apache2 reload service ) apache:

a2ensite magento2
service apache2 restart

dont forget to activate the rewrite mod of apache2:

a2enmod rewrite
service apache2 restart

Save and close your browser ( echap > :wq )

Create the database for magento2

First we will list our databases and we will create one called magento2:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> create database magento2;
Query OK, 1 row affected (0.00 sec)

Install the magento2 files

For this part, I assume that GIT is installed on your pc. If it is not here how to install it:

apt-get install git

To install magento2 from the GIT repo, you can launch the following commands :

cd /var/www/
git clone https://github.com/magento/magento2.git

Install Composer if it is not already done and install magento

url -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
cd magento2 && composer install

Here your files are installed !

Provide the ability to write to var, media, pub

Modify the rights on your server to give the system write access to the folders pub/media/, var/, pub/static/ and app/ etc (to see your css during the installation for example).

chmod -R 777 var/
chmod -R 777 pub/
chmod -R 777 app/etc/

For more security, do not make 777 on your machines prod eh !! ^^
Here you can now use the magento2 installer!
If after the installation you have CSS that are not present , the layout of magento is broken ... you had a rights issue somewhere in these folders and magento2 could not create CSS files (or themes folders). Change the rights, delete the app/etc/local.xml file and redo the installation !

Use the magento2 installer

You can now log in with your browser on www.magento2.lan, so follow the installation procedure:

Here is "clic clic", you enter the necessary info and it should work :)

ERREOR : "Host 'apache2.dockerapache2mysql_default' is not allowed to connect to this MySQL server"
2 possibles cases :
- you didn't change the bind adresse of mysql to 0.0.0.0 in your my.cnf file

root@51ca7e014513:/$ vim /etc/mysql/mysql.conf.d/mysqld.cnf 
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0

- the mysql user didn't have the right to connect to your database remotely:

mysql> CREATE USER 'pfay'@'%' IDENTIFIED BY 'pfay123';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'pfay'@'%' IDENTIFIED BY 'pfay123';              
Query OK, 0 rows affected, 1 warning (0.00 sec)

How to install sample datas for magento2 ?

We will first go into our directory of magento2, at the root and we will clone the project magento2-sample-data, we will then put the right rights on the folder then we will run the script that allows to create links with samples Datas. We then launch the update and that's it ... magento2 is installed with the samples datas!
Here's how:

root@e63dc125d882:/var/www/html/magento2$ git clone https://github.com/magento/magento2-sample-data.git
root@e63dc125d882:/var/www/html/magento2$ chown www-data:www-data -R magento2-sample-data/            
root@e63dc125d882:/var/www/html/magento2$ php -f magento2-sample-data/dev/tools/build-sample-data.php -- --ce-source="./"                                
root@e63dc125d882:/var/www/html/magento2$ ./bin/magento setup:upgrade

Congratulations to you who installed Magento2! Now you will be able to follow the tutorials to learn how to develop under Magento2!

Do not hesitate to ask your questions in the comments. Good luck to all for the continuation of the tutorials.
Books that can help you :
  • Livre Magento 2 Developer's Guide by Branko
  • Livre Mastering Magento2 Second Edition
  • Livre Magento 2 Cookbook
Questions about this lesson
No questions for this lesson. Be the first !

You must be logged in to ask for help on a lesson.