Fix issue with LAMP Environment in Kubernetes (kubernetes level 2)

Hello,i updated the “index.php” file with the correct variables,the connection now works fine (php index.php) but the “check” button fails,ive tried this many times and honestly sick of it lol
i just wanna a solution to this to move on to the next “Kubernetes level 3”
After i corrected the index.php file,should i recreate the “Pod” and the “deployment” ?thnx :slight_smile:


And this is my “index.php”:

<?php $dbname = $_ENV['MYSQL_DATABASE']; $dbuser = $_ENV['MYSQL_USER']; $dbpass = $_ENV['MYSQL_PASSWORD']; $dbhost = $_ENV['MYSQL_HOST']; $connect = mysqli_connect($dbhost, $dbuser, $dbpass); if (!$connect) { die("Unable to connect to '$dbhost': " . mysqli_connect_error()); } mysqli_select_db($connect, $dbname); $test_query = "SHOW TABLES FROM $dbname"; $result = mysqli_query($connect, $test_query); if (!$result) { die("Error in query: " . mysqli_error($connect)); } echo "Connected successfully"; ?>

When you check the answer what is the error?

Did you validate the service for lamp-service?

There are some errors but i don’t think they are so accurate,and For the service,the targetPort is already good,

Is the NodePort correct? The errors are actually accurate.

yes it is correct.
I updated the index.php accordingly,checked the connection and it is good,but don’t know what to do later?because i recreated the Pod and Deployment,and it is still not working (the app is unaccessible)

Without seeing the error it is hard to tell what is wrong.

You don’t need to recreate the Pod or the Deployment, you can run this in the Pod:

service php-fpm restart

hi @karaoudriadh

You could use the following php script which worked fine for me and the validation has passed…

<?php // Fetching environment variables $dbname = $_ENV['MYSQL_DATABASE']; $dbuser = $_ENV['MYSQL_USER']; $dbpass = $_ENV['MYSQL_PASSWORD']; $dbhost = $_ENV['MYSQL_HOST']; // Creating a connection to the database $connect = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); // Checking connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } echo "Connected successfully"; // Performing a test query $test_query = "SHOW TABLES FROM $dbname"; $result = mysqli_query($connect, $test_query); if (!$result) { die("Query failed: " . mysqli_error($connect)); } // Fetch and display the tables while ($row = mysqli_fetch_row($result)) { echo "Table: {$row[0]}\n"; } // Closing the connection mysqli_close($connect); ?>

(For Others: The index .php file was located inside the httpd-php-container at /app location…The error which has been mentioned in the task are,

  1. Most cases nodeport/container port mapping may be wrong
  2. The env variables in the index.php file contains some spelling mistakes and config issues so use the above script for the convenient.

image