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 declear Apache2 site configuration for Magento 2 store, you have to create a new configuration file magento2.conf
:
sudo vi /etc/apache2/sites-available/magento2.conf
Copy and paste the following content to 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>
Enable Rewrite mod
Make sure you enable rewrite mod to use site friendly URLs:
sudo a2ensite magento2.conf
Then, you can go to the /etc/apache2 directory rewrite the apache2.conf file
sudo a2enmod rewrite
Step 1.3: Install PHP 7.2 and extensionsOn 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-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip
Step 1.4: Update php.ini file
Now time to increase values in 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 everytime 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 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 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