How to remove nginx and re activate apache?

I have installed Apache2, mysql, php5 and phpmyadmin on my Ubuntu 14.04 but later on mistakenly I install nginx.

Now my localhost page show me Welcome to nginx server. And the localhost/phpmyadmin link is not working.

How can I get my LAMP server back?

i removed ngnix using command

sudo apt-get remove nginx
sudo apt-get purge nginx

installing apache

sudo apache2ctl restart

but at the end on restarting apache2 i get this error

sudo apache2ctl restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
Action 'restart' failed.

Solution 1:

First, you need to stop nginx so it releases port 80 so that apache2 can listen to it later on.

sudo service nginx stop

Next, if nginx was installed with apt-get, it can be removed by running one of the following two commands (I explained the difference in the next paragraph).

sudo apt-get remove nginx

Or

sudo apt-get purge nginx

Both of them remove all package files, while the second also removes the configuration files that package had installed.
If you intend to use nginx later on with the configuration you did, use remove. Else, I would suggest using purge.

After removing nginx, you can restart apache to make sure it is listening to port 80.

sudo apache2ctl restart

If you had removed apache before installing nginx, you can re-install it with

sudo apt-get install apache2

Solution 2:

if after that the Welcome to nginx! page appears you can try unistall other version on nginx existing on your server with

sudo apt-get remove nginx-*

and

sudo apt-get purge nginx-*

Solution 3:

Remove all nginx packages

sudo apt-get autoremove nginx
sudo apt-get purge nginx

This works for me

sudo service apache2 restart