This procedure will create on an Ubuntu 22 machine, a “LAMP” stack. It assumes a brand new Ubuntu 22 install on either a physical or virtual machine.
Source: https://www.linode.com/docs/guides/how-to-install-a-lamp-stack-on-ubuntu-22-04/
Install LAMP stack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
sudo apt-get -y update && sudo apt-get -y upgrade
sudo apt-get -y install apache2
sudo apt-get -y install mysql-server
sudo apt-get -y install php libapache2-mod-php php-mysql
sudo apt-get -y install php-curl php-json php-cgi
sudo apt-get -y install php-curl php-gd php-mbstring php-xml php-xmlrpc
$FN="/etc/apache2/mods-available/mpm_prefork.conf"
sudo echo "<IfModule mpm_prefork_module>" >> $FN
sudo echo " StartServers 4" >> $FN
sudo echo " MinSpareServers 3" >> $FN
sudo echo " MaxSpareServers 40" >> $FN
sudo echo " MaxRequestWorkers 200" >> $FN
sudo echo " MaxConnectionsPerChild 10000" >> $FN
sudo echo "</IfModule>" >> $FN
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
sudo systemctl restart apache2
Example PHP files
This script proves that Apache and PHP are working together properly.
1
2
3
<?php
phpinfo();
?>
This script proves that Apache, PHP and MySQL are working properly.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "mysql";
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SHOW tables from mysql";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$res = mysqli_query($conn,"SHOW TABLES;");
while($cRow = mysqli_fetch_array($res))
{
printf( "[$cRow[0]]<br>" );
}
} else {
echo "0 results";
}
$conn->close();
?>
Setting the root password
By default, MySQL v8 has a root password that is blank.
1
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password';