I am not an experienced Apache coder/developer. I've edited .conf files before, but it's been a minute or several.
I have Apache/2.4.52 on my Ubuntu 22.04 machine. For what it's worth, I use PHP8.1.2
How can I view my development websites (dev-sites) via localhost when the directory I have my websites in is not /var/www/html?
I build my sites(code) in /home/jdc44/Websites/ I.e: one such site is: /home/jdc44/Websites/LivingMuayThai There is a live website, but I want to make changes to the site/code and be able to view it locally before pushing any issues live. I would like to view the site at: localhost/livingmuaythai or camel-cased: localhost/LivingMuayThai as that is the name of the directory the code is in.
I'll post my code here and hope someone can tell me what I'm missing or how to do it if this is all wrong. I followed this tutorial from 2009, but it is not working. Maybe things have changed...
How to configure apache webserver on linux
I created a livingmuaythai.conf file in /etc/apache2/sites-available/
## /etc/apache2/sites-available/livingmuaythai.conf
## I removed all the commented lines for space
<VirtualHost *:80>
# ServerName www.example.com
ServerName livingmuaythai // do I need a .com on this?
ServerAdmin [email protected]
DocumentRoot /home/jdc44/Websites/LivingMuayThai/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/jdc44/Websites/LivingMuayThai/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<FilesMatch "\.*">
SetHandler application/x-httpd-php
</FilesMatch>
</VirtualHost>
## /etc/hosts
127.0.0.1 localhost livingmuaythai
I enabled the site:
sudo a2ensite livingmuaythai
A symlink was created in /etc/apache2/sites-enabled/. The setup created this, not me.
livingmuaythai.conf -> ../sites-available/livingmuaythai.conf
Then restarted/reloaded Apache
When I go to http://localhost/livingmuaythai/index.html I get a 404 Not Found page.
Note: I have a firewall and port 80 is open.
Thoughts? Thanks for any help.
You have talked about enabling your new site, but not about disabling the default site, so my guess is you have both still set up. You can check this in two ways:
/etc/apache2/sites-enabled/- as you've seen, this is the folder managed by thea2ensiteanda2dissitecommands, as a convenient way of turning sites on and offsudo apache2ctl -S, which gives a breakdown of all the "virtual hosts" Apache thinks are configured, and where they're definedProbably, you just want to run
sudo a2dissite some-default-site-in-the-listAt this point, it's worth a quick detour to understand how Apache resolves sites:
Includelines and symlinks are just for human convenience.http://example.com/foo/bar/bazwill have IP address93.184.216.34(that's what I currently get when I runnslookup example.com), port80and Host headerexample.com<VirtualHost>blocks in the configuration.<VirtualHost>blocks specifying an IP address and/or port of*are matched.ServerNameandServerAliaslines they contain. The first time one is found that matches the requested hostname, that VirtualHost block is used.ServerNameorServerAlias, the first block is used (out of the list matching IP address and port).In your case,
<VirtualHost *:80>means "any IP address, port 80", andServerName livingmuaythaisays this should be a good choice for URLs likehttp://livingmuaythai/foo/bar.Your request
http://localhost/livingmuaythai/index.htmlwill look for, in order:<VirtualHost 127.0.0.1:80>withServerName localhostorServerAlias localhost<VirtualHost 127.0.0.1:80>block defined<VirtualHost *:80>withServerName localhostorServerAlias localhost<VirtualHost *:80>block defined