Install Lamp stack on Almalinux. Then host a website called "php.table.com". The "php.table.com" must contain a file called table.php. When someone opens the link "http://php.table.com/table.php", the page must display the contents from a database.
Run system update
dnf update
The next step is to install the Apache webserver on AlmaLinux
dnf install httpd httpd-tools
Once the webserver is installed, let’s start its service and also make it automatically up with the system boot. This will ensure whenever you boot AlmaLinux you won’t need to start Apache manually.
systemctl start httpd
systemctl enable httpd
After installing Apache and applying its settings, we will now check its Status:
systemctl status httpd
If you want to access the Apache webserver outside your local machine using some browser, then first we have to open ports 80 and 443 on our AlmaLinux server.
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
Install mariadb
dnf install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
systemctl Status mariadb
This step will give some options to follow and set some settings so that we can secure of Database from any common future threats.
mysql_secure_installation
Install php
First, check what are PHP versions available to install:
dnf module list php
To install PHP 8.2, first enable the module as provided.
dnf module reset php
dnf module enable php:8.2
install php
dnf install php php-common php-opcache php-cli php-gd php-curl php-mysqlnd
To get better performance for various applications using PHP, we can start (if not already) and enable PHP-FPM (FastCGI Process Manager) using the below commands:
systemctl start php-fpm
systemctl enable php-fpm
now verify the installation
php -v
Create and configure the website
Create Document Root Directory:
mkdir -p /var/www/php.table.com
Set permissions
chown -R apache:apache /var/www/php.table.com
chmod -R 755 /var/www/php.table.com
configure your DNS settings to point php.table.com to your server's IP address.
vim /etc/hosts
192.168.1.89 php.table.com
Create Apache Configuration File for php.table.com: Create a new file in /etc/httpd/conf.d/:
vim /etc/httpd/conf.d/php.table.com.conf
ServerAdmin [email protected]
DocumentRoot /var/www/php.table.com
ServerName php.table.com
ErrorLog /var/log/httpd/php.table.com-error.log
CustomLog /var/log/httpd/php.table.com-access.log combined
</VirtualHost>
Restart httpd
systemctl restart httpd
Set up the database
Log in to MariaDB:
mysql -u root -p
Create Database and Table:
CREATE DATABASE clado;
USE clado;
CREATE TABLE students ( name CHAR(20), mark INT(3) );
INSERT INTO students (name, mark) VALUES ('Alice', 85);
INSERT INTO students (name, mark) VALUES ('Bob', 90);
INSERT INTO students (name, mark) VALUES ('Charlie', 78);
EXIT;
Create table.php in the Document Root:
vim /var/www/php.table.com/table.php
Add the following code
$servername = "localhost";
$username = "root";
$password = "1234";
$dbname = "clado"; // Create connection
$conn = new mysqli($servername, $username, $password, $dbname); // Check connection
if ($conn->connect_error)
{ die("Connection failed: " . $conn->connect_error); } // Fetch data
$sql = "SELECT name, mark FROM students";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{ // Output data of each row echo "<table border='1'><tr><th>Name</th><th>Mark</th></tr>";
while($row = $result->fetch_assoc())
{ echo "<tr><td>" . $row["name"]. "</td><td>" . $row["mark"]. "</td></tr>"; }
echo "</table>";
}
else
{ echo "0 results"; }
$conn->close();
?>
Save and close the file. Ensure the correct permissions:
chown apache:apache /var/www/php.table.com/table.php
chmod 644 /var/www/php.table.com/table.php
Open your web browser and navigate to http://php.table.com/table.php. You should see a table displaying the contents from the students database.