How to install latest Magento 2 CMS in Debian 9

Magento is an open-source e-commerce platform written in PHP. The software was originally developed by Varien, Inc, a US private company headquartered in Culver City, California, with assistance from volunteers.

Varien published the first general-availability release of the software on March 31, 2008. Roy Rubin, former CEO of Varien, later sold a substantial share of the company to eBay, which eventually completely acquired and then sold the company to Permira.

Magento Features

  • Free and open-sourced.
  • Built using PHP, Zend framework and MySQL database.
  • Can easily be used to create online web-stores.
  • Ability to install & change default website theme, without need to change the content.
  • Ability to install & configure modules to add more functionality.
  • 3 Available editions to use which are: Community Edition – Professional Edition – Enterprise Edition.
  • Supported by a large community.

Requirements
This article will guide you to install the most recent version of “Community Edition” of Magento on a system running:

  • Apache version 2.2 or 2.4
  • PHP version 5.6 or 7.0.x or later with required extensions
  • MySQL version 5.6, 5.7 or MariaDB.

Step 1: Install Apache, PHP and MySQL

1. Magento is a PHP script, that uses MySQL database, thats why we will need a running web-server and a MySQL database server with PHP Support, to install those things on Debian, you will have to run the following commands in the terminal.

Note: On Debian, during mysql installation, it will prompt you to setup password for mysql user (i.e. root) by default.

apt-get update && apt-get upgrade
apt-get install php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-bcmath php7.0-iconv php7.0-soap mysql-client mysql-server

Note: Currently, PHP 7.0.27 is the latest and most stable available version from the default Debian repository.

If you’re using older Debian distribution, consider upgrading to PHP 7.0 or later to adopt the new features of Magento CE (Community Edition).

apt-get -y update
add-apt-repository ppa:ondrej/php
apt-get -y update
apt-get install -y php7.0 libapache2-mod-php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-bcmath php7.0-iconv php7.0-soap

2. Next, you need to increase PHP memory for Magento, to do this, open php.ini file.

nano /etc/php/7.0/apache2/php.ini

Seach for the line ‘memory_limit‘ in the file.

memory_limit = 128M

And change the value to 512.

memory_limit = 512M

Once all the required packages has been installed on the system/server successful, now move forward to create a new MySQL database for Magento installation.

Step 2: Create MySQL Database for Magento

3. This section instructs, how to create a new database and new user for Magento. Although a new magento database is recommended, but optionally you can also deploy into an existing database, it’s up to you.

To create a new database and a user, login to your database server using root account and password that you’ve created during mysql-server installation above.

mysql -u root -p
## Creating New User for Magento Database ##
MariaDB [(none)]> CREATE USER magento@localhost IDENTIFIED BY "your_password_here";
## Create New Database ##
MariaDB[(none)]> create database magento;
## Grant Privileges to Database ##
MariaDB [(none)]> GRANT ALL ON magento.* TO magento@localhost;
## FLUSH privileges ##
MariaDB [(none)]> FLUSH PRIVILEGES;
## Exit ##
MariaDB [(none)]> exit

Step 3: Configure Apache for Magento

4. Now we will create a new virtual host file kvm1.prado.lt.conf for our Magento site under /etc/apache2/sites-available/.

nano /etc/apache2/sites-available/kvm1.prado.lt.conf

Now add the following lines to it.

<VirtualHost *:80>
    ServerName kvm1.prado.lt
    ServerAlias www.kvm1.prado.lt
    ServerAdmin webmaster@localhost
    DocumentRoot /home/kvm1/public_html/

    ErrorLog /home/kvm1/logs/error.log
    CustomLog /home/kvm1/logs/access.log combined

    <Directory /home/kvm1/public_html/>
        Require all granted
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
    </Directory>
</VirtualHost>

Save and close the file.
5. Now, enable new virtual host (kvm1.prado.lt.conf) and ‘mod_rewrite‘ module.

a2ensite kvm1.prado.lt.conf
a2enmod rewrite

6. We will disable the default virtual host configuration file to avoid any conflict with our new virtual host.

a2dissite 000-default.conf

7. Finally, restart the Apache service.

systemctl reload apache2

Step 4: Download Magento Community Edition

8. As usual, we’ll download the latest version from the official website, at the time of writing this article, the latest version from the Community Edition is 2.2.4, which you can download using the following link, it is under the “Full Release” section, of course, you need to register first before downloading Magento.

http://www.magentocommerce.com/download

9. After you download Magento you may extract the downloaded file, place its content in /home/kvm1/public_html/ using root permissions.

mv magento2-2.2.4.tar.gz /home/kvm1/public_html/
tar -xvf magento2-2.2.4.tar.gz
rm -rf magento2-2.2.4.tar.gz

10. Now we need to set Apache ownership to the files and folders.

chown -R kvm1:kvm1 /home/kvm1/public_html/

11. Now open your browser and navigate to the following url, you will be presented with the Magento installation wizard.

http://kvm1.prado.lt

Step 5: Vendor autoload installation

12. Now open your system/server console and run ‘composer install’ under application root directory.

Step 6: Permissions

The important things:

The owner of the Magento file system: Must have full control (read/write/execute) of all files and directories.

Must not be the web server user; it should be a different user.

The web server user must have write access to the following files and directories: var app/etc pub (and probably new in 2.2.1:) generated

In addition, the web server’s group must own the Magento file system so that the Magento user (who is in the group) can share access to files with the web server user. (This includes files created by the Magento Admin or other web-based utilities.)

We recommend setting the permissions as follows:

All directories have 770 permissions.
770 permissions give full control (that is, read/write/execute) to the owner and to the group and no permissions to anyone else.
All files have 660 permissions.
660 permissions mean the owner and the group can read and write but other users have no permissions.

You should set as bellow recommended.

cd /home/kvm1/public_html/
mkdir generated
chown -R: generated
chmod 777 generated

find . -type f -exec chmod 644 {} \;                        // 644 permission for files
find . -type d -exec chmod 755 {} \;                        // 755 permission for directory 
find ./var -type d -exec chmod 777 {} \;                // 777 permission for var folder    
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;

chmod 777 ./app/etc
chmod 777 ./app/etc/NonComposerComponentRegistration.php
chmod 777 ./app/etc/vendor_path.php
chmod 777 ./app/etc/di.xml
chmod 777 ./var/.htaccess
chmod 777 ./var/composer_home/.htaccess
chmod 777 ./pub/media/theme_customization/.htaccess
chmod 777 ./pub/media/.htaccess
chmod 777 ./pub/media/downloadable/.htaccess
chmod 777 ./pub/media/customer/.htaccess
chmod 777 ./pub/media/import/.htaccess
chmod 777 ./pub/static/.htaccess
chmod 644 ./app/etc/*.xml

chown -R : .

chmod u+x bin/magento

Step 7: Install Magento Community Edition

13. This will be the first step you see in the installation process of Magento, Accept the license agreement and click “Continue”.

14. Next, the wizard will perform a Readiness Check for the correct PHP version, PHP extensions, file permissions and compatibility.

15. Enter magento database settings.

16. Magento Web site configuration.

17. Customize your Magento store by setting timezone, currency and language.

18. Create a new Admin account to manage your Magento store.

19. Now click ‘Install Now‘ to continue Magento installation.

 

Step 8: Magento Configuration

Magento is a very configurable CMS, the problem is that it isn’t easy, however you may download Magento official user guide which will explain how to configure Magento from Beginning to advance for you.

Magento Homepage

Magento Documentaion

Leave a Reply

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