Hi Vijay, althought its not necessary to install the LAMP or XAMPP stack along with PHP, but as you might know PHP is a scripting language and it needs some server to interact with. So its a good practice to install the full stack including server (Apache/Apache2) so that you can test and run your php scripts.
Now I am going to show you the step by step installation process of LAMP (Linux-Apache-MySql-PHP) stack:
1. To install Apache server, use the following command:
>>sudo apt install apache2
2. Next start installing MySQL using the mentioned command:
>>sudo apt install mysql-server
3. After installing Mysql, use this command to finally start installing PHP:
>>sudo apt install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php
4. After successful installation of PHP, apache server should restart automatically. If not, type in the following command to restart it:
>>sudo service apache2 restart
5. To check whether server is running successfully, open browser and navigate to http://localhost/. You should see a web page like this:
6. And everything should be working fine now as all the installations are done. To check the php, type the following command in terminal and you should see a response like shown in screenshot below:
>>php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'