Search code examples
phpapachelocalhostlampwindows-subsystem-for-linux

Localhost not working after basic installation on WSL


I am trying to install a LAMP working environnement but for some reason nothing happen. The lack of error messages makes me wonder what to look for.

I followed the Ubuntu installation process :

sudo apt install apache2 php libapache2-mod-php mysql-server php-mysql

At that stage, localhost should display the "It works!" message but it doesn't.

I have been restarting the apache service several times with no effect:

sudo service apache restart

it looks to be fine anyway.

I have checked the following files as advices on some online tutorial :

/etc/apache2/sites-available/000-default.conf
/etc/apache2/apache2.conf

I am atually clueless on what to troubleshoot at that point.

Any ideas ?


Solution

  • You have apache2 installed. Try running this instead: sudo service apache2 restart

    I tried installing LAMP on WSL too. But I was lucky. I followed these steps:

    Step 1: Update and Upgrade the ubuntu subsystem

    sudo apt-get update && sudo apt-get upgrade
    

    Step 2: Start bash.exe type:

    sudo apt-get install lamp-server^
    

    remember the caret (^) at the end of the command.

    add these 2 lines in /etc/apache2/apache2.conf :

    Servername localhost
    AcceptFilter http none
    

    then you can start apache :

    /etc/init.d/apache2 start
    

    Step 3: Test Web Server, PHP and MySQL Test Apache: Open Web Browser and type this URL:

    http://127.0.0.1 or http://localhost
    

    Test PHP: Create below file (info.php) and place it in /var/www/html

    <?php
    phpinfo();
    ?>
    

    Open Web Browser and type this URL:

    http://127.0.0.1/info.php or http://localhost/info.php
    

    Test MySQL: Type below command in bash prompt

    service mysql start
    mysql -uroot -ppassword
    

    Hope it works for you.