Magento is a popular open source e-commerce platform written in PHP. Magento is highly popular ecommerce platform and it is owned and managed by Adobe Inc. The platform is flexible and has a large variety of features to build an online store. The latest version as of this writing is Magento 2.4.4 and it was released in April 12, 2022.
In this tutorial we will guide you on how to install Magento 2.4.4 community edition with the LAMP stack on Ubuntu 22.04.
Let us proceed with the installation.
Prerequisites
- Ubuntu 22.04
- At least 2 GB of RAM or Higher
Updating the system
sudo apt update -y && apt upgrade -y
Installing PHP and PHP extensions
The default PHP version ships for Ubuntu 22.04 is PHP 8.1. And PHP 8.1 is the required PHP version to run Magento 2.4.4. Now let us install PHP and it’s dependencies.
sudo apt install php libapache2-mod-php php-bcmath php-curl php-fpm php-gd php-intl php-mbstring php-mysql php-soap php-xml php-xsl php-zip php-cli
After the installation Locate your PHP configuration and modify some of the parameters required to run and install Magento.
To locate the PHP configuration file run the following command:
root@techtutorguro:~# php --ini | grep "Loaded Configuration File"
Output:
Loaded Configuration File: /etc/php/8.1/cli/php.ini
Edit the PHP configuration file.
nano /etc/php/8.1/cli/php.ini
Modify the configuration files with the following values.
memory_limit = 1G
upload_max_filesize = 128M
zlib.output_compression = on
max_execution_time = 18000
realpath_cache_size = 10M
realpath_cache_ttl = 7200
Save the configuration file and exit.
Database Installation and configuration
The database version required for Magento 2.4.4 is MySQL 8 or MariaDB 10.4. In this tutorial we will use MySQL as our database.
Let us install MySQL.
sudo apt install mysql-server
Let us configure MySQL server. But before we run the mysql_secure_installation let us first set the MySQL root password.
sudo mysql
Let us set the MySQL root password.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mysecretpassword';
Then exit in the MySQL terminal.
If you don’t set the MySQL root password first before running mysql_secure_installation you will encounter this error:
… Failed! Error: SET PASSWORD has no significance for user ‘root’@’localhost’ as the authentication method used doesn’t store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.
Let us proceed configuring MySQL.
sudo mysql_secure_installation
Output:
Securing the MySQL server deployment.
Enter password for user root:
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.
Estimated strength of the password: 50
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
Restart MySQL service.
sudo systemctl restart mysql
Let us create a database for our Magento instance.
First login to MySQL console.
sudo mysql -u root -p
Then enter the root password you set while configuring MySQL.
Now let us create a database for our Magento instance. In the MySQL console run these commands.
Before we proceed in creating the database let us first change the password policy to “LOW” this is optional if you don’t want to use the strict password policy. To set the password policy to low run this command.
SET GLOBAL validate_password.policy = 0;
Let us create the database for our Magento instance.
create database magento2;
Let us create a database user.
CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'mypassword';
Grant all privileges to the newly created user to magento2 database.
GRANT ALL ON magento2.* TO 'magento_user'@'localhost';
flush privileges;
exit
Please don’t forget to change the “mypassword” to your desired password you can also change the database user “magento_user“ to your desired database user.
Web server Installation and Configuration
Since the stack that we are going to use in this tutorial is LAMP we will install Apache as our web server.
Let us install Apache.
sudo apt install apache2
Start and enable Apache.
sudo systemctl enable apache2 --now
Create a Virtual Host.
nano /etc/apache2/sites-available/magento2.conf
Add the content below.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/magento2/pub
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/">
AllowOverride all
</Directory>
</VirtualHost>
Save and exit.
Please don’t forget the change the domain.com to your own domain.
Let us enable the virtual host we created.
a2ensite magento2.conf
Then enable mod_rewrite module.
a2enmod rewrite
Then restart Apache.
systemctl restart apache2
Installing Elastic Search
Starting Magento 2.4, all installations must be configured to use Elasticsearch.
Let us install Elasticsearch.
sudo apt install apt-transport-https ca-certificates gnupg2
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'
sudo apt update
sudo apt install elasticsearch
sudo systemctl enable elasticsearch --now
Check the status if Elasticsearch is running.
sudo systemctl status elasticsearch
Installing Composer
Composer is a PHP package manager.
Let us install composer.
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Download and Install Magento 2.4.4
For most situation it is recommended to install Magento using the Marketplace(https://marketplace.magento.com/) by creating access key.
Let us create an access key.
- First Login to your Marketplace account
- Go to Name->My Profile
- Go to Marketplace->My Products->Access Keys
- Under Magento 2 tab click “Create A New Access Key“
- On the popup enter any name in textbox then click OK.
- You’re done and you will see the Access Keys generated.
Let us proceed with Magento 2.4.4 Installation.
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.4 /var/www/magento2
After running the command above it will ask you to provide the username and password which is your Access keys.
Username: YOUR_PUBLIC_KEY
Password: YOUR_PRIVATE_KEY
After entering your credentials the installation will ask you if you want to store the credentials in a local file.
Do you want to store credentials for repo.magento.com in /root/.config/composer/auth.json ? [Yn] Y
Go to your Magento root directory.
cd /var/www/magento2/
Then run the Magento 2 installation command.
bin/magento setup:install \
--base-url=http://domain.com \
--db-host=localhost \
--db-name=magento2 \
--db-user=magento_user \
--db-password=mypassword \
--admin-firstname=admin \
--admin-lastname=admin \
[email protected] \
--admin-user=admin \
--admin-password=myadminpassword \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1
Note: Please don’t forget to modify the highlighted values based on your own set of values.
After the installation process you will see the admin link for your Magento 2.4.4 site.
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_re1i89
Nothing to import.
Setup the Cron Jobs
Magento is using cron jobs to automate important operation. Let us setup the cron jobs.
sudo bin/magento cron:install
Before we access our Magento instance we need to fix the permission.
sudo chown -R www-data:www-data /var/www/magento2
You should be able to access your Magento instance.
If you have issue logging in to your Magento Instance you need to disable the Two factor authentication by running the command below:
sudo bin/magento module:disable Magento_TwoFactorAuth
Congratulations you have successfully installed Magento 2.4.4 you can now access your Magento site at http://domain.com
Conclusion
You have learned in this tutorial on how to install Magento 2.4.4 with the LAMP stack. If you are using Ubuntu 20.04 you can check our article on Magento 2.4.3.
If you have questions, feel free to leave a comment and we will try to answer it.
Thank you and hope you enjoy our tutorial ?
Hi, I follow the tutorial, but when I install magento2,
Then run the Magento 2 installation command.
I can’t go to the next step. Nothing happens and no problem is prompted.
You need to make sure that you are inside the Magento directory before running the installation command.