Install LAMP and PHPMYADMIN on Ubuntu 22.04

Step 1: Install Apache
sudo apt install apache2 -y
sudo systemctl status apache2
sudo systemctl enable --now apache2
http://server-ip

Step 2: Install MariaDB database server
sudo apt install mariadb-server -y
sudo systemctl status  mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
First, create a password for the root account.
To secure your database server,  type ‘Y‘  for the remaining prompts to achieve the following:
Remove anonymous users
Disallow remote root login
Remove test database
Reload privilege tables

Step 3: Install PHP and the Required Extensions
sudo apt install php libapache2-mod-php -y
php -v
sudo apt install  php-mysql php-xml php-xmlrpc php-curl php-gd php-imagick php-cli php-imap php-mbstring php-opcache php-soap php-zip php-intl -y

let’s create a PHP script to test out PHP integration with Apache.Run the following command
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

http://server-ip/info.php

Step 4: Install phpmyadmin

sudo apt install phpmyadmin -y
sudo phpenmod mbstring
sudo systemctl restart apache2

http://server-ip/phpmyadmin/

if it not works, try solution below

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin.conf
sudo systemctl reload apache2.service

Create mysql user

mysql -u root -p

CREATE USER 'user'@'%' IDENTIFIED BY 'password_user'; (Change password_user in password for user)

GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;

FLUSH PRIVILEGES;