How To Install Magento 2.4.7 with Apache, & OpenSearch on Ubuntu 24.04
#Magento 2 #Apache Server #OpenSearch #Ubuntu 24.04 #Magento Setup Guide #eCommerce Development

Complete Guide: Install Magento 2.4.7 with OpenSearch on Ubuntu 24.04

Installing Magento 2.4.7 with performance optimization tools like OpenSearch (search engine replacement for Elasticsearch) ensures your e‑commerce store runs fast, secure, and scalable. This guide walks you through the complete installation from scratch on Ubuntu 24.04 LTS, suitable for production or staging environments.

1. System Requirements

Server Requirements

  • OS: Ubuntu 24.04 LTS Ubuntu 24.04 LTS (64-bit)
  • RAM:Minimum 4 GB (8 GB recommended)
  • Disk Space:Minimum 50 GB (SSD recommended)

Software Requirements

  • Web Server: Apache
  • Database: MySQL 8.0
  • PHP: 8.2 with required extensions
  • Composer: Composer 2.0+
  • OpenSearch: OpenSearch 2x

2. Initial Server Setup

Update system packages:

sudo apt update && sudo apt upgrade -y

Install required utilities:

sudo apt install curl wget unzip gnupg2 ca-certificates lsb-release software-properties-common -y

3. Install Apache Web Server

Install Apache:

sudo apt install apache2 -y

Enable Apache to start on boot:

sudo systemctl enable apache2

Enable required Apache modules:

sudo a2enmod rewrite headers proxy proxy_http ssl expires

Restart Apache to apply changes:

sudo systemctl restart apache2

Verify Apache is running:

sudo systemctl status apache2

5. Install MySQL Database Server

Add PHP repository:

sudo add-apt-repository ppa:ondrej/php -y
sudo apt update

Install PHP and required extensions:

sudo apt install php8.2 php8.2-fpm php8.2-cli php8.2-common php8.2-mysql \
php8.2-xml php8.2-curl php8.2-bcmath php8.2-intl php8.2-mbstring \
php8.2-soap php8.2-zip php8.2-gd php8.2-opcache -y

Adjust PHP settings:

sudo nano /etc/php/8.2/fpm/php.ini

Recommended values:

memory_limit = 2G
max_execution_time = 1800
zlib.output_compression = On

Restart PHP-FPM service:

sudo systemctl restart php8.2-fpm

Install MySQL:

sudo apt install mysql-server -y

Secure MySQL installation:

sudo mysql_secure_installation

Create a database and user for Magento:

sudo mysql -u root -p
CREATE DATABASE magento;
CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON magento.* TO 'magento_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

6. Install Composer

    curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer --version

7. Install OpenSearch (Magento Search Engine)

Add OpenSearch GPG key and repository:

    curl -fsSL https://artifacts.opensearch.org/publickeys/opensearch.pgp | sudo gpg --dearmor -o /usr/share/keyrings/opensearch-keyring.gpg


echo "deb [signed-by=/usr/share/keyrings/opensearch-keyring.gpg] https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main" | sudo tee /etc/apt/sources.list.d/opensearch.list


sudo apt update
sudo apt install opensearch -y

Configure OpenSearch:

sudo nano /etc/opensearch/opensearch.yml

Add the following lines:

cluster.name: opensearch-cluster
node.name: node-1
network.host:127.0.0.1
http.port: 9200
discovery.type: single-node

Start and enable OpenSearch:

sudo systemctl start opensearch
sudo systemctl enable opensearch

Verify OpenSearch is running:

curl -X GET "localhost:9200"

8. Download and Install Magento 2.4.7

Navigate to the web root directory:

cd /var/www/html

Download Magento using Composer:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.7 magento2

Set proper permissions:

sudo chown -R www-data:www-data /var/www/html/magento2
sudo find /var/www/html/magento2 -type d -exec chmod 755 {} \;
sudo find /var/www/html/magento2 -type f -exec chmod 644 {} \;

Install Magento via CLI:

php bin/magento setup:install \
--base-url=http://yourdomain.com \
--db-host=localhost \
--db-name=magento \
--db-user=magentouser \
--db-password=strongpassword \
--admin-firstname=Admin \
--admin-lastname=User \
--admin-email=admin@domain.com \
--admin-user=admin \
--admin-password=Admin@123 \
--language=en_US \
--currency=USD \
--timezone=Asia/Kolkata \
--use-rewrites=1 \
--search-engine=opensearch \
--opensearch-host=localhost \
--opensearch-port=9200

9. Configure Apache for Magento

Create Apache virtual host configuration:

sudo nano /etc/apache2/sites-available/magento.conf

Add the following configuration:

   
   
    
ServerName yourdomain.com
DocumentRoot /var/www/magento2/pub



AllowOverride All
Require all granted



ErrorLog ${APACHE_LOG_DIR}/magento_error.log
CustomLog ${APACHE_LOG_DIR}/magento_access.log combined


Enable the Magento site and rewrite module:

sudo a2ensite magento.conf
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

Access your Magento store at http://yourdomain.com and log in to the admin panel using the credentials provided during installation.

10. Final Steps

  • Enable Magento production mode:
php bin/magento deploy:mode:set production
  • Set up cron jobs for Magento:
php bin/magento cron:install
  • Clear Magento cache:
php bin/magento cache:clean

Your Magento 2.4.7 installation with OpenSearch on Ubuntu 24.04 is now complete! You can further optimize and secure your installation based on your specific requirements.

Conclusion

By following this guide, you have successfully installed Magento 2.4.7 with OpenSearch on Ubuntu 24.04. This setup provides a robust foundation for your e-commerce store, ensuring optimal performance and scalability. Regularly update your system and Magento installation to maintain security and performance.

×
MLM PLAN
×
×