AI systemsSoftware engineeringDigital solutions

Ubuntu Os

Setup Apache2, MYSQL,PHP on Ubuntu 22.04

By Tarnnum Shahnaz
$ sudo apt update
$ sudo apt install apache2

To only allow traffic on port 80, use the Apache profile:

$ sudo ufw allow in "Apache"

Open your server's public IP address in your web browser

http://your_server_ip

Step 2 — Installing MySQL

$ sudo apt install mysql-server

When prompted, confirm installation by typing Y, and then ENTER. After installation First, open up the MySQL prompt using below command:

$ sudo mysql

Then run the following ALTER USER command to change the root user's authentication password

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> exit

Step 3 — Installing PHP

$ sudo apt install php libapache2-mod-php php-mysql
$ php -v
Output
PHP 8.1.2 (cli) (built: Mar  4 2022 18:13:46) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

Changing Apache's Directory Index

$ sudo nano /etc/apache2/mods-enabled/dir.conf

It will look like this:


    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
Move the PHP index file to the first position after the DirectoryIndex - Now Restart the Apache2 Server
sudo systemctl restart apache2
Tags:IT