Create dynamic web content

To demonstrate how easily we can create dynamic web pages that will connect to the database using PHP from the Nginx server, we will create a new PHP page in /var/www/html. So fire up your favorite editor, and we will create the page within the document root, /var/www/html/db.php:

<h2>Databases</h2>
<?php
      $dbh=mysqli_connect("localhost","root","Password1");
      $result=mysqli_query($dbh, "SHOW DATABASES");
      while ($row = mysqli_fetch_assoc($result)) {
        echo $row['Database'] . "<BR>";
      }
?>

The code again is kept as simple as possible, and ideally we would include the connection credentials stored within another file that was not accessible to the web server, allowing access only from the PHP process; however, keeping the code ...

Get CentOS System Administration Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.