Magento is one of the most popular open-source e-commerce platforms available today. It offers a rich set of features that provide an unparalleled e-commerce experience. Magento is highly customizable, scalable, and designed to handle large amounts of data, making it ideal for businesses of all sizes. Whether you are a small business looking to expand your online presence or a large enterprise needing a robust platform to manage your sales, Magento has the tools to help you succeed.
How to Install Magento2 on Ubuntu
In this tutorial, we will walk you through the process of installing Magento on an Ubuntu server. By the end of this tutorial, you will have a fully functional Magento store up and running. We will cover everything from installing the necessary software to configuring your server and setting up Magento.
Step 1: Install Apache and PHP
First, we need to install Apache, PHP, and Composer. Apache is the web server, PHP is the scripting language, and Composer is a dependency manager for PHP.
- Open your terminal.
- Update your package list:
sudo apt update
- Install Apache:
sudo apt install apache2
- Install PHP and necessary PHP extensions:
sudo apt install php libapache2-mod-php php-mysql php-xml php-curl php-intl php-soap php-zip php-gd php-bcmath php-mbstring
- Install Composer:
sudo apt install composer
Step 2: Install and Configure MariaDB
MariaDB is the database server that Magento will use to store its data. You can also choose MySQL Server to use with your application.
- Install MariaDB:
sudo apt install mariadb-server
- Secure the MariaDB installation:
sudo mysql_secure_installation
Follow the prompts to set the root password and remove unnecessary options for better security.
Step 3: Create Database and User
We need to create a database and a user for Magento.
- Log in to MariaDB as root:
sudo mysql -u root -p
- Use the following sql statements to create database and user for your Magento2 Application:
-- Create database CREATE DATABASE magento2; -- Create user for magento CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'your_password'; -- Grant all privileges to the new user: GRANT ALL ON magento.* TO 'magentouser'@'localhost' IDENTIFIED BY 'your_password' WITH GRANT OPTION; --Flush privileges and exit: FLUSH PRIVILEGES; EXIT;
Step 4: Install Elasticsearch
Elasticsearch is required for Magento’s search functionality.
- Install Java (Elasticsearch needs Java to run):
sudo apt install openjdk-11-jdk
- Add Elasticsearch GPG key and repository:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'
- Install Elasticsearch:
sudo apt update
sudo apt install elasticsearch
- Start and enable Elasticsearch:
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
Step 5: Download and Configure Magento
You can either downloads the Magento2 source code from official GitHub releases page. Another option is to to compose command line utility to setup it.
- Change to the web root directory:
cd /var/www/html
- Download Magento using Composer:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
- Change ownership of the Magento directory:
sudo chown -R www-data:www-data /var/www/html/magento2
sudo chmod -R 755 /var/www/html/magento2
- Change to the Magento directory:
cd /var/www/html/magento2
- Set up Magento:
bin/magento setup:install --base-url=http://your_domain_or_IP \ --db-host=localhost \ --db-name=magento \ --db-user=magentouser \ --db-password=your_password \ --admin-firstname=Admin \ --admin-lastname=User \ [email protected] \ --admin-user=admin \ --admin-password=admin_password123 \ --language=en_US \ --currency=USD \ --timezone=America/Chicago \ --use-rewrites=1
Step 6: Setup Apache Virtual Host
We need to create an Apache virtual host configuration for Magento.
- Create a new virtual host file:
sudo nano /etc/apache2/sites-available/magento2.conf
- Add the following configuration to the file:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/magento2 ServerName your_domain_or_IP <Directory /var/www/html/magento2> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/magento2_error.log CustomLog ${APACHE_LOG_DIR}/magento2_access.log combined <Directory /var/www/html/magento2/bin/> AllowOverride All Options Indexes FollowSymLinks Require all granted </Directory> <Directory /var/www/html/magento2/pub/> AllowOverride All Options Indexes FollowSymLinks Require all granted </Directory> <Directory /var/www/html/magento2/var/> AllowOverride All Options Indexes FollowSymLinks Require all granted </Directory> <Directory /var/www/html/magento2/app/> AllowOverride All Options Indexes FollowSymLinks Require all granted </Directory> <Directory /var/www/html/magento2/setup/> AllowOverride All Options Indexes FollowSymLinks Require all granted </Directory> </VirtualHost>
- Enable the new virtual host:
sudo a2ensite magento2.conf
- Disable the default site:
sudo a2dissite 000-default.conf
- Enable the Apache rewrite module:
sudo a2enmod rewrite
- Restart Apache:
sudo systemctl restart apache2
Step 7: Testing
Now, you should be able to access your Magento store in your web browser.
- Open your web browser.
- Navigate to http://your_domain_or_IP.
If everything is set up correctly, you will see the Magento storefront.
Conclusion
Congratulations! You have successfully installed Magento 2 on your Ubuntu server. With Magento up and running, you now have a powerful platform to build and manage your online store. From adding products to configuring payment gateways and customizing your store’s appearance, Magento provides a vast array of tools to help you create a unique shopping experience for your customers.
Remember, setting up Magento is just the beginning. To make the most of this powerful e-commerce platform, you’ll want to explore its many features and extensions. Whether you need advanced marketing tools, detailed analytics, or enhanced security options, the Magento marketplace offers a wide range of add-ons to expand your store’s capabilities.
Thank you for following this tutorial. We hope it was helpful and easy to understand. Hope the online store helped you to reach your business at next level.