Magento Open Source is a flexible e-commerce platform for developers and small businesses. The free open source edition comes with the performance and features to meet the requirements of the businesses of today. It is the perfect platform for growing small business sites or anyone who wishes to learn and experiment with building an online store.

Magento Open Source

Contents

Deploying a cloud server

If you have not already registered with UpCloud, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.

Once you have signed up, log into your UpCloud Control Panel and deploy a server.

Deploy a new cloud instance for hosting the Magento site, select an availability zone of your choosing and the Ubuntu 16.04 from the Public Templates. You can find in-depth instructions on all of the configuration options at the guide for How to Deploy a Server.

Upgrading the Magento applications and extensions can require up to 2GB of RAM to complete an upgrade successfully. For the best results, you should select a configuration with at least the recommended 2GB of system memory.

Installing prerequisites

Running a Magento site requires a basic web server functionality to operate. More specifically, you will need to install at least a web service like Apache2 or nginx, a database such as MySQL or MariaDB, and a PHP script preprocessor, or in other words, a LAMP stack.

In this section, you will find streamlined instructions for fulfilling each of these requirements by installing Apache2, MariaDB, and PHP.

Apache2

Start by installing Apache2 straight from the default repositories with the command below.

sudo apt-get install apache2 -y

Once installed, you need to enable rewrite for Magento to work correctly.

sudo a2enmod rewrite

Then create a new configuration file for the Magento Open Source site by opening a text editor with the next command.

sudo nano /etc/apache2/sites-available/magento2.example.com.conf

Enter the example configurations to the file, then save and exit the editor.

<VirtualHost *:80>
   ServerAdmin [email protected]
   DocumentRoot /var/www/html/magento2/
   ErrorLog /var/www/html/magento2/error.log
   CustomLog /var/www/html/magento2/access.log combined
   <Directory /var/www/html/magento2/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
   </Directory>
</VirtualHost>

Next, disable the default site and enable your Magento configuration.

sudo a2dissite 000-default.conf
sudo a2ensite magento2.example.com.conf

Create the following directory for the site.

sudo mkdir /var/www/html/magento2

Then restart Apache.

sudo systemctl restart apache2

With the first of the prerequisites installed, continue to the next step to install the database.

MariaDB

MariaDB is a popular open source alternative to the MySQL database server. It is available on Ubuntu default repositories, but for the latest version, you will need to add their own repo to your sources list with the commands below.

sudo apt install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb http://mirrors.coreix.net/mariadb/repo/10.2/ubuntu xenial main'

Once you have imported the key and added the repository, you need to update your sources and then install MariaDB. When installing the database, the installation script will ask you to set a password for the database, create a password for the root user when prompted.

sudo apt update
sudo apt install mariadb-server -y

When the database install is complete, you will need to configure MariaDB with a database for the Magento install.

Log into your database server using the root user and the password you set during the installation. Enter the following command to get to the MySQL command prompt.

mysql -u root -p

Enter the following commands in the order shown to create a database instance named magento2 with username magento with the same for the password.

MariaDB [(none)]> create database magento2;
MariaDB [(none)]> GRANT ALL ON magento2.* TO [email protected] IDENTIFIED BY 'magento';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

Using the exit command will quit the database client and return to the regular terminal.

Verify that the database was created successfully and that the new user is able to access it. Use the command below along with the password set to the user to log into the database.

mysql -u magento -p

Granted the database opened, exit the command prompt like before.

MariaDB [(none)]> exit

In case you get any errors, repeat the preceding commands in the database command prompt on the root user and try again.

PHP 7.0

The last part of the LAMP stack is the hypertext preprocessor or PHP in this case. Magento also requires a number of additional PHP packages. Install PHP 7.0 along with all of the needed extras using the rather long command below.

sudo apt install php7.0 php7.0-curl php7.0-mysql libapache2-mod-php7.0 \
php7.0-bcmath php7.0-curl php7.0-gd php7.0-intl php7.0-mbstring php7.0-mcrypt \
php7.0-soap php7.0-xml php7.0-xsl php7.0-zip php7.0-json php7.0-iconv -y

Once all of the PHP packages have been installed, you should make a couple of quick changes to the configuration files.

