Table of Contents
Introducing Magento 2 is never a simple errand. Since the absolute first delivery, there are numerous issues clients may experience when introducing Magento 2.
With the most recent arrival of Magento 2.4.3, things have gotten more earnestly as Magento 2 currently, requires Elasticsearch as a compulsory part.
To make a Magento 2 establishment work appropriately in the Production climate, clients are prescribed to introduce Magento 2 in localhost first. At that point move the neighborhood establishment to a Magento 2 facilitating and update storeβs Baseurl, and reindex Magento 2.
In this instructional exercise, we will experience the way toward introducing Magento 2 (with Elasticsearch) in Ubuntu.
If you are also want to install Magento2 on Windows. Click Here.
Install Magento 2.4.5 or Magento 2.4.6 on Ubuntu 22.04 [Complete Guide]
Contents-
- Step 1: Install Apache2
- Step 2: Install MySQL and Create Database for Magento2
- Step 3: Install PHP and required extensions
- Step 4: Install and configure Elasticsearch
- Step 5: Install Composer
- Step 6: Download and Install Magento2
- Wrapping up
Before starting the installation, you can check theΒ system requirement for installing Magento2 here.
Step 1: Install Apache2
First, we will install Apache web server. Connect to your server using ssh protocol with root access and run this command:
Apache is available in Ubuntuβs default software repositories. For this reason, weβll start by updating the local package index for the latest changes.
sudo apt update
|
Then, lets install the apache2Β package.
|
The system will ask to continue yes/no. Input βyβ then enter to proceed.
Once installed, you can check the installed Apache version with the following command:
|
Awesome, as you can see Apache 2.4 is compatible with Magento2.4.3 in the system requirement. We can proceed to the next step.
To verify if apache2 was install properly, in your browser, enter your domain or ip address or 127.0.0.1. If the result is apache default page => everything is fine
To enable auto startup for apache, use this command:
|
Step 2: Install MySQL and Create Database for Magento2
Install MySQL using apt command:
sudo apt install mysql-server |
When prompted, typingΒ Y
Β to confirm installation and then pressΒ ENTER
.
When the installation is complete, lets check the mysql version
MySQL 8 is compatible with Magento2.4.3 as mentioned in the system requirement. So lets continue..
When the installation is complete, run the following command to secure your MySQL. This command will remove some insecure default settings and block access to your database system.
sudo mysql_secure_installation |
When prompted, pressΒ Y
Β to setup validate password.
Next, select a level of password validation. Enter your root password. The server will show the password strength for the root password you just entered and the server will ask if you want to continue with that password. If you accept, pressΒ Y
.
For the rest of the questions, pressΒ Y
Β and pressΒ ENTER
Β key at each prompt.
When finished, Test login to MySQL with root user by the command:
sudo mysql |
You should see output like this:
Then, exit MySQL console by command:
1
|
exit |
Configure Password Access for the MySQL Root Account
Login with root user.
sudo mysql |
SELECT user,authentication_string,plugin,host FROM mysql.user; |
Note: Replace βyour_secure_password β with your password. |
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_secure_password'; |
Verify mysql.user table with the command:
SELECT user,authentication_string,plugin,host FROM mysql.user; |
exit |
Create new MySQL user for Magento 2
Login with root user.
mysql -u root -p |
SELECT user,authentication_string,plugin,host FROM mysql.user; |
Note: Replace βyour_secure_password β with your password. |
CREATE USER 'magento2'@'localhost' IDENTIFIED BY 'your_secure_password'; |
ALTER USER 'magento2'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_secure_password'; |
Grant all privileges toΒ magento2
Β users.
GRANT ALL PRIVILEGES ON *.* TO 'magento2'@'localhost' WITH GRANT OPTION; |
SELECT user,authentication_string,plugin,host FROM mysql.user; |
exit |
Create Magento 2 database
1
|
mysql -u magento2 -p |
1
|
CREATE DATABASE magento2; |
1
|
exit |
Step 3: Install PHP and required extensions
In this step, we will install PHP.Β Magento 2.4Β require PHP 7.4, so we will install php 7.4 in this tutorial.
Update your APT repositories.
sudo apt update |
Install PHP 7.4 and packages with command:
sudo apt install php7.4 libapache2-mod-php php-mysql |
Next, verify your PHP version:
php -v |
Edit the /etc/apache2/mods-enabled/dir.conf file.
1
|
sudo nano /etc/apache2/mods-enabled/dir.conf |
Modify the index.php file order to the top listed in the DirectoryIndex.
The dir.conf file after modifying will look like this:
Install and enableΒ mbstring
Β extension.
1
|
sudo apt install php7.4-mbstring |
1
|
sudo phpenmod mbstring |
Enable the Apache rewrite module.
1
|
sudo a2enmod rewrite |
Install PHP modules for Magento 2.4.x.
1
|
sudo apt install php7.4-bcmath php7.4-intl php7.4-soap php7.4-zip php7.4-gd php7.4-json php7.4-curl php7.4-cli php7.4-xml php7.4-xmlrpc php7.4-gmp php7.4-common |
Reload Apache for the changes to take effect.
1
|
sudo systemctl reload apache2 |
Configure php settings
php -i | grep "Configuration File"
From this command, you will get path to the php.ini file. Open this file to modify some settings:
sudo nano <path_of_php.ini_file>
In php.ini file, search and change the following values as below
max_execution_time=18000 max_input_time=1800 memory_limit=4G
Save the file. Reload Apache2.
sudo systemctl reload apache2 |
These values will keep the installation go properly without interruption.
Step 4: Install and configure Elasticsearch
From Magento 2.4, Elasticsearch has become compulsory component. From Magento 2.4, catalog search will no longer use mysql, instead the system will use Elasticsearch by default.
So let’s install and configure it.
Install Elasticsearch
First, we will install Openjdk17 (Java) as Elasticsearch runs on Java:
1
|
sudo apt install openjdk-17-jdk |
Next, verify if the java was installed properly and check its version with this syntax
1
|
java -version |
The first step is toΒ import the GPG keyΒ for Elasticsearch packages using the following command:
sudo apt install curl |
sudo curl -sSfL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --no-default-keyring --keyring=gnupg-ring:/etc/apt/trusted.gpg.d/magento.gpg --import
Then you need toΒ add Elasticsearch repositoryΒ to the system using the following command:
sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'
sudo chmod 666 /etc/apt/trusted.gpg.d/magento.gpg
After completing the above steps, you must firstΒ update the cacheΒ using the following commands. ThenΒ install Elasticsearch packagesΒ on the system:
sudo apt update
sudo apt install elasticsearch
Finally, you can use the following commandsΒ StartΒ andΒ enableΒ the Elasticsearch service:
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
Configure Elasticsearch
Once the elasticsearch has been installed on your system, open the elasticsearch.yml configuration file.
Now that you have installed Elasticsearch and its Java dependency, it is time to configure Elasticsearch.
The Elasticsearch configuration files are in theΒ /etc/elasticsearch
directory. The ones weβll review and edit are:
elasticsearch.yml
Β β Configures the Elasticsearch server settings. This is where most options are stored, which is why we are mostly interested in this file.jvm.options
β Provides configuration for the JVM such as memory settings.
The first variables to customize on any Elasticsearch server are node.name
Β andΒ cluster.name
Β inΒ elasticsearch.yml
. Letβs do that now.
As their names suggest,Β node.name
Β specifies the name of the server (node) and the cluster to which the latter is associated. If you donβt customize these variables, aΒ node.name
Β will be assigned automatically in respect to the server hostname. TheΒ cluster.name
Β will be automatically set to the name of the default cluster.
TheΒ cluster.name
Β value is used by the auto-discovery feature of Elasticsearch to automatically discover and associate Elasticsearch nodes to a cluster. Thus, if you donβt change the default value, you might have unwanted nodes, found on the same network, in your cluster.
Letβs start editing the mainΒ elasticsearch.yml
configuration file. Open it usingΒ nano
Β or your preferred text editor:
sudo nano /etc/elasticsearch/elasticsearch.yml
Remove theΒ #
Β character at the beginning of the lines forΒ node.name
Β andΒ cluster.name
Β to uncomment them, and then change their values. Your first configuration changes in theΒ /etc/elasticsearch/elasticsearch.yml
Β file will look like this:
...
Now we have finished installing Elasticsearch.
Now let’s install next component – Composer.
Step 5: Install Composer
In this tutorial, we will install Magento 2.4 using composer. First, run this command to download composer installer.
Move back to the root directory.
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/bin --filename=composer
Let’s check the composer version.
composer
Our composer version is 2.1.6.Β Now we are ready toΒ download Magento 2.4Β using composer.
Step 6: Download and Install Magento2
Download Magento2:-
Go toΒ html
Β folder by command:
1
|
cd /var/www/html |
Create a new Composer project using the Magento Open Source or Magento Commerce metapackage.
Download Magento 2 with the specified version. we will use Magento Open Source and Magento version 2.4.3. So our command will be
sudo composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.3 magento2
Create an account on Magento marketplace and go toΒ https://marketplace.magento.com/customer/accessKeys/ to get private and public access key,
Create Access keys here. If you have access keys, you can use those.
Now enterΒ UsernameΒ
Β andΒ password
Β to start downloading
- Username: Your public KeyΒ 2fc966a913d4e83b28041eeb3c3b72e5
- Password: Your private key. 48e05400d17ca1bcb4e693825c45416e
You will see this screen if everything is fine. Now just wait some minutes, composer is download Magento 2 to your server
Wait the process to complete.
Set file permissions
cd /var/www/html/<magento install directory>
sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + sudo chown -R user_name:www-data . sudo chmod u+x bin/magento
sudo chown -R user_name:www-data .
Β => user_name is the user with root accessInstall Magento 2
Everything is ready, now we will run the final command to install Magento 2.4
First, change the current directory to your website folderΒ (this is also where you downloaded Magento 2 data in step 3)
Go to Magento 2 install directory.
1
|
cd /var/www/html/<magento install directory> |
You must use the command line to install Magento.
php bin/magento setup:installΒ
--base-url=<your-domain>Β
--db-host=localhostΒ
--db-name=magento2Β
--db-user=magento2Β
--db-password=<your-db-password-of-magento2-user>Β
--admin-firstname=AdminΒ
--admin-lastname=AdminΒ
--admin-email=admin@admin.comΒ
--admin-user=adminΒ
--admin-password=<your-admin-password>Β
--language=en_USΒ
--currency=USDΒ
--timezone=America/ChicagoΒ
--backend-frontname=adminΒ
--search-engine=elasticsearch7Β
--elasticsearch-host=localhostΒ
--elasticsearch-port=9200
Replace the following information with your information
--base-url
: your domain, eg: sonal.magento.com
. You can change this base URL later if you make mistake.
--db-host
Β : Database host, inputΒ localhost
Β if you follow my tutorial
--db-name
Β : name of the database we created in step 2
--db-user
Β : name of the database user we created in step 2
--db-password
Β : password of your mysql user
Now composer will start installing Magento 2.4. The process will take a while (approximately 20 minutes)
Wait until the installation is successful.
When everything is done you will see this
Congratulation, Magento 2.4 was successfully installed to your ubuntu server.
Change DocumentRoot To Pub
You can read detailed documentation from MagentoΒ here.
If you append a directory name to your serverβs hostname or IP address to create the base URL when you installed Magento (for example http://<your-ip>/magento2 or http://<your-sever-hostname>/magento2), youβll need to remove it.
Edit your virtual host file
1
|
sudo nano /etc/apache2/sites-available/000-default.conf |
Add the path to your MagentoΒ pub/
Β directory to theΒ DocumentRoot
Β directive:
1
2
3
4
5
6
7
8
9
10
11
12
|
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/magento2/pub Β Β Β Β Β ServerName Β sonal.magento.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory "/var/www/html"> AllowOverride all </Directory> </VirtualHost> |
Restart Apache for the changes to take effect:
sudo systemctl restart apache2
sudo nano /etc/hosts
127.0.0.1 sonal.magento.com
php bin/magento indexer:reindex && php bin/magento se:up && php bin/magento se:s:d -f && php bin/magento c:f && php bin/magento module:disable Magento_TwoFactorAuth
Hit the URL http://sonal.magento.com in the browser. This is Magento 2 Home page
Admin Login
Your Admin Url βΒ http://sonal.magento.com/admin/Β
Step 7: Install sample data for Magento 2
Now we will deploy sample data for our new Magento 2 website on localhost. Sample data will fill your website with some products, categories and images so your website will look like this:
To install the sample data, run the below command
php bin/magento sampledata:deploy && php bin/magento indexer:reindex && php bin/magento se:up && php bin/magento se:s:d -f && php bin/magento c:f
Well done! refresh your website and enjoy your new Magento 2.4 installation with sample data
You can watch complete video for this installation of Magento2 on Ubuntu.
Powered by Embed YouTube Video
Wrapping up
I have tried my best to give you the step-by-step tutorial so that it will be helpful for users who are having trouble installing Magento 2.4. If you face any problems during installation process, please drop a comment below (better with image describing your problem). I will be happy to help!
Thank you so much for a guide on setup magento2.
I have performed the all steps but I didn’t get the Magento 2 Home Page
Follow this https://www.thecoachsmb.com/site-is-not-accessible/
“The account sign-in was incorrect or your account is disabled temporarily. Please wait and try again later”.
I’m getting the above error when trying to access the admin URL.
Hello Suraj.
Follow this https://www.thecoachsmb.com/solved-admin-login-error/
Thanks,
I have installed the Magento 2 on ubuntu server. Do I have to install the XAMPP on windows machine to run the website?
no
Hello Maam,
previously i installed magento 2.4.3 on my windows by your tutorial it works fine , but now i just installed 2.4.5 on ubuntu live server , and add virtual host as you say , when i browse it show “We canβt connect to the server at desenfundanew.magento.com”
can you please guide me ?
Hello smruti,
Have you mentioned desenfundanew.magento.com url in the etc/hosts file? If not, please update.
Also make changes in virtual host file for documentRoot and serverName.
Thanks,
Hello mam, you are doing such a great job! I have successfully installed magneto 2 with the help of composer and also all of its dependencies but when I curl it in my browser it says permission denied
below is the success message of my work.
———————————————————————————————————-
For security, remove write permissions from these directories: ‘/home/abdulqadir/magento/magento2/app/etc’
[Progress: 1384 / 1385]
Write installation date…
[Progress: 1385 / 1385]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin
Nothing to import.
————————–
Composer version 2.4.0 2022-08-16 16:10:48
————————————
virtual host file:
VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/abdulqadir/magento/magento2/pub
ServerName abdul.magento.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
AllowOverride all
I am waiting for your reply thankyou
when I curl it in my browser means?
Hello Maam ,
Previously i installed 2.4.3 on my local server windows it run fine but now when i installed magento2.4.5 on ubuntu live server and add in virtual host as you say , and also change in core_config_data table for web/unsecure/base_url value as per vertual host server name , but in browser it show . ” We canβt connect to the server at desenfundanew.magento.com. why ?
Cross Check here – https://www.thecoachsmb.com/install-magento-2-4-5-on-ubuntu-22-04-complete-guide/.
Sonal, your tutorials are absolutely detailed and we learn so much from you. I have an issue – magento2.4.4 setup on ubuntu 22.04 was successful. I am able to reach frontend and backend however when attempting to upload files magento2 crashes. please advise
Thanks Deresh Pillay. Can you please elaborate more on which files are you uploading? Module files ?
mam after login into my magento2 url looks like this
http://myname.magento.com/admin/banner/index/index/key/9f6dae516bab0e4467bd79bd0318eff414cbfa336f934b9ae34d576018895cf6/
Here I I have added banner but my url is coming all other things index/index/key/9f6dae516bab0e4467bd79bd0318eff414cbfa336f934b9ae34d576018895cf6/
because of this my ajax is not loading.
Please help me this url problem mam I need url untill banner only
Thanks for the Tutorial ………….. Great Work !!
Can we have Tutorial on NGINX setup Also ?
thanks ! sure
After I install.. the css and js files were not loading as it’s say not found ( 404) but when I search path in magento folder it’s their… but in browser it’s not loading… can u please help me here ??
Run the command,
php bin/magento setup:static-content:deploy -f
mam when i run this command he gave this error Error happened during deploy process: The path “/var/www/html/magento2/pub/static/deployed_version.txt” is not writable.
give permission to ub/static directory
Hello Sonal mam
I follow all step. installation done. but front not show.
root@jainam-Inspiron-3542:/var/www/html/magento2# tail /var/log/apache2/error.log
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message
[Sat Jan 29 10:12:57.493273 2022] [mpm_prefork:notice] [pid 14307] AH00163: Apache/2.4.41 (Ubuntu) configured — resuming normal operations
[Sat Jan 29 10:12:57.493293 2022] [core:notice] [pid 14307] AH00094: Command line: ‘/usr/sbin/apache2’
[Sat Jan 29 10:16:59.239282 2022] [mpm_prefork:notice] [pid 14307] AH00171: Graceful restart requested, doing restart
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message
[Sat Jan 29 10:16:59.301782 2022] [mpm_prefork:notice] [pid 14307] AH00163: Apache/2.4.41 (Ubuntu) configured — resuming normal operations
[Sat Jan 29 10:16:59.301804 2022] [core:notice] [pid 14307] AH00094: Command line: ‘/usr/sbin/apache2’
[Sat Jan 29 11:34:39.933857 2022] [mpm_prefork:notice] [pid 14307] AH00169: caught SIGTERM, shutting down
[Sat Jan 29 11:34:40.090825 2022] [mpm_prefork:notice] [pid 23196] AH00163: Apache/2.4.41 (Ubuntu) configured — resuming normal operations
[Sat Jan 29 11:34:40.090927 2022] [core:notice] [pid 23196] AH00094: Command line: ‘/usr/sbin/apache2’
root@jainam-Inspiron-3542:/var/www/html/magento2#
Follow this link – https://www.thecoachsmb.com/solved-forbidden-you-dont-have-permission-to-access-this-resource/
Thanks mam you make it so simple, its a great tutorial
Thanks Geza.
mam Please make a video on live server installation too .
I did all steps but my website is showing the list of files instead or running magento website
Sure. For now I can help you.
Superb, tutorial
This is a great tutorial which worked for me. Thanks for your live support.