Forum Moderators: phranque

Message Too Old, No Replies

Problem setting up Apache2

         

larry29936

7:24 pm on Jul 3, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



I've created a .conf file in the apache2/sites-available folder as follows:
<VirtualHost *:80>

ServerName test

ServerAdmin webmaster@localhost
DocumentRoot /home/larry/web/test/public_html
LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

I also added test to the hosts. When I try to open http://test, I get the apache default screen instead of /home/larry/web/test/public_html/index.html file. I restarted apache2 and checked the status, which is good. Can someone help me out on this?

Thanks in advance,
Larry


[edited by: not2easy at 7:29 pm (utc) on Jul 3, 2020]
[edit reason] readability [/edit]

not2easy

8:12 pm on Jul 3, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Hi larry29936 and welcome to WebmasterWorld [webmasterworld.com]

Sorry, your post needed a minor edit so that others could read that test URL. The forum software auto-links URLs unless they use "example.com" but your URL appears to be part of a path rather than a URL. In a typical configuration, you would need to use a request for http://example.com/index.html or http://example.com/ or http://11.22.33.nn/index.html to view that page in a browser - but a browser is expecting to parse an URL using http: that includes a domain or an IP. We're missing some information.

Without some background on the configuration /setup it is not clear how a browser could view that page. For your own privacy/security it is acceptable to anonymize specifics( as done with the "IP" used) that could expose your server when sharing information here. Is your Apache part of a MAMP or WAMP package?

That readability thing happens to me too ;)

[edited by: not2easy at 10:00 pm (utc) on Jul 3, 2020]

lucy24

8:53 pm on Jul 3, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When I try to open http://test

By “try to open” do you mean typing it into your browser? How does the browser know where to go if it isn’t a public site with a DNS entry? Exact mechanics will depend on your OS--I mean the computer that has the browser, not the server's OS--but on mine* I had to manually edit the system’s Hosts file so it would know where to look.


* not2easy and I both happen to be on Macs, so if you are on something else you can happily ignore everything we tell you.

w3dk

9:17 pm on Jul 3, 2020 (gmt 0)

10+ Year Member Top Contributors Of The Month



I've created a .conf file in the apache2/sites-available folder


Have you created the necessary symlink from the "sites-enabled" folder? (eg. "a2ensite test" - where "test" refers to "test.conf" in the sites-available folder)

Ordinarily, Apache looks for conf files (or symlinks to) in the "sites-enabled" folder on startup - although versions may vary - and you can configure this however you like.
(In the main server config there would an "include" directive that does this.)

larry29936

9:42 pm on Jul 3, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



This was installed from a LAMP stack. Yes, I ran sudo a2ensite test and restarted the server. The symlink was created in the sites-enabled folder. The host file entry for test uses the same ip as for localhost.

Could the issue be that when I edited the .conf I didn't use an editor in terminal?

larry29936

9:49 pm on Jul 3, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



Disregard my last comment, I opened test.conf in vi, added a space to the end of the file, and saved it. No change, still getting the apache2 default page.

w3dk

10:36 pm on Jul 3, 2020 (gmt 0)

10+ Year Member Top Contributors Of The Month



What is the HTTP status code in the response?

You aren't currently "allowing" access, so I would perhaps expect a 403 Forbidden - unless you are allowing access elsewhere? (Although I wouldn't necessarily expect the "Apache default screen" in this instance - unless this is configured as the 403 error page?)

You would need something like the following in your VirtualHost config:


<Directory /home/larry/web/test/public_html>
Require all granted
</Directory>


(Assuming Apache 2.4)

larry29936

6:53 am on Jul 4, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



@w3dk I added your suggested directives to test.conf, deleted the symlink in the sites-enabled folder, ran a2ensite to recreate the symlink, and reloaded apache2. Now when I go to http://test in my browser, I get a grey screen which is the background color of index.php. If I go to http://test/index.php, it shows the code of index.php. If I rename index.php to index.html, I get the same result. There's a lot of php code in index.php so I think the problem now is in the configuration of php 7.4.

I confirmed that I'm a member of the www-data group, if that matters.

[edited by: phranque at 12:28 am (utc) on Jul 14, 2020]
[edit reason] unlinked urls [/edit]

larry29936

6:59 am on Jul 4, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



Just out of curiosity I tried to open phpMyAdmin to establish a database. I got a 404 Not Found error.

larry29936

7:49 am on Jul 4, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



Added the following to apache2.conf and reloaded apache2. Now the browser is showing the contents of a php file when I try to open phpMyAdmin.
Include /etc/phpmyadmin/apache.conf

larry29936

12:41 pm on Jul 4, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



Thanks to everyone for your help. I finally got it working. There were several things that were misconfigured. It was an all-nighter doing searches on the web before I found them all. I'll do a write-up so if anyone else trying to do a LAMP setup runs into the same type of problems, I'll be able to suggest fixes.

not2easy

1:02 pm on Jul 4, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



We're always happy when a problem is solved. We're even happier when we get to know the end of the story. That way it can help the next one who has this problem. ;)

larry29936

3:27 pm on Jul 4, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



The best site I found with instructions on installing a LAMP Stack on Ubuntu 20 and other distros based on it is "linuxbabe.com".
Here are some problems I ran into after following instructions on another website:

1. After copying the 000-default.conf in /etc/apache2/sites-available, they didn't say anything about modifying the file to include the following:

 <Directory /var/www/html> <-----Where ever your website files are
Require all granted
</Directory>
.

2. They didn't say anything about modifying /etc/apache2/apache.conf to add the following line to ensure that apache knows about phpMyAdmin.
 Include /etc/phpmyadmin/apache.conf
.

3. In the /etc/hosts file, they said to add your server name and set it IP to "127.0.0.1". They didn't mention that it should be set to whatever localhost is set to, which in my case is "127.0.1.1".

Hope this helps someone in the future.

not2easy

4:15 pm on Jul 4, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Thank you Larry, that does help anyone trying to do the same thing you did.