Open the first file with the command underneath.

sudo nano /etc/php/7.0/cli/php.ini

Find the row that defines the max_execution_time and set the value to 180 like below, then save and exit the editor.

max_execution_time = 180

Use the next command to open the other configuration file.

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

It will also contain a max_execution_time that should be set to a little higher value.

max_execution_time = 180

In the same file, you will find a memory_limit that can be increased accordingly depending on your cloud server configuration. For example, on the basic 2GB preconfigured instance you should set the memory_limit to 1024M.

memory_limit = 1024M

Afterwards, save the changes and exit the editor.

With the PHP configured, your LAMP stack is then ready to host Magento Open Source. Continue below with the instructions to downloading and setting up your e-commerce site.

Downloading Magento

Magento is available for download in multiple versions and via a couple of channels. The open source version can be downloaded either manually from Magento’s product files or from their GitHub repository. You also have the option to download the Magento source with ready-to-go sample data included to get an example site up and running in no time at all.

Regardless of the method used to download Magento packages, you will need to start by registering and logging into a Magento account.

Once you have registered with Magento, start off the server side configurations by creating a new user for running Magento without root priveledges.

sudo adduser --disabled-password --gecos "" magento
sudo adduser magento www-data

Then choose the option for downloading Magento you wish to use and continue below.

Option 1. Manually with Access Token

Log into your Magento account and go to the Download Access Token under Account Settings menu. There you will find your Magento ID and the access token options which can be used to download Magento packages on the command line.

Click the link to Generate new token.

Then use the following command to check the available Magento downloads while replacing the <ID> and <TOKEN> with your credentials.

curl -k https://<ID>:<TOKEN>@www.magentocommerce.com/products/downloads/info/filter/version/2.*

You can download any specific file using the correct path and filename, for example .../downloads/file/Magento-CE-2.1.9.tar.gz for that version without sample data.

Download the package version you wish, e.g. with the sample data using the command below.

curl -k -O https://<ID>:<TOKEN>@www.magentocommerce.com/products/downloads/file/Magento-CE-2.1.9%2BSamples.tar.gz

When the download finishes, create a directory for the files and extract the package.

mkdir ~/magento2
tar zxvf ~/Magento-CE-2.1.9%2BSamples.tar.gz -C ~/magento2/

Then copy the files to the web server directory.

sudo cp -R ~/magento2 /var/www/html/

With the Magento downloaded and copied over, jump forward to the next section to continue configuring the site.

Option 2. Using Composer and GitHub

Magento Open Source is also available for download on the GitHub which might be a preferred alternative, especially to developers. To use the Magento GitHub repository, you will need to install and setup Composer.

Download and install Composer with the following command.

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

You will also need to create a folder for Composer in the Magento user’s home directory.

sudo mkdir /home/magento/.composer

Next, log into your GitHub account and create a new Access token. You can find instructions for how to do this at the GitHub help article.

Leave the page open with your access token for the moment and log into your Magento account. Open the Marketplace tab and click Access Keys section.

On the Access Keys page, click the button to Create a New Access Key, give the key pair a name and then click OK.

Magento developer documentation has additional instructions for using your Access Keys.

Once you have generated both your GitHub access token and Magento access keys, create a new file in the Composer directory called auth.json.

sudo nano /home/magento/.composer/auth.json

Enter the following information while replacing the <github-token> with the access token to your GitHub account and the Magento public and private keys respectively.

{
   "github-oauth": {
      "github.com": "<github-token>"
   },
   "http-basic": {
      "repo.magento.com": {
         "username": "<magento-public-key>",
         "password": "<magento-private-key>"
      }
   }
}

Save the file and exit the editor, then fix the file ownership of the .composer directory.

sudo chown magento:magento -R /home/magento/.composer

You are then ready to clone the repository, change into the HTML root directory.

cd /var/www/html

Check that you have git installed.

sudo apt install git

Then clone the repository with the command below.

sudo git clone https://github.com/magento/magento2.git

Update the directory ownership.

sudo chown www-data:www-data -R /var/www/html/magento2

Next, switch to the magento user.

sudo su magento

Change into the Magento site directory.

cd /var/www/html/magento2

