Magento is a free, open-source CMS for web-commerce websites, first launched in 2008 and later acquired by eBay, according to W3Techs, Magento is used by 2.6% in all websites world-wide on the Internet, which is why it is important for a Linux admin to know how to install it on Linux machine which we will be explaining in this article.
- 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.
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 or later
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 Ubuntu/Debian, you will have to run the following commands in the terminal.
Note: On Ubuntu/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 $ sudo apt-get install php7.0-common php7.0-gd php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-iconv mysql-client mysql-server
Note: Currently, PHP 7.1.3 is the latest and most stable available version from the default Ubuntu and Debian repository, and works with Magento Community Edition 2.1 and 2.0.
If you’re using older Ubuntu or Debian distribution, consider upgrading to PHP 7.0 or later to adopt the new features of Magento CE (Community Edition).
$ sudo apt-get -y update $ sudo add-apt-repository ppa:ondrej/php $ sudo apt-get -y update $ sudo apt-get install -y php7.0 libapache2-mod-php7.0 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
2.Next, you need to increase PHP memory for Magento, to do this, open php.ini file.
$ sudo 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 upto 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 ## mysql> CREATE USER magento@localhost IDENTIFIED BY "your_password_here"; ## Create New Database ## mysql> create database magento; ## Grant Privileges to Database ## mysql> GRANT ALL ON magento.* TO magento@localhost; ## FLUSH privileges ## mysql> FLUSH PRIVILEGES; ## Exit ## mysql> exit
Step 3: Configure Apache for Magento
4. Now we will create a new virtual host file
example.com.conf for our Magento site under /etc/apache2/sites-available/.
$ sudo nano /etc/apache2/sites-available/example.com.conf
Now add the following lines to it.
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com ServerAdmin [email protected] DocumentRoot /var/www/html/example.com/ ErrorLog /var/www/html/example.com/logs/error.log CustomLog /var/www/html/example.com/logs/access.log combined <Directory /var/www/html/example.com/> Options Indexes FollowSymLinks MultiViews AllowOverride All </Directory> </VirtualHost>
Save and close the file.
5. Now, enable new virtual host (example.com.conf) and ‘mod_rewrite‘ module.
$ sudo a2ensite example.com.conf $ sudo a2enmod rewrite
6. We will disable the default virtual host configuration file to avoid any conflict with our new virtual host.
$ sudo a2dissite 000-default.conf
7. Finally, restart the Apache service.
$ sudo service apache2 restart
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.1.5, 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.
9. After you download Magento you may extract the downloaded file, place its content in /var/www/html/ using root permissions.
$ sudo mv Magento-CE-2.1.5-2017-02-20-05-36-16.tar.gz /var/www/html/example.com/ $ sudo tar -xvf Magento-CE-2.1.5-2017-02-20-05-36-16.tar.gz $ sudo rm -rf Magento-CE-2.1.5-2017-02-20-05-36-16.tar.gz
10. Now we need to set Apache ownership to the files and folders.
$ sudo chown -R www-data:www-data /var/www/html/example.com/
11. Now open your browser and navigate to the following url, you will be presented with the Magento installation wizard.
Step 5: Install Magento Community Edition
12. This will be the first step you see in the installation process of Magento, Accept the license agreement and click “Continue”.
13. Next, the wizard will perform a Readiness Check for the correct PHP version, PHP extensions, file permissions and compatibility.
14. 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 6: Magento Configuration
Magento is a very configurable CMS, the problem is that it isn’t easy, it is not like configuring WordPress or Drupal themes & modules, thats why we won’t talk a lot in this section here, however you may download Magento official user guide which will explain how to configure Magento from Bennington to advance for you.
- Magento Homepage
- Magento Documentaion
Have you ever tried Magento before? What do you think about it in comparing with other web-commerce CMSs? Please share your feedback using our comment section.