How To Install Magento 2.4.7 On Ubuntu
Magento 2.4.7 has been released with hundreds of quality fixes and enhancements, enhancing GraphQL coverage for custom attributes and resolver caches. Please follow the post How To Install Magento 2.4.7 On Ubuntu to install it successfully.
To start the installation, you should prepare yourself a VPS running Ubuntu operating system. In this post, we choose to use VPS provided by Vultr to bring speed and stability to Magento 2 website. If you have not used any VPS service, please click here to sign up for an account and get $100 for free.
1. Notes before installation
These are the changes of Magento 2.4.7 compared to previous versions. We need to know these before installation.
- Compatible PHP 8.3.
- Compatible Elasticsearch 8.11.
- Supports Varnish 7.4.
- Supports Redix 7.2.
- Supports RabbitMQ 3.13.
- Compatible with Composer 2.7.x.
2. Install and Configure Apache
You can refer to the post How To Install Apache On Ubuntu 20.04 to be able to install Apache 2.
3. Install MySQL
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, 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:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 807
Server version: 8.0.23-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

Then, exit MySQL console by command:
exit
You can install phpmyadmin to easily manage the database with this post How To Install PhpMyAdmin On Ubuntu.
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
mysql -u magento2 -p
CREATE DATABASE magento2;
exit
4. Install PHP 8.3
First, install all the necessary dependencies:
sudo apt install curl gpg gnupg2 software-properties-common ca-certificates apt-transport-https lsb-release
Add PHP repository to your system:
sudo add-apt-repository ppa:ondrej/php
Update your APT repositories.
sudo apt update
Install PHP 8.3 with command:
sudo apt install php8.3
And packages:
sudo apt install php8.3-{exif,bz2,intl,soap,cli,pdo,mysql,zip,gd,mbstring,curl,xml,bcmath,common,xmlrpc,gmp}
Next, verify your PHP version:
php -v
You should see output like this:
PHP 8.3.16 (cli) (built: Jan 19 2025 13:45:36) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.16, Copyright (c) Zend Technologies
with Zend OPcache v8.3.16, Copyright (c), by Zend Technologies

