Magento 2 Training : Unit 1 – Lesson A

Magento 2 is available after many years of waiting. Source code is on Github, and we will see how to install this new version and how to configure it.

Prerequisites

Before installing Magento 2 you need to :
– Have Linux OS like RedHat Enterprise Linux (RHEL), CentOS, Ubuntu, Debian etc…
Composer (Dependency Manager for PHP) (Install curl et php5-cli packages before)
– Apache 2.2 or 2.4 / Or Nginx 1.8
– PHP 5.6.x or 5.5.22 (or greater), or 7.0.2 (since Magento 2.0.1)
– Following PHP extensions :
* bc-math (For Magento Enterprise)
* curl
* gd, ImageMagick 6.3.7 (or later) or both
* intl
* mbstring
* mcrypt
* mhash
* openssl
* PDO/MySQL
* SimpleXML
* soap
* xml
* xsl
* zip

– MySQL 5.6 or later
– Mail Transfer Agent (MTA) or SMTP server
– Not required but recommanded :
* php_xdebug2.2.0 or later (only on development environment)
* PHPUnit 3.7 or later

Type this command line to install all the php packages above :

sudo apt-get install curl php5-mysql libapache2-mod-php5 php5-mcrypt php5-curl php5-gd php5-imagick php5-xdebug phpunit php5-intl php5-xsl

You can do phpinfo() in order to see installed packages on your server.

Composer and Magento

Composer manage dependencies during the installation. Open your shell and type these commands :

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Clone Magento 2 Github repository

Install git if you haven’t got it :

sudo apt-get install git

Go inside the folder you want to install Magento 2 (On Apache it’s often /var/www and on Nginx, /usr/share/nginx/html) and launch cloning :

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

We choose the “2.1” branch in order to have the “officiel” branch.
You can clone “develop” branch if you want to have latest commit from the magento team.

 Composer launch

Go on the root folder of Magento 2 (cd magento2) and type :

composer install

Composer will install dependencies automatically !
Don’t run with sudo, if you have error during the installation, try to delete the “/home/<USER>/.composer” folder.

If you have a message like “enter your GitHub credentials to go over the API rate limit”, go on the Github website, create your account. When it’s okay, type your login and password on the shell.

If you have a message like “please create a GitHub OAuth token to go over the API rate limit”, go on the Github website to create a token. When you’ve got the token number, paste it on the shell.

If you have a message like “Authentication required (repo.magento.com):”, go on the Magento website, create an account. Sign in and go on “Developper > Secure Keys” section. Create a new key – I named it “magento 2 – the public key will be the username, and the pricate key, the password. Put these keys on your shell prompt and continue the installation.

 

Ownership and permissions creation

To find the user you need, type this commande :

  • Ubuntu / Apache: ps -ef | grep apache2
  • Ubuntu / Nginx : ps -ef | grep nginx

In my case, the user is “www-data”. I will use this value during the next steps, change it if you have a different value.
Get the user’s group, it can be the same value as the user :

groups www-data

Go on the magento 2 root folder(/usr/share/nginx/html/magento2 or /var/www/magento2), and type this command :

cd /var/www/magento2
sudo chown -R :www-data .

On the same folder, set permissions 770 on folders, 660 on files :

sudo find . -type d -exec chmod 755 {} \; && sudo find . -type f -exec chmod 644 {} \; && sudo chmod u+x bin/magento; sudo chmod -R g+w ./{pub,var}; sudo chmod -R g+s ./{pub,var}

Add your current linux user on the www-data group (à adapter selon votre installation) :

sudo adduser <username> www-data

Don’t forget to close session and reconnect to reload the new permissions !

Magento 2 Setup Wizard

You can access on your local URL to launch the setup.
Here some configuration for apache :

sudo vi /etc/hosts

Add the line :

127.0.0.1 magento2.lan

Add create a new vhost:

sudo vi /etc/apache2/sites-available/magento2.conf

Here is what I put in the file :

<VirtualHost *:80>
    ServerName magento2.lan
    DocumentRoot /var/www/magento2
    SetEnv MAGE_MODE "developer"
    <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>

Make a symbolic link to activate the vhost :

sudo ln -s /etc/apache2/sites-available/magento2.conf /etc/apache2/sites-enabled/magento2.conf

Don’t forget to restart apache :

sudo service apache2 restart

Type the URL on your web browser and follow the installation step by step.

If you have some problems, ask your question on the comments or search if a solution is on this page : https://github.com/magento/magento2#troubleshooting

If you want to install Magento 2 with commands line, go on the Magento official documentation !

Installation Troubleshooting

Change xdebug.max_nesting_level configuration

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

Add the following line :

xdebug.max_nesting_level=200

Restart apache :

sudo service apache2 restart

Create “magento2” database

It’s the name I choose, you can choose another name.

Update to MySQL 5.6

Launch the following command :

sudo apt-get install mysql-server-5.6

This will delete the old version of MySQL at the same time.

PHPStorm change file owner on save

Go on PHPStorm settings :
Settings > Appearance & Behavior > System Settings
Disable “safe write” option

Continue training
Install Magento 2
Share on FacebookTweet about this on TwitterShare on Google+Email this to someone
Tagged on:         

Leave a Reply

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

We use cookies to ensure that we give you the best experience on our website.
Ok