Step-by-step guide to install Magento 2.4.5 with PHP 7.4 on Ubuntu 22.04

1. Update and Upgrade Packages:

  • Open a terminal window and run:

    Bash
    sudo apt update && sudo apt upgrade
    

2. Install Apache2:

  • Install the Apache web server:

    Bash
    sudo apt install apache2
    

3. Install PHP 7.4 and Extensions:

  • Add the Ondrej PHP repository:

    Bash
    sudo add-apt-repository ppa:ondrej/php
    sudo apt update
    
  • Install PHP 7.4 and required extensions:

    Bash
    sudo apt install php7.4 php7.4-common php7.4-mysql php7.4-gd php7.4-curl php7.4-intl php7.4-mbstring php7.4-zip php7.4-xml php7.4-soap php7.4-bcmath php7.4-fpm php7.4-opcache
    

4. Configure Apache for PHP 7.4:

  • Disable the default PHP 8.1 module:

    Bash
    sudo a2dismod php8.1
    
  • Enable the PHP 7.4 module:

    Bash
    sudo a2enmod php7.4
    
  • Restart Apache:

    Bash
    sudo systemctl restart apache2
    

5. Install MySQL:

  • Install MySQL server and client:

    Bash
    sudo apt install mysql-server mysql-client
    
  • Secure MySQL installation:

    Bash
    sudo mysql_secure_installation
    

6. Create a Magento Database:

  • Access the MySQL shell:

    Bash
    sudo mysql -u root -p
    
  • Create a database and user:

    SQL
    CREATE DATABASE magento_db;
    CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'your_password';
    GRANT ALL PRIVILEGES ON magento_db.* TO 'magento_user'@'localhost';
    FLUSH PRIVILEGES;
    
  • Exit the MySQL shell:

    SQL
    exit
    

7. Install Elasticsearch:

  • Add the Elasticsearch repository key and repository:

    Bash
    wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
    echo
    "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
    
  • Install Elasticsearch:

    Bash
    sudo apt update
    sudo apt install elasticsearch
    
  • Start and enable Elasticsearch:

    Bash
    sudo systemctl start elasticsearch
    sudo systemctl enable elasticsearch
    

8. Install Composer:

  • Download and install Composer:

    Bash
    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    php -r "if (hash_file('SHA384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3d5936c39e735c55f72dac986e5155545f5485754052f589f555a852f40f66c454a93') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    

Leave a Reply