Introduction
Magento is a robust e-commerce platform that enables developers and online entrepreneurs to create and customize online stores in minutes. The platform is written in PHP, and it requires database and web servers to run successfully. On the other hand, Ubuntu is an open source platform that delivers technical and economic scalability to meet enterprise-level server needs.
This tutorial will help you install the latest version of Magento on Ubuntu 18.04 LTS. We’ll use the LAMP (Linux, Apache2, MySQL, and PHP) stack to install Magento 2 on your Linux distribution. To accomplish this, let’s follow the steps below.
Prerequisites
First, you should ensure your system is up-to-date. Run the commands below to update and upgrade your system:
$ sudo apt-get update -y $ sudo apt-get upgrade -y
Step 1 – Installing Apache2
As aforementioned, Magento requires a web server to run commendably. For this reason, we’ll first install Apache2 which is one of the most popular web servers in the modern tech world. Run the command below to install Apache2:
$ sudo apt-get install apache2
Next, run the command below to deactivate the directory listing:
$ sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/apache2/apache2.conf
Once Apache2 is installed run the command below to start and enable the service:
$ sudo systemctl start apache2.service $ sudo systemctl enable apache2.service
Step 2 – Installing MariaDB
By now the web server is set. Next, we install the database server, and MariaDB is always a great platform to start with. Run the commands below to install MariaDB.
$ sudo apt-get install mariadb-server mariadb-client
Use the commands below to start and enable the database server:
$ sudo systemctl start mariadb.service $ sudo systemctl enable mariadb.service
Next, run the command below to secure the database server:
$ sudo mysql_secure_installation
Here, you will be prompted to answer the following questions:
- Enter current password for root (enter for none): since you have just installed MariaDB and have not set the root password yet, the password value is blank. Press Enter to continue.
- Set root password? [Y/n]: Type Y and press Enter to continue
- New password: Enter your preferred password
- Re-enter new password: Re-type the password and press enter to continue
- Remove anonymous users? [Y/n]: Type Y, then press enter
- Disallow root login remotely? [Y/n]: Type Y and press enter
- Remove test database and access to it? [Y/n]: Type Y, then press enter
- Reload privilege table now? [Y/n]: Type Y and press enter.
Restart the database server:
$ sudo systemctl restart mariadb.service
Step 3 – Installing PHP 7.1 And Its Related Modules
Ubuntu default repositories don’t provide PHP 7.1, and that means you have to install the application from third-party repositories.
The commands below will help you add 3rd party repository for PHP 7.1:
$ sudo apt-get install software-properties-common $ sudo add-apt-repository ppa:ondrej/php
To update and upgrade to the required PHP version (7.1), run the command below:
$ sudo apt update
Next, run the following command to install PHP 7.1 together with its related modules:
$ sudo apt-get install php7.1 php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-gd php7.1-xml php7.1-intl php7.1-mysql php7.1-cli php7.1-mcrypt php7.1-ldap php7.1-zip php7.1-curl
Step 4 – Creating Magento Database
By now, all the packages required to support Magento 2 installation are ready. Next, we’ll create a blank database for Magento. To accomplish this, first, login to the MariaDB server:
$ sudo mysql -u root -p
You will be prompted for your MariaDB Server password. Enter the password and click Enter to continue.
Run the following commands to create a new database titled Magento.
CREATEDATABASE magento;
Next, create a user called magentouser and assign the user a new password, using the commands below:
CREATEUSER'magentouser'@'localhost'IDENTIFIEDBY'new_password_here';
Then grant, the user you’ve created unlimited access to the new database:
GRANT ALL ON magento.* TO'magentouser'@'localhost'IDENTIFIEDBY'user_password_here'WITHGRANTOPTION;
Save the changes and exit:
FLUSHPRIVILEGES; EXIT;
Step 5 – Downloading The Latest Magento Release
Create an account on Magento website to get the right to download a copy of the application. Download the community edition of Magento.
Next, run the following commands to extract the file into your Apache2 root directory:
$ sudo mkdir /var/www/html/magento/ $ sudo tar -zxvf ~/Downloads/Magento-CE*.tar.gz -C /var/www/html/magento/
You will need to alter the directory permission to suite the Apache2 configuration:
$ sudo chown -R www-data:www-data /var/www/html/magento $ sudo chmod -R 755/var/www/html/magento
Step 6 – Configuring Apache2
By now the installation is almost complete, but we need to configure Apache2 website configuration file for your Magento store. This configuration file dictates how your site visitors access the Magento content.
First, we create the configuration file and name it magento.conf:
$ sudo nano /etc/apache2/sites-available/magento.conf
Next, paste the following content into the configuration file and save.
Note: Replace example.com and www.example.com with your own credentials.
<VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot /var/www/html/magento/ ServerName example.com ServerAlias www.example.com <Directory /var/www/html/magento/> Options Indexes FollowSymLinks MultiViews AllowOverrideAll Order allow,deny allow from all </Directory> ErrorLog${APACHE_LOG_DIR}/error.log CustomLog${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Save and exit
Step 7 – Enabling The Rewrite Module and Magento
Once the virtual host is configured, run the commands below to enable it:
$ sudo a2ensite magento.conf $ sudo a2enmod rewrite
Step 8 – Restarting Apache2
Run the command below to restart the service:
$ sudo systemctl restart apache2.service
Restarting Apache2 allows all the settings changes to take effect.
Step 9 – Setting Up The Magento Store
Open a web browser and search your server domain name (http://example.com). This will present the Magento setup wizard. Follow the instructions in the wizard to complete the setup.
Readiness Check
Click Start Readiness Check to initiate the process:
Adding Database Information
Next, enter your database credentials
Click Next to move to the next step, Follow the instructions carefully and continue until you get to Create Admin Account.
Creating Admin Account
Enter all the required details
Continue until the setup is complete:
That is it!
Conclusion
You have successfully installed Magento on your Ubuntu 18.04 server. Thank you for using this tutorial to install one of the most popular, open source eCommerce platforms. All the best as you embark on a mission to trade online.
Check out these top 3 Magento hosting services:
- Your query to the best web hosting can end by clicking on this link.