Apache - Setup Magento2

This is to install Magento2 on a RedHat 9 RHEL server 

 Follow these instructions HERE but do not go past the MariaDB installation section of the document. 

 Once installed then continue with the following: 

 # Install MySQL

sudo dnf install -y mariadb-server mariadb

# Install PHP 8.3 via Remi with Magento-required extensions

sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm

sudo dnf module reset php -y

sudo dnf module enable php:remi-8.2 -y

# Core stack + almost all required extensions

sudo dnf install -y \

 httpd mod_ssl php php-cli php-pear php-devel php-gmp php-imagick php-redis php-memcached php-mysqli \

 php php-fpm php-mysqlnd php-opcache php-gd php-intl php-mbstring php-bcmath php-json php-iconv php-soap php-curl \

 php-zip php-xml php-sodium php-dom php-simplexml php-xmlwriter php-xsl php-sockets php-ctype php-fileinfo php-filter \ 

 php-hash php openssl php-pcre php-pdo php-spl php-tokenizer php-zlib php-exif php-gettext php-bz2 php-calendar php-libxml

# Install Elasticsearch (required by Magento 2.4+)

sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

sudo tee /etc/yum.repos.d/elasticsearch.repo << 'REPO'

[elasticsearch]

name=Elasticsearch repository

baseurl=https://artifacts.elastic.co/packages/7.x/yum

gpgcheck=1

gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch

enabled=1

REPO

sudo dnf install -y elasticsearch

# Configure MySQL

sudo systemctl enable --now mariadb

sudo mysql 'SQL'

CREATE DATABASE magento CHARACTER SET utf8mb4;

CREATE USER 'magento'@'localhost' IDENTIFIED BY 'MagentoPass456!';

CREATE USER 'magento'@'%' IDENTIFIED BY 'MagentoPass456!';

GRANT ALL PRIVILEGES ON magento.* TO 'magento'@'localhost';

GRANT ALL PRIVILEGES ON magento.* TO 'magento'@'%';

FLUSH PRIVILEGES;

SQL

# Configure Elasticsearch

sudo systemctl enable --now elasticsearch

# Verify Elasticsearch is running

curl -s http://localhost:9200

# Tune PHP for Magento

sudo tee /etc/php.d/99-magento.ini << 'PHP'

memory_limit = 4G

max_execution_time = 180

max_input_time = 180

post_max_size = 128M

upload_max_filesize = 128M

date.timezone = America/New_York

opcache.enable=1

opcache.memory_consumption=512

opcache.interned_strings_buffer=24

opcache.max_accelerated_files=20000

opcache.revalidate_freq=0

PHP

# Install Composer if not already present

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

# Create the Magento project

# You will need Magento authentication keys from marketplace.magento.com

cd /var/www/html

sudo composer create-project --repository-url=https://repo.magento.com/ \

 magento/project-community-edition magento2

# Set file permissions

sudo chown -R apache:apache /var/www/html/magento2

find /var/www/html/magento2 -type d -exec chmod 755 {} \;

find /var/www/html/magento2 -type f -exec chmod 644 {} \;

sudo chmod -R 775 /var/www/html/magento2/{var,generated,pub/static,pub/media,app/etc}

sudo chmod 755 /var/www/html/magento

# Install Magento 2

cd /var/www/html/magento2

bin/magento setup:install \

 --base-url=http://www.houseestatesales.com/ \

 --db-host=localhost \

 --db-name=magento \

 --db-user=magento \

 --db-password='MagentoPass456!' \

 --admin-firstname=Admin \

 --admin-lastname=User \

 --admin-email=steve.ling@sflservicesllc.com \

 --admin-user=admin \

 --admin-password='Admin456!' \

 --language=en_US \

 --currency=USD \

 --timezone=America/New_York \

 --use-rewrites=1 \

 --search-engine=elasticsearch8

# After install → set production mode & compile

bin/magento deploy:mode:set production

bin/magento setup:di:compile

bin/magento setup:static-content:deploy -f

bin/magento cache:clean

# Configure Apache Site

sudo tee /etc/httpd/conf.d/magento.conf << 'APACHE'

<VirtualHost *:80>

 ServerName www.houseestatesales.com

 ServerAlias houseestatesales.com

 DocumentRoot /var/www/html/magento2

 <Directory "/var/www/html/magento2">

 Options -Indexes +FollowSymLinks

 AllowOverride All

 Require all granted

 </Directory>

 # Magento performance recommendations

 <IfModule mod_expires.c>

 ExpiresActive On

 ExpiresDefault "access plus 1 year"

 </IfModule>

 ErrorLog /var/log/httpd/magento_error.log

 CustomLog /var/log/httpd/magento_access.log combined

</VirtualHost>

APACHE

# Enable-Start Appache

sudo systemctl enable --now httpd

sudo systemctl status httpd