Configure LAMP server

Title: Unable to Connect to MariaDB from stlb01 Host

Description:

Hello Kode Kloud community,

I hope you’re all doing well. I’m currently facing an issue with configuring a LAMP server in Linux, particularly with connecting to MariaDB from the stlb01 host.

Here’s the situation:

However, I’m encountering difficulties connecting to MariaDB from the stlb01 host. I’ve reviewed the official documentation from MariaDB, but I’m still unable to establish a connection.

Im using this script to performe the tasks

#!/bin/bash

Function to install httpd, php, and their dependencies on all app hosts

install_httpd_php() {
echo “Installing httpd, php, and dependencies…”
sudo yum install httpd php php-mysqlnd -y
}

Function to configure Apache to serve on port 8082 within the apps

configure_apache_port() {
echo “Configuring Apache to serve on port $HTTP_PORT…”
sudo sed -i “s/^Listen 80$/Listen $HTTP_PORT/” /etc/httpd/conf/httpd.conf
sudo systemctl restart httpd
}

Function to install and configure MariaDB server on DB Server

install_configure_mariadb() {
echo “Installing and configuring MariaDB server…”
sudo yum install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
}

Function to create database and user in MariaDB

create_database_user() {
echo “Creating database and user in MariaDB…”
sudo mysql -e “CREATE DATABASE IF NOT EXISTS $DB_NAME;”
sudo mysql -e “CREATE USER IF NOT EXISTS ‘$DB_USER’@‘%’ IDENTIFIED BY ‘$USER_PASSWORD’;”
sudo mysql -e “GRANT ALL PRIVILEGES ON $DB_NAME.* TO ‘$DB_USER’@‘%’;”
sudo mysql -e “FLUSH PRIVILEGES;”
}

Main function to execute all steps

DB_NAME=“kodekloud_db6”
DB_USER=“kodekloud_gem”
USER_PASSWORD=“GyQkFRVNr3”
HTTP_PORT=“8082”

main() {
install_httpd_php
configure_apache_port
install_configure_mariadb
create_database_user
}

Execute main function

main

im getting this message if i try to connect locally with stlb01

mysql -u kodekloud_user -p database_name -h stlb01
Error Message: error 2002 (hy000): can’t connect to mysql server on ‘stl 01’ (115)

and on static app website got this message Unable to Connect to ‘stdb01’

also my mariadb is working and running on right port

For a start, your script configures the user as kodekloud_gem and the mysql command you are running to connect is using user kodekloud_user

Please also paste scripts

in code blocks

then all the comments will not be rendered as headings.