This document is free text: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see
Although my tutorials (and my learning curve) contain Debian and Ubuntu Linux distributions; Time to time, an admin may need to handle other Linuxes too.
In this tutorial, my aim is to help with other linuxes, namely Red Hat, Alpine and Devuan.
In the previous versions, I used to include OpenSuse too; but I decided that I cannot concentrate on it anymore.
Main subjects are:
Main Distributions:
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9
https://wiki.alpinelinux.org/wiki/Main_Page
https://wiki.debian.org/
https://www.geeksforgeeks.org/how-to-retrieve-data-from-mysql-database-using-php/
Commands require root or sudo.
apt update
apt upgrade
apt install apache2
apt remove apache2
apt search apache2
apt autoremove
apt show apache2
The name of the network adapter will be something like enp0s3, but we need the exact name.
The following command lists the network interface name(s). The one in en* format should be the name of your network adapter.
ls /sys/class/net
In any case you cannot get the name, you can try to following command:
ip a
sudo nano /etc/network/interfaces
I assume that your network adapter name is enp0s3, otherwise change it.
Fill the file like below (change to your IP addresses)
auto enp0s3
iface enp0s3 inet static
address 192.168.0.3/24
broadcast 192.168.0.255
network 192.168.0.0
gateway 192.168.0.1
If you want to use DHCP, fill the file as below
auto enp0s3
iface enp0s3 inet dhcp
sudo nano /etc/resolv.conf
Add your DNS addresses as below
nameserver 46.196.235.35
nameserver 178.233.140.110
nameserver 46.197.15.60
Assuming your network adapter name is enp0s3
sudo ifdown enp0s3 && sudo ifup enp0s3
or
sudo systemctl restart networking.service
If you are connecting through SSH, your connection would break up. You need to connect with the new IP again.
sudo apt update
sudo apt install --yes apache2 mariadb-server php \
libapache2-mod-php php-mysql
This is all we need actually. But if you are like me, that is you have to see it to believe it; you are going to want to test it. So let's test it.
We'll create a test database on Mariadb, we'll create a table in that database, add some rows to the table. We will also create a test PHP file with the PHP code to retrieve the data from the database and display it as HTML. That way we'll be able to test the PHP-Mariadb and PHP-Apache connections.
sudo mariadb
Create mysampledb database, connect to it, create a table, fill the table, create a user with the access permission to that database and the table.
Run on Mariadb shell:
CREATE DATABASE mysampledb;
USE mysampledb;
CREATE TABLE Employees (Name char(15), Age int(3), Occupation char(15));
INSERT INTO Employees VALUES ('Joe Smith', '26', 'Ninja');
INSERT INTO Employees VALUES ('John Doe', '33', 'Sleeper');
INSERT INTO Employees VALUES ('Mariadb Server', '14', 'RDBM');
GRANT ALL ON mysampledb.* TO 'appuser'@'localhost' IDENTIFIED BY 'password';
exit
Create test PHP
sudo nano /var/www/html/test.php
Fill it as below
<?php
$mycon = new mysqli("localhost", "appuser", "password", "mysampledb");
if ($mycon->connect_errno)
{
echo "Connection Error";
exit();
}
$mysql = "SELECT * FROM Employees";
$result = ($mycon->query($mysql));
$rows = [];
if ($result->num_rows > 0)
{
$rows = $result->fetch_all(MYSQLI_ASSOC);
}
?>
<!DOCTYPE html>
<html>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Occupation</th>
</tr>
</thead>
<tbody>
<?php
if(!empty($rows))
foreach($rows as $row)
{
?>
<tr>
<td><?php echo $row['Name']; ?></td>
<td><?php echo $row['Age']; ?></td>
<td><?php echo $row['Occupation']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>
<?php
mysqli_close($conn);
?>
Now, from your workstation's browser, load the page (replace srv with your server's IP:
http:/srv/test.php
You can use the same steps for testing LAMP stack on other distros too.
Conventionally, when a package with a service is installed on Debian, it is enabled and started by default.
systemctl status apache2
sudo systemctl stop apache2
sudo systemctl start apache2
To force to stop
sudo systemctl kill apache2
Reads configuration file again
sudo systemctl reload apache2
Stops and Starts
sudo systemctl restart apache2
sudo systemctl enable apache2
sudo systemctl disable apache2
Commands require root or sudo.
apt update
apt upgrade
apt install apache2
apt remove apache2
apt search apache2
apt autoremove
apt show apache2
The name of the network adapter will be something like enp0s3, but we need the exact name.
The following command lists the network interface name(s). The one in en* format should be the name of your network adapter.
ls /sys/class/net
In any case you cannot get the name, you can try to following command:
ip a
By default Ubuntu uses netplan for network configuration.
sudo nano /etc/netplan/00-installer-config.yaml
The file name might be different, in that case, use that file.
I assume that your network adapter name is enp0s3, otherwise change it.
Fill the file like below (change to your IP addresses)
network:
ethernets:
enp0s3:
addresses:
- 192.168.1.182/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 192.168.1.1
search:
- x11.xyz
version: 2
sudo netplan apply
If you are connecting through SSH, your connection would break up. You need to connect with the new IP again.
sudo apt update
sudo apt install --yes apache2 mariadb-server php \
libapache2-mod-php php-mysql
You can use the test scenario at 1.3.2 to test RHEL LAMP stack.
As Ubuntu being a derivative of Debian, when a package with a service is installed, it is enabled and started by default.
systemctl status apache2
sudo systemctl stop apache2
sudo systemctl start apache2
To force to stop
sudo systemctl kill apache2
Reads configuration file again
sudo systemctl reload apache2
Stops and Starts
sudo systemctl restart apache2
sudo systemctl enable apache2
sudo systemctl disable apache2
Centos (upto 8.x version), Alma and Rocky Linux are compatible with Red Hat. That is, they are same other than brandings and names. So if something works in RHEL, it works in Centos, Alma, and Rocky too.
RHEL gives free licenses for testing purposes, I have 2 VMs running for testing purposes (versions 8.x and 9.x).
Commands require root or sudo.
dnf check-update
It is always called when installing or updating packages.
So it is not necessary
dnf upgrade
dnf install httd
dnf remove httpd
dnf search httpd
dnf autoremove
dnf info httpd
The name of the network adapter will be something like enp0s3, but we need the exact name.
The following command lists the network interface name(s). The one in en* format should be the name of your network adapter.
ls /sys/class/net
In any case you cannot get the name, you can try to following command:
ip a
I assume that your network adapter name is enp0s3, otherwise change it.
Change IP and Gateway, change DNS
sudo nmcli con modify 'enp0s3' ifname enp0s3 ipv4.method manual \
ipv4.addresses 192.168.0.210/24 gw4 192.168.0.1
sudo nmcli con modify 'enp0s3' ipv4.dns 8.8.8.8
sudo nmcli con down 'enp0s3' && sudo nmcli con up 'enp0s3'
As you might expect package names are different in RHEL (e.g. httpd instead of apache2).
sudo dnf -y install httpd mariadb-server php php-mysqlnd
sudo systemctl enable --now httpd
sudo systemctl start httpd
sudo systemctl enable --now mariadb
sudo systemctl start mariadb
RHEL activates firewall by default. We have to open http and https ports permanently.
sudo firewall-cmd --add-service=http --add-service=https
sudo firewall-cmd --add-service=http --add-service=https --permanent
You can use the test scenario at 1.3.2 to test RHEL LAMP stack. For RHEL 8, you should run "sudo mysql" instead of "sudo mariadb".
Unlike Debian and derivatives, RHEL and derivatives does not enable and start services by default.
systemctl status httpd
sudo systemctl stop httpd
sudo systemctl start httpd
To force to stop
sudo systemctl kill httpd
Reads configuration file again
sudo systemctl reload httpd
Stops and Starts
sudo systemctl restart httpd
sudo systemctl enable httpd
sudo systemctl disable httpd
Commands require root or sudo.
apk update
apk upgrade
apk add apache2
apt del apache2
apk search apache2
Not available as much as I know.
apk info apache2
The name of the network adapter will be something like eth0, but we need the exact name.
The following command lists the network interface name(s). The one in eth* format should be the name of your network adapter.
ls /sys/class/net
In any case you cannot get the name, you can try to following command:
ip a
I assume that your network adapter name is eth0, otherwise change it.
Change IP address and Gateway:
sudo nano /etc/network/interfaces
File contents will be like below
auto lo
iface lo inet loopback
#auto eth0
#iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 192.168.0.247/24
gateway 192.168.0.1
hostname alpine
Change DNS Addresses:
sudo nano /etc/resolv.conf
File contents will be like below
nameserver 192.168.0.1
nameserver 8.8.8.8
sudo ifdown eth0 && sudo ifup eth0
sudo apk add apache2 php php-mysqli php-apache2 mariadb mariadb-client
sudo rc-update add apache2 default
sudo rc-service apache2 restart
sudo mysql_install_db --user=mysql --datadir=/var/lib/mysql
sudo rc-update add mariadb default
sudo rc-service mariadb start
You can use the test scenario at 1.3.2 to test Alpine Linux LAMP stack.
Just remember, default web site directory is /var/www/localhost/htdocs in Alpine.
Alpine Linux uses OpenRC as the init system.
rc-service apache2 status
sudo rc-service apache2 stop
sudo rc-service apache2 start
Reads configuration file again
sudo rc-service apache2 reload
Stops and Starts
sudo rc-service apache2 restart
sudo rc-update add apache2 default
sudo rc-update del apache2 default
Devuan is a derivative of Debian without systemd. Devuan 5 & 4 are based on Debian 12 & 11.
Commands require root or sudo.
apt update
apt upgrade
apt install apache2
apt remove apache2
apt search apache2
apt autoremove
apt show apache2
The name of the network adapter will be something like enp0s3, but we need the exact name.
The following command lists the network interface name(s). The one in eth* format should be the name of your network adapter.
ls /sys/class/net
In any case you cannot get the name, you can try to following command:
ip a
sudo nano /etc/network/interfaces
I assume that your network adapter name is eth0, otherwise change it.
Fill the file like below (change to your IP addresses)
auto eth0
iface eth0 inet static
address 192.168.0.3/24
broadcast 192.168.0.255
network 192.168.0.0
gateway 192.168.0.1
If you want to use DHCP, fill the file as below
auto eth0
iface eth0 inet dhcp
sudo nano /etc/resolv.conf
Add your DNS addresses as below
nameserver 46.196.235.35
nameserver 178.233.140.110
nameserver 46.197.15.60
Assuming your network adapter name is enp0s3
sudo ifdown eth0 && sudo ifup eth0
If you are connecting through SSH, your connection would break up. You need to connect with the new IP again.
sudo apt update
sudo apt install --yes apache2 mariadb-server php libapache2-mod-php php-mysql
You can use the test scenario at 1.3.2 to test Devuan Linux LAMP stack.
Conventionally, when a package with a service is installed on Devuan, it is enabled and started by default.
At Devuan installation, user can choose from 3 init systems:
At this tutorial, I assume our Devuan server has sysvinit system.
sudo service apache2 status
sudo service apache2 stop
sudo service apache2 start
Reads configuration file again
sudo service apache2 reload
Stops and Starts
sudo service apache2 restart
sudo update-rc.d apache2 defaults
sudo update-rc.d apache2 remove