Edit the /etc/apache2/mods-enabled/dir.conf file.
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:
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Enable mbstring
extension.
sudo phpenmod mbstring
Enable the Apache rewrite module.
sudo a2enmod rewrite
Reload Apache for the changes to take effect.
sudo systemctl reload apache2
5. Install Elasticsearch
Before installing Elasticsearch, we need install necessary packages.
sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https lsb-core curl wget -y
Install Elasticsearch.
wget -q https://artifacts.elastic.co/GPG-KEY-elasticsearch -O- | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list
sudo apt update
sudo apt-get install elasticsearch=8.11.0
Configure Elasticsearch
To configure Elasticsearch, we will edit its main configuration file elasticsearch.yml
sudo nano /etc/elasticsearch/elasticsearch.yml
Find the line that specifies network.host
and http.port
, uncomment it, and replace its value like this:
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: localhost
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
Run the commands below to secure Elasticsearch
sudo ufw allow from anywhere to any port 9200
sudo ufw enable
sudo ufw status
sudo systemctl status elasticsearch
Start and enable Elasticsearch.
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
Verify Elasticsearch proxy with port 9200 by command:
curl -X GET 'http://localhost:9200'
If the installation is successful you will receive a response similar below:
{
"name" : "ubuntu",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "3UwkdtxPTiaFR5z2iDdq8A",
"version" : {
"number" : "8.11.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "d9ec3fa628c7b0ba3d25692e277ba26814820b20",
"build_date" : "2023-11-04T10:04:57.184859352Z",
"build_snapshot" : false,
"lucene_version" : "9.8.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}

If the response has the error below:
curl: (52) Empty reply from server
Edit its main configuration file elasticsearch.yml
and find the line that specifies xpack.security.enabled
and replace to false
:
# Enable security features
xpack.security.enabled: false
6. Install Composer 2
Move back to the root directory.
cd ~
Downloading and installing composer.
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/bin --filename=composer
You should see output like this:
All settings correct for using Composer
Downloading...
Composer (version 2.8.5) successfully installed to: /usr/bin/composer
Use it: php /usr/bin/composer
If your installation version is greater than Magento’s requirement, use this command to downgrade the version:
sudo composer self-update <--your-version-required-->
Check Composer 2 is installed in Ubuntu?
composer
If installed, you should see output like this:
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.7.9 2024-09-04 14:43:28
Usage:
command [options] [arguments]
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
...

7. Download Magento 2.4.7
Go to html
folder by command:
cd /var/www/html
Create a new Composer project using the Magento Open Source or Magento Commerce metapackage.
Magento Open Source
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <install-directory-name>
For example:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
Download Magento 2 with the specified version.
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=<magento-version> <install-directory-name>
For example:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.7 magento2
Magento Commerce
composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition <install-directory-name>
Download Magento 2 with the specified version.
composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition=<magento-version> <install-directory-name>
Set file permissions
cd /var/www/html/<magento install directory>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R :www-data .
chmod u+x bin/magento
sudo chmod -R 777 var/ pub/static generated/ app/etc pub/media
8. Install Magento 2.4.7
Go to Magento 2 install directory.
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 \
[email protected] \
--admin-user=admin \
--admin-password=<your-admin-password> \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1

Wait until the installation is successful.
9. 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
sudo nano /etc/apache2/sites-available/000-default.conf
Add the path to your Magento pub/
directory to the DocumentRoot
directive:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/magento2/pub
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
Update your base URL
Login with magento2 user.
mysql -u magento2 -p
Specify the Magento database you created when you installed Magento:
use magento2
Update the base URL:
For IP:
UPDATE core_config_data SET value='http://<your-ip>' WHERE path='web/unsecure/base_url';
For Server’s Hostname:
UPDATE core_config_data SET value='http://<your-server-hostname>' WHERE path='web/unsecure/base_url';
Update the env.php file
Go to env.php file.
sudo nano /var/www/html/magento2/app/etc/env.php
The node below needs to be in the file, check it out:
'directories' => [
'document_root_is_pub' => true
]
Switch modes
Go to Magento 2 install directory.
cd /var/www/html/magento2
Switch to production
mode.
php bin/magento deploy:mode:set production
php bin/magento cache:flush
Refresh your browser and verify that the storefront displays properly.
Switch to developer
mode.
php bin/magento deploy:mode:set developer
php bin/magento cache:flush
Refresh your browser and verify that the storefront displays properly.
Verify the storefront
If you see the storefront showing a 500 internal server error, please fix set permissions for the Magento 2 file according to the post: How To Fix Magento 2 500 Internal Server Error.
10. Grant Permission To Folders
chmod -R 777 var
chmod -R 777 pub/static
chmod -R 777 generated
chmod -R 777 generated/
11. See Your Results
Don’t forget to run the following commands:
php bin/magento s:up
php bin/magento s:s:d -f
php bin/magento c:f
If you have problems with the Admin Page: “Failed to send the message. Please contact the administrator”.
You need to disable the Two-Factor Authorization module using the following command:
php bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth Magento_TwoFactorAuth
So we have successfully installed Magento 2.4.7 on Ubuntu. Here are the results:


This is the end of the How To Install Magento 2.4.7 On Ubuntu.
Follow us for the more helpful posts!
We hope this is a useful post for you.
Thank you for reading!
Thank you very much!
This was a smooth installation article which help me to install Magento 2.4 without any issues.
Why are adding a proxy with Apache instead of hiting ElasticSearch on :9200?
–base-url=http://localhost/magento2 can be configured during Instal which would already appear in core_config_data table, however making the change in the 000-default.conf, would it require to revise the configuratuin in the env.php with http://localhost/magento2?
I installed 2.45 on Ubuntu wsl, however received Index of /magento2 after install. Now I am receiving an error 500 after trying to create a domain name on localhost.
Please advise and thanks!
Aran