Technology

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 admin@example.com
    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 --admin-email=admin@example.com --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 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.

Recent Posts

Expert guide on boosting employee health and safety when their ‘workplace’ is the road

The boom in ridesharing, food delivery and parcel delivery services has seen more cars on the road for work purposes.… Read More

3 years ago

Southeast Asia beckons – dairy exports into ASEAN-6 nations set to boom over the next decade

Demand for dairy in Southeast Asia is set to surge over the coming decade, creating future opportunities for key dairy-exporting… Read More

4 years ago

Sony PlayStation5 prices in India announced: All details

Sony has announced that it will be bringing the new PlayStation5 in India soon. While the company hasn’t provided the… Read More

4 years ago

Microsoft’s attempt to hobble Trickbot botnet wasn’t successful, Intel 471 says

But the U.S.-based threat intelligence company Intel 471 found that Trickbot continues to operate four days after Microsoft’s seizure of… Read More

4 years ago

Twitter changes hacking policy after blocking New York Post story on Hunter Biden

Twitter declined to comment about the most recent change on the record. Late Thursday night, Twitter executive Vijaya Gadde tweeted… Read More

4 years ago

FCC changes its stance on Section 230 policy after months of Trump tweets

The FCC is an independent agency, and historically, it has sought to emphasize its separation from the White House. But… Read More

4 years ago

This website uses cookies.