7 Steps to Install Magento 2 on Ubuntu/Debian [Latest] - Sample Data
Are you looking for a step-by-step guide to Install Magento 2 latest version on Ubuntu/Debian from Magento repo or Github with Apache/NginX, MySQL/MariaDB and PHP7.x? This is best place for you. In this post, I will show you how to install Magento 2.3 on an Ubuntu latest with Apache2, MariaDB. In previous posts, I talked about Install Magento 2 on MAC OS, Centos or Windows.
Before jumping in, please check on Magento 2 Requirements:
You should double check 8 main requirements for Magento 2 here.
Learn more about Magento 2 Module Development
Step 1: Install Apache2 PHP and Required Extensions
Step 1.1 Install Apache2 Server
The Apache HTTP Server, called Apache, it is free and open-source cross-platform web server software. Apache is the most popular HTTP Server now. It runs on Linux, Windows, OpenVMS, NetWare and other operating systems.
To install Apache, you should update packages before running install Apache install command:
sudo apt update
sudo apt install apache2
To run apache automatically during startup, run the following command line:
sudo systemctl enable apache2.service
Step 1.2 Configure Apache2 Virtual Host
To declare Apache2 site configuration for Magento 2 store, you have to create a new configuration file magento2.conf
:
sudo nano /etc/apache2/sites-available/magento2.conf
Copy and paste the following content to the above file. Remember, you should change domain.com
to your domain.
<VirtualHost *:80>
ServerAdmin admin@domain.com
DocumentRoot /var/www/html/magento2/
ServerName domain.com
ServerAlias www.domain.com
<Directory /var/www/html/magento2/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If you are installing Magento locally, you can change domain.com
to localhost.com
, dev.com
or m2.com
. Then you have to update hosts
file at /etc/hosts
with
127.0.0.1 localhost.com
127.0.0.1 dev.com
127.0.0.1 m2.com
IMPORTANT:
In this tutorial, I use localhost.com
.
Enable Rewrite mod
Make sure you enable rewrite mod to use site friendly URLs:
sudo a2ensite magento2.conf
sudo a2enmod rewrite
Step 1.3: Install PHP 7.2 and extensions
On Ubuntu 18.04, you can install PHP 7.2 easily with the following command line:
sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-gmp php7.2-curl php7.2-soap php7.2-bcmath php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-mcrypt php7.2-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip
Step 1.4: Update php.ini file
Now it’s time to increase values in the php.ini file. Open php.ini
file:
sudo nano /etc/php/7.2/apache2/php.ini
Change the following data:
file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 512M
upload_max_filesize = 128M
max_execution_time = 3600
Then save this php.ini
file.
After that, you should restart apache2. Run this command:
sudo systemctl restart apache2.service
Step 2: Install Database Server
Magento prefered MariaDB Database Server to default MySQL Database Server, because of faster and better performance. To install MariaDB Server and Client, run this command line:
sudo apt-get install mariadb-server mariadb-client
Make sure it start and startup every time you reboot server:
sudo systemctl restart mariadb.service
sudo systemctl enable mariadb.service
You’ve just installed MariaDB server, now you have to initially setup this database server.
sudo mysql_secure_installation
It prompte and you choose the following option:
Enter current password for root (enter for none): Enter
Set root password? [Y/n]: Y
New password: Type your password
Re-enter new password: Type your password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
Step 3: Create MySQL User (Required)
From Magento 2.3.x, Magento requires a unique user for Magento installation, it cannot default user: root
.
First of all, you have to login to MariaDB:
sudo mysql -u root -p
Create a new database for Magento 2:
CREATE DATABASE magento2
Then create a new user name call: mageplaza
CREATE USER 'mageplaza'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD';
Grant mageplaza
user to magento2
database:
GRANT ALL ON magento2.* TO 'mageplaza'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD' WITH GRANT OPTION;
Ok, time to flush privileges and exit.
FLUSH PRIVILEGES;
EXIT;
Step 5: Install Composer
Download Composer and install or you can use command line to install Composer
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Check Composer installed or not just type:
composer -v
Ouput:
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.8.5 2019-04-09
Step 6: Download Magento 2 Pack
You can download from one of the folling resources:
- https://magento.com/tech-resources/download
- https://github.com/magento/magento2/releases
- https://www.mageplaza.com/download-magento/
After donwload, you should extract the pack to /var/www/html/
. E.g you have a folder call: magento2
in /var/www/html/
Set permissions: Run this command
sudo chown -R www-data:www-data /var/www/html/magento2/
sudo chmod -R 755 /var/www/html/magento2/
Step 7: Install Magento 2
Access to this address http://localhost.com/magento2
, you will get this Magento Setup Wizard as the following:
Step 7.3: Start Installing
- Click
Start Readiness Check
. If any errors are displayed, you must resolve them before you continue. Click More detail if available to see more information about each check. - Click
Next
Step 7.2 Add a Database
Fill database information then click Next
Step 7.3 Web Configuration
- Enter the following information:
- Your Store Address:
http://localhost.com
- Magento Admin Address: Enter the relative URL by which to access the Magento Admin. e.g: secret, backend
- Your Store Address:
- Then click
Next
Step 7.4. Customize Your Store
- From the Store Default Time Zone list, click the name of your store’s time zone.
- From the Store Default Currency list, click the default currency to use in your store.
- From the Store Default Language list, click the default language to use in your store.
- Expand Advanced Modules Configuration to optionally enable or disable modules before you install the Magento software.
You can choose to install Sample Data or not in this step.
Click Next
Important!: Use Skip dependency check for individual modules with caution. We recommend against it because a typical reason for this error is you manually edited the deployment configuration. Editing the deployment configuration is not recommended because future Magento software updates can undo your changes.
Step 7.5. Create Admin Account
Now enter admin information such as
- New Username
- New E-Mail
- New Password
- Confirm Password
- Then click Next
Step 7.6. Install
After completing all previous steps in the Setup Wizard, click Install Now
.
Installation Success The message Success will be displayed to indicate a successful installation.
Step 7.7: Check the result
Now go to the frontend and backend to see the result
Frontend
Backend
Benefits of using Ubuntu/Debian to install Magento 2
Ubuntu or Devian has some advantages when it comes to installing Magento 2. Here are they:
- Magento itself strongly recommends developers install the platform on Linux-based systems for full capacity and compatibility
- Using Ubuntu or Debian will cost less than macOS or Windows because it’s open-sourced and supported by many free softwares
- Linux-based system “naturally” has the ability to prevent virus attacks properly
- Linux community is quite active to help with your specific problem in your situation
Now, you can start configuring your store using the Ubuntu /Debian system. Magento is a versatile yet powerful platform that enables users to build up and customize special features. Therefore, there are a lot practices that we all need to learn and update. If you have any questions, don’t hesitate to let us know in the comment section down below!
0 comments:
Post a Comment
Thanks