Install Magento on Ubuntu 20.04

Introduction
This document covers the installation process of Magento 2.4.2 on an EC2 instance of Ubuntu 20.04
Prerequisites
Before beginning the installation process, you must create an account at https://magento.com/
After creating an account, acquire your public and private keys, needed for a later step, by visiting this site. Once on there, click on your name in the top right corner and then click on "My Profile". Once there, click on "Access Keys", located under Marketplace > My Products.
Assuming you don't already have an access key created, simply create one and name it something appropriate. Once created, make note that in a later step, your public key will act as your username and your private key will act as your password.
Installation steps
Create magento
user
sudo adduser magento
sudo usermod -aG sudo magento
- Adds user to the
sudo
group sudo -iu magento
- Logs in as
magento
Install nginx
sudo apt -y install nginx
Install PHP
apt-get -y install php7.4-fpm
- Might possibly need to run
apt-get -y install php7.4-cli
Configure PHP
- Open the
php.ini
files in an editor: vim /etc/php/7.4/fpm/php.ini
vim /etc/php/7.4/cli/php.ini
- Edit both to include the following values:
memory_limit = 2G
max_execution_time = 1800
zlib.output_compression = On
- Uncomment
;extension=curl
- Save the changes you made and restart PHP with
systemctl restart php7.4-fpm
Install MariaDB
sudo apt install mariadb-server
sudo mysql_secure_installation
This will launch the configurator for mariaDB
Enter current password for root (enter for none): Press [Enter] since no password is set by default
Set root password? [Y/n]: Y (Keep this password handy for a later step)
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
Once done:
3. systemctl status mariadb.service
4. systemctl enable mariadb.service
Configure DB
sudo mysql -u root -p
- Enter the
magento
user password when asked - Enter the following commands in the order shown to create a database instance named magento with username magento:
mysql -u magento -p
- Use the root password we set up in the second SQL statement referenced as
Password
use magento;
and ensure the output isDatabase changed
create database magento;
create user 'magento'@'localhost' IDENTIFIED BY 'Password';
GRANT ALL ON magento.* TO 'magento'@'localhost';
flush privileges;
Install Elasticsearch
Starting with version 2.4, Magento requires that Elasticsearch be utilized
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.1-amd64.deb
sudo dpkg -i elasticsearch-7.6.1-amd64.deb
sudo systemctl start elasticsearch
sudo systemctl status elasticsearch
curl -XGET 'http://localhost:9200'
Configure Elasticsearch
sudo vim /etc/elasticsearch/elasticsearch.yml
cluster.name: Magento Cluster
node.name: Magento Node
network.host: localhost
systemctl restart elasticsearch.service
- Re-run
curl -XGET 'http://localhost:9200'
to confirm changes are reflected
Configure Permissions
sudo usermod -g www-data magento
sudo chown -R magento:www-data /var/www/html/
Installing PHP Extensions
At this point, I found that before I could run the composer
command in the next section, I had several php extensions I had to install. Those were:
php-bcmath
php7.4-curl
php-xml
php-7.4-mbstring
php7.4-intl
php7.4-gd
php7.4-mysql
php7.4-soap
Installing Magento
- Installing Magento
sudo apt install zip unzip php-zip
cd /var/www/html
and ensure the directory is empty of any contents. Generally, Nginx have a test file in here that you will need to delete.- Install composer globally:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
composer create-project --repository=<https://repo.magento.com/ magento/project-community-edition .
- When prompted, provide public key as username and private key as password
- https://marketplace.magento.com/customer/accessKeys/
Once finished, you may be presented with some messages highlighted in yellow. These are not necessarily anything to worry about unless they're explicitly warnings or if the highlighting is red instead of yellow.
We now run the composer install command to actually install Magento, itself
composer install
bin/magento setup:install \
--base-url=<http://localhost/magento2ee> \
--db-host=localhost \
--db-name=magento \
--db-user=magento \
--db-password=db_password \
--backend-frontname=admin \
--admin-firstname=Tanner \
--admin-lastname=Cude \
--admin-email=email \
--admin-user=magentoadmin \
--admin-password=alphanumberic_password \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1
Note that this step may take several minutes to install.
Stay tuned for an additional post describing how to configure Nginx to work with Magento – allowing users to access your Magento site.