If you haven’t got a Magento website yet, you will have to install a copy of Magento Community Edition open source e-commerce web application before using MGS Front-end Builder Theme.
If you already had a Magento application installed, you can skip this section
To install Magento version 2.4, please follow these steps:
STEP 1: Download Magento on Ubuntu Server
Install PHP 8.1:
sudo apt install php8.1-fpm
Install Composer, which is a PHP dependency manager.
sudo apt install -y composer
Create web root directory for Magento.
sudo mkdir -p /var/www/magento/
Create the .config
directory for the www-data
user.
sudo mkdir -p /var/www/.config/
Make sure the www-data
user can write to this directory.
sudo chown www-data:www-data /var/www/ -R
Install the necessary PHP extensions.
sudo apt install -y php-imagick php8.1-fpm php8.1-mbstring php8.1-soap php8.1-bcmath php8.1-xml php8.1-mysql php8.1-common php8.1-gd php8.1-cli php8.1-curl php8.1-zip php8.1-intl
Change to the /var/www/
directory.
cd /var/www/
Create the Magento project.
sudo -u www-data composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento
The repo.magento.com
URL requires user authentication. Go to https://marketplace.magento.com/ to create an account, then go to this URL (https://marketplace.magento.com/customer/accessKeys/) to create an access key for Magento 2. Use the Public key as your username and the Private key as your password.
Next, run the following commands to set file permissions.
cd /var/www/magento/
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 :www-data .
sudo chmod u+x bin/magento
STEP 2: Install MySQL Database Server
Magento currently supports: MySQL-8
, MySQL-5.7
, MariaDB-10.4
. MariaDB 10.5 or higher is not supported. Ubuntu 22.04 repository includes MariaDB 10.6, so we will choose MySQL instead of MariaDB.
Run the following command to install MySQL 8.0 from the default Ubuntu repository.
sudo apt install mysql-server-8.0
Once it’s installed, MySQL server will be automatically started, as can be seen with:
sudo systemctl status mysql
If it’s not running, you can start with:
sudo systemctl enable --now mysql
STEP 3: Create a Database and User for Magento Site
Log into MySQL console as root with the following command.
sudo mysql -u root
Once you are logged in, create a database for Magento using the following command. I named it magento
, but you can use whatever name you like such as your site name. (Don’t leave out the semicolon.)
CREATE DATABASE magento;
Then enter the command below to create a database user for Magento. Replace magento_password
with your preferred password.
CREATE USER 'magento'@'localhost' IDENTIFIED BY 'magento_password';
Next, grant permissions to this user.
GRANT ALL PRIVILEGES ON magento.* to 'magento'@'localhost';
Flush the privileges table for the changes to take effect and then get out of MySQL console.
FLUSH PRIVILEGES;
EXIT
Step 4: Set Up Nginx Virtual Host
Make sure you are in the /var/www/magento/
directory.
cd /var/www/magento/
Run the following command to install Magento.
sudo -u www-data bin/magento setup:install --base-url=http://example.com --use-secure=1 --base-url-secure=https://example.com --use-secure-admin=1 --db-host=localhost --db-name=magento --db-user=magento --db-password=magento_password --admin-firstname=super --admin-lastname=admin [email protected] --admin-user=admin --admin-password=admin_password --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --elasticsearch-host=http://127.0.0.1 --elasticsearch-port=9200 --elasticsearch-enable-auth=0
Replace:
example.com
with your real domain name.magento_password
with the password created in step 5.[email protected]
with your preferred admin email address.admin_password
with your preferred admin password.
The installation process is pretty fast. As you can see, Magento is installed successfully.
If you encounter the following error in the installation process, it’s because ElasticSearch isn’t running or you configured it wrong.
Could not validate a connection to Elasticsearch. No alive nodes found in your cluster
Now create Magento Cron jobs.
sudo -u www-data php8.1 bin/magento cron:install
This will add the cron job in the www-data user’s crontab file. You can check it with:
sudo -u www-data crontab -l
Output:
#~ MAGENTO START d1957f62aa710cc367525c9ec68dd7456d4311756b5aa37d2143c4a98b25318c
* * * * * /usr/bin/php8.1 /var/www/magento/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/magento/var/log/magento.cron.log
#~ MAGENTO END d1957f62aa710cc367525c9ec68dd7456d4311756b5aa37d2143c4a98b25318c
The Magento installer gives us the admin URI. Each Magento may have a unique admin URI, so you need to remember or bookmark it in your web browser. Next, we need to set up Nginx web server in order to access the admin panel.
STEP 4: Set Up Nginx Virtual Host
Install Nginx web server.
sudo apt install nginx
Remove the default virtual host.
sudo rm /etc/nginx/sites-enabled/default
Magento ships with a sample Nginx config file in /var/www/magento/
directory. Move it to the /etc/nginx/conf.d/
directory.
sudo mv /var/www/magento/nginx.conf.sample /etc/nginx/conf.d/magento.sample
We create a new virtual host file for Magento in the /etc/nginx/conf.d/
directory. The file name must end with .conf
.
sudo nano /etc/nginx/conf.d/magento.conf
Put the following texts into the file. Replace the red texts with your own domain name. Don’t forget to create DNS A records for your domain name in your DNS zone editor.
upstream fastcgi_backend {
server unix:/var/run/php/php8.1-fpm.sock;
}
server {
listen 80;
listen [::]:80;
server_name www.example.com example.com;
set $MAGE_ROOT /var/www/magento/;
include /etc/nginx/conf.d/magento.sample;
client_max_body_size 2M;
access_log /var/log/nginx/magento.access;
error_log /var/log/nginx/magento.error;
}
Save and close the file. Then test Nginx configurations.
sudo nginx -t
If the test is successful, reload Nginx.
sudo systemctl reload nginx
Enter your domain name in the browser address bar and the default Magento page will show up.
example.com
To install other services, continue reading the following document Document setup SMTP,HTTPS
Tip: How to disable Two factor Authentication module in Magento:
run below command in terminal Magento root path :
bin/magento module:disable Magento_TwoFactorAuth
bin/magento cache:flush