Installing Magento 2 on Ubuntu using a Bash Script

Here is the magento2 bash script’s that you can you to install Magento using LAMP and elasticsearch

#!/bin/bash

# Update the system
sudo apt-get update
sudo apt-get upgrade

# Install LAMP stack
sudo apt-get install -y apache2 mysql-server php php-cli php-common php-curl php-gd php-intl php-mbstring php-mysql php-soap php-xml php-zip

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

# Configure MySQL
sudo mysql_secure_installation

# Download Magento 2
wget https://github.com/magento/magento2/archive/2.4.1.tar.gz

# Extract the downloaded file
tar -zxvf 2.4.1.tar.gz

# Move the extracted files to the web root
sudo mv magento2-2.4.1/ /var/www/html/magento2

# Set the correct permissions
sudo chown -R www-data:www-data /var/www/html/magento2
sudo chmod -R 775 /var/www/html/magento2

# Create a virtual host
sudo nano /etc/apache2/sites-available/magento2.conf
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/magento2
    ServerName example.com
    ServerAlias www.example.com
    <Directory /var/www/html/magento2/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# Enable the virtual host
sudo a2ensite magento2.conf

# Restart Apache
sudo service apache2 restart

# Run the Magento 2 installation command
php bin/magento setup:install --base-url=http://example.com/ --db-host=localhost --db-name=magento2 --db-user=root --db-password=password --admin-firstname=admin --admin-lastname=admin [email protected] --admin-user=admin --admin-password=password --search-engine=elasticsearch7 --elasticsearch-host=127.0.0.1 --elasticsearch-port=9200

# Set file permissions
sudo chmod -R 777 var/ generated/ pub/

This script will install Magento 2 on Ubuntu using a LAMP stack and Elasticsearch. It also assumes that you have already configured your domain name to point to the server. The script will also create a virtual host for Magento 2, and set the necessary permissions for the files and directories. Be sure to replace example.com and admin@

Koushik CH

Koushik CH

KOUSHIK CH is a Young Software Developer, who enjoys challenges, Traveling, eating out, and cookery. He is Accountable and Geek, but can also be very Mobile/Laptop Addicted and a bit Foodie Selfish.
Enable Notifications OK No thanks