After LAMP stack tutorials, I can't find my site on localhost

October 7, 2019 130 views
Apache

I’m a student trying to figure out how to get LAMP stack working on my laptop for Ubuntu 18.04. I need it for a project I’m working on at school and out of school.

I followed a few tutorials,

first
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04
second
https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04
third
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04
fourth
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-on-ubuntu-18-04

to make a long story short, I set my domain as abc and this is me looking at it in terminal

Skynet:/var/www/abc$ ls
index.html websitedirectory

index.html is from the second tutorial and displays:
“Success! The your_domain virtual host is working!”
The index.html works fine and displays when I go to url localhost in firefox. If I try to do localhost/websitedirectory I get a blank page and if I try to do www.abc/websitedirectory/login.php (I added login.php into /etc/apache2/mods-enabled/dir.conf to prioritize it) I also get a blank page. I’m not really sure what I’m doing wrong and how I can get my actual site to display using the LAMP stack. I was using the lampp package from apachefriends.org and I had my site working with that, but I’m trying to figure out how to use it with LAMP stack instead and to apply it to real world situations.

Would anyone be able to clarify this for me and explain what I’m doing wrong. Thank you in advance.

Big thank you to the tutorial authors:
Justin Ellingwood, Kathleen Juell, and Mark Drake

2 Answers

What happens if you enter the full path in your browser - localhost/abc/subdirectory/index.php

Also are you using an .htaccess file and if so can you place the content of it here?

  • for localhost/abc/subdirectory/index.php i get the same Not Found The requested URL was not found on this server.

    yes, I’m using .htaccess

    AuthType Basic
    AuthName "Restricted Files"
    AuthUserFile /etc/phpmyadmin/.htpasswd
    Require valid-user
    
  • I got it working. I was doing 2 things wrong. #1 I had a missing database connection which was causing the blank white screen to load. After adding the db the page loaded. Also when using localhost/ one doesn’t need to provide the full path like localhost/abc/index.php instead use localhost/index.php and that will display the site (at least on a linux machine.) The full path /var/www/your_domain I guess is included when using localhost/ in the URL so using localhost/your_domain/index.php is redundant and results an error.

Hello, @Pachuca

Can you please check if mod_rewrite is enabled? You can check it via this command:

httpd -M | grep rewrite

Also, please make sure that the site files are located in the same directory where your apache virtual hosts - document root is pointing to.

Let me know how it goes.

  • that command doesn’t work for me.

    Skynet:/var/www$httpd -M | grep rewrite
    
    Command 'httpd' not found, did you mean:
    
      command 'http' from snap http (1.0.2-1)
      command 'xttpd' from deb xtide
      command 'http' from deb httpie
    
    See 'snap info <snapname>' for additional versions.
    
    
    • I’m sorry httpd is for CentOS, for Ubuntu is:

      apache2ctl -M
      

      You can try:

      apache2ctl -M | grep rewrite
      

      Let me know how it goes.

      • Thank you for your help. So far I’m not getting anything from that
        output:

        Skynet:~$ apache2ctl -M | grep rewrite
        Skynet:~$ 
        
        
        • It might not be enabled.

          Can you please run this command to enable it:

          sudo a2enmod rewrite
          

          then restart apache:

          sudo systemctl restart apache2
          

          Check again if mod_rewrite is enabled:

          apache2ctl -M | grep -i rewrite
          

          If it’s okay/enabled check your site if it’s loading.

          Let me know how it goes.

          • great that did something

            Skynet:/var/www/abc$ apache2ctl -M | grep -i rewrite
             rewrite_module (shared)
            

            BUT when I visit localhost/abc i’m getting the below instead of a blank page.

            Not Found
            
            The requested URL was not found on this server.
            Apache/2.4.41 (Ubuntu) Server at localhost Port 80
            

            My index.php file for the site is in a sub directory of abc so the full path is like localhost/abc/subdirectory/index.php even when I put that into the url I’m getting the same result. I can’t even see the directories from localhost/abc/ or localhost/.

            this is my virtual host file in /etc/apache2/sites-available/abc.conf

            <VirtualHost *:80>
                ServerAdmin webmaster@localhost
                ServerName abc
                ServerAlias www.abc.com
                DocumentRoot /var/www/abc
                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined
            </VirtualHost>
            

            I was a little confused at this step. Is the way the Server* should be setup correct in terms of url and root path? I don’t know if I did it right.

            Also I only enabled Apache for ufw and not Apache Full, I don’t know if that makes any difference either.

Have another answer? Share your knowledge.