Then use Composer to install the site.

composer install

Once completed, continue to the last part of this guide to finalize the Magento installation.

Configuring the Magento install

The final part of installing Magento Open Source is to configure the site admin and a few other available options. This can be performed either on command line or following the install wizard in a web browser.

Before continue, double check that the Magento installation directory has the appropriate permissions. Change into the site directory.

cd /var/www/html/magento2

Make sure the web server has the ownership over the files.

sudo chown -R www-data:www-data .

Then set the following permissions per each file and folder.

sudo find . -type d -exec chmod 775 {} \;
sudo find . -type f -exec chmod 664 {} \;

These permission updates might take a moment to process because of the number of files and folders, especially with sample data included.

Next, add the indexing cron jobs shown underneath to the magento user’s crontab. Open the crontab in an editor with the command below.

sudo crontab -u magento -e

Choose the editor you wish to use, then copy the following lines to the file, save and exit.

* * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run | grep -v 'Ran jobs by schedule' >> /var/www/html/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/update/cron.php >> /var/www/html/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento setup:cron:run >> /var/www/html/magento2/var/log/setup.cron.log

Finally, restart Apache to apply all the changes.

sudo systemctl restart apache2

As mentioned above, you have two options for finalizing the Magento Open Source installation; in web browser guided wizard or a command line configuration tool. Continue below with the method you prefer.

Option 1. In browser configurations

Once all of these are set, you can continue in your web browser by opening your cloud server’s public IP or domain. You can find your server’s IP addresses in your UpCloud Control Panel under Network menu.

http://<public IP>

Follow the instructions presented in the installation wizard to set up the site.

1. Start by running the readiness checks, the results should show all green.

Magento web install - Readiness check

2. Enter the database details as configured earlier while installing MariaDB.

Magento web install - Database settings

3. Check your site configurations and updated as necessary. You can set the store to use a domain if you have one configured for the server. And while the admin default URL is just fine, you might wish to change it to something easier to remember.

Magento web install - Web configuration

4. Customize your store with the available time zone, currency and language options or continue along with the defaults.

Magento web install - Customize your store

5. Enter user details for your admin account.

Magento web install - Admin account

6. When you are done with the options, click the Install Now button to let the system do its thing. This might take a moment.

Magento web install - Start install

Success! Once finished, you will be presented with a summary of your site configurations. The page includes your website and admin URLs which you might want to bookmark for later.

Magento web install - Install successful

After successfully installing Magento Open Source, disable write access to the following directory with the command below for security purposes.

sudo chmod -w /var/www/html/magento/app/etc

Option 2. Command line configurations

Alternatively, you can make the last configurations also on the command line with the help of the magento tool in the .../magento2/bin/ directory.

First, make the file is executable with the following command.

sudo chmod +x /var/www/html/magento2/bin/magento

You can check the available configuration options over at Magento developer documentation for command line install.

The following example command includes the minimum parameters to get the site installed. Replace the <public IP> with your server’s public IP address or domain name if you have one. You can find your server’s IP addresses in your UpCloud Control Panel under Network menu.

/var/www/html/magento2/bin/magento setup:install --admin-firstname="admin" --admin-lastname="admin" --admin-email="[email protected]" --admin-user="magento" --admin-password="magento2" --db-user="magento" --db-password="magento" --base-url="http://<public IP>"

The installation will take a moment.

Once completed, you will see an output similar to the one below confirming the installation and showing your admin URL.

[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_148ohr

For security, remove write permissions from the following directory with the command below.

sudo chmod -w /var/www/html/magento2/app/etc

Then restart Apache and your site will be available for testing.

sudo systemctl restart apache2

If you have problems opening the site, rerun the following command to make sure the web server has access rights to the whole /magento2 directory.

sudo chown -R www-data:www-data /var/www/html/magento2

Summary

Congratulations! You should now have a fully functional Magento Open Source e-commerce site up and running.

Magento boasts the largest and most active community of developers and merchants in the world. Developers share innovative ideas, help each other, and collaborate to improve the capabilities and performance of the Magento Open Source platform. With the help of the comprehensive documentation available for Magento, you can easily join the community to begin designing your own commerce extensions or build the next hit marketplace.