foxclone Posted April 9, 2022 Share Posted April 9, 2022 My Apache2 local server is working fine for my website. I've added a test.conf to sites-available and added it to my hosts file so I can do some experimentation without messing with my production website. The problem is that when I try to go to it in my web browser, I get a Not Found. This is on a Linux system, and yes, I did restart apache after I added test.conf. There's nothing in either the error log or the access log. My entry from sites-enabled follows: <VirtualHost *:80> ServerAdmin webmaster@test ServerName test ServerAlias test DocumentRoot /var/www/test/public_html <Directory /> AllowOverride All </Directory> <Directory /var/www/test/public_html> Options Indexes FollowSymLinks MultiViews AllowOverride all Require all granted </Directory> ErrorLog /var/log/apache2/test-error.log LogLevel error CustomLog /var/log/apache2/test-access.log combined </VirtualHost> I'm beginning to wonder if test is a reserved word for apache. I'd appreciate some help on this. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
foxclone Posted April 9, 2022 Author Share Posted April 9, 2022 I did some testing. If I enter 127.0.0.1/test/public_html, the new test website appears in the web browser. This tells me the problem isn't in the hosts file. If I enter http://test/public_html in the web browser, I get a Not Found. This tells me that the the problem is with Apache. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 9, 2022 Share Posted April 9, 2022 The servername needs to be a domain name -- something that the DNS of your workstation can resolve. What you want to do is use an appropriate top level domain (ie. .com, .net etc) for testing, and set that up in your hosts file on your workstation. The IETF set aside a number of development tld's, and of these you should use either .test or .example. You should avoid using .localhost even though that is also reserved, just in case you get some loopback conflict. so what I'd suggest is that you add something like this in your /etc/hosts 127.0.0.1 www.project1.test 127.0.0.1 www.project2.test It doesn't matter what project1 or project2 actually is. One argument in favor of using one domain like (projects.test), is that you can setup a local SSL cert on your machine, and use that for multiple projects. You would then use www.projects.test, cms.projects.test, admin.projects.test or whatever else makes sense for your development work. It doesn't matter how you do it, so long as it works for you. In this example, I will stay with the 2 separate domains example. Here is the apache vhosts config you would want: <Directory /> AllowOverride None </Directory> <VirtualHost *:80> ServerAdmin webmaster@test ServerName www.project1.test DocumentRoot /var/www/public_html <Directory /var/www/public_html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog /var/log/apache2/project1-error.log LogLevel error CustomLog /var/log/apache2/project1-access.log combined </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@test ServerName www.project2.test DocumentRoot /var/www/test/public_html <Directory /var/www/test/public_html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog /var/log/apache2/project2-error.log LogLevel error CustomLog /var/log/apache2/project2-access.log combined </VirtualHost> Notice that I fixed the Directory statements for each of your vhosts. These refer to the directory structure of your server, so you can't redefine those perms, as they aren't relative to a specific vhost. Apache starts out with (or should, depending on your OS/Distribution) a definition of <Directory />AllowOverride None</Directory> as a way of blacklisting the entire directory structure by default. You are then meant to override specific directories from which you are actually serving content. Usually this type of configuration is set so that you can/will have a .htaccess file in the root of your project directory that you will use for things like mod_rewrite rules. Quote Link to comment Share on other sites More sharing options...
foxclone Posted April 9, 2022 Author Share Posted April 9, 2022 (edited) @gizmola - Does that get put in as one long file? I did, and both project1 and project2 take me to the test folder. project1 should be taking me to the foxclone folder. Edited April 9, 2022 by foxclone additional info Quote Link to comment Share on other sites More sharing options...
foxclone Posted April 9, 2022 Author Share Posted April 9, 2022 (edited) @gizmola - Got everything fixed - had to better define DocumentRoot path for both. I appreciate your continued support. Edited April 9, 2022 by foxclone 1 Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 10, 2022 Share Posted April 10, 2022 No worries. To answer your question, typically apache's main config file will load files in one or two other directories. Some linux distros have schemes for turning vhosts on/off via symlinks from one directory to another. It really depends on your OS/Linux distro and the defaults. Reading through the conf files is worth doing. The general best practice is to put each vhost in its own conf file. You also want to have each virtual host site in its own directory, and not have any nesting. In other words Do this: /var/www/site1 /var/www/site2 Don't do this: /var/www/site1 /var/www/site1/site2 Really, the best practice for php projects is to do this: /var/www/site1/public <- set webroot to this for site1. /var/www/site2/public <- webroot for site2 This allows you to have other directories with php files in them that you want to include, but can't be directly accessed via a url. Things like config files, class definitions, function libraries etc. can all be kept out of webspace, but are still available by scripts in or beneath site1/public. Quote Link to comment Share on other sites More sharing options...
foxclone Posted April 10, 2022 Author Share Posted April 10, 2022 (edited) @gizmola - I've run into a problem. I tried adding project2 to the file but it's not working. I did add an entry for it in hosts file. Here's what I have: <Directory /> AllowOverride None </Directory> <VirtualHost *:80> ServerAdmin webmaster@test ServerName foxclone DocumentRoot /var/www/foxclone/public_html <Directory /var/www/public_html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog /var/log/apache2/foxclone-error.log LogLevel error CustomLog /var/log/apache2/foxclone-access.log combined </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@test ServerName www.project1.test DocumentRoot /var/www/test/public_html <Directory /var/www/test/public_html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog /var/log/apache2/test-error.log LogLevel error CustomLog /var/log/apache2/test-access.log combined </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@test ServerName www.project2.test DocumentRoot /var/www/brown/public_html <Directory /var/www/brown/public_html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog /var/log/apache2/test-error.log LogLevel error CustomLog /var/log/apache2/test-access.log combined </VirtualHost> What I get when I enter http://www.project2.test in my browser is just an "Index of /" and a blank page. There is an index.php in the public_html folder. I appreciate your help. Edited April 10, 2022 by foxclone Quote Link to comment Share on other sites More sharing options...
foxclone Posted April 11, 2022 Author Share Posted April 11, 2022 I've split the combined file into individual files and get the same results. I'm totally stumped. Here's my project2.conf file: <VirtualHost *:80> ServerAdmin webmaster@test ServerName www.project2.test DocumentRoot /var/www/blue/public_html <Directory /var/www/blue/public_html> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> ErrorLog /var/log/apache2/test-error.log LogLevel error CustomLog /var/log/apache2/test-access.log combined </VirtualHost> Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 11, 2022 Share Posted April 11, 2022 Putting the vhosts into separate conf files is an option. It's not a necessity. In your original file i saw this mismatch: DocumentRoot /var/www/foxclone/public_html <Directory /var/www/public_html> You declare the docroot to be /var/www/foxclone/public_html but then your Directory doesn't match that. See the issue? In order for an index.php to be the default file loaded you need a DirectoryIndex index.php Somewhere in the loading of files. One other thing that can cause issues is that the user that apache is running as, needs at very least "rx" permissions to directories, and "r" perms for the files. It doesn't matter if they get those permissions as owner,group or other, although it's best practice not to use "other" perms. Typically your apache process is going to be configured to run as "apache". You can do a quick check from a shell using "ps aux | grep http" Quote Link to comment Share on other sites More sharing options...
foxclone Posted April 11, 2022 Author Share Posted April 11, 2022 (edited) @gizmola- I fixed the foxclone problembefore my last message. The problem is that project 2,3, and 4 don't work. That's why I posted project2, hoping you'd see a problem. Here's the result of "ps aux | grep http" : larry@t430:~$ ps aux | grep http larry 2130 0.0 0.0 2420 520 ? S 06:02 0:00 sh -c /usr/lib/x86_64-linux-gnu/libproxy/0.4.17/pxgsettings org.gnome.system.proxy org.gnome.system.proxy.http org.gnome.system.proxy.https org.gnome.system.proxy.ftp org.gnome.system.proxy.socks larry 2131 0.0 0.0 233200 8556 ? Sl 06:02 0:00 /usr/lib/x86_64-linux-gnu/libproxy/0.4.17/pxgsettings org.gnome.system.proxy org.gnome.system.proxy.http org.gnome.system.proxy.https org.gnome.system.proxy.ftp org.gnome.system.proxy.socks larry 2185 0.0 0.0 16798540 3020 ? Sl 06:03 0:00 /opt/google/chrome/chrome_crashpad_handler --monitor-self --monitor-self-annotation=ptype=crashpad-handler --database=/home/larry/.config/google-chrome/Crash Reports --url=https://clients2.google.com/cr/report --annotation=channel= --annotation=lsb-release=LMDE 5 (elsie) --annotation=plat=Linux --annotation=prod=Chrome_Linux --annotation=ver=100.0.4896.75 --initial-client-fd=5 --shared-client-connection larry 2187 0.0 0.0 16790328 1324 ? Sl 06:03 0:00 /opt/google/chrome/chrome_crashpad_handler --no-periodic-tasks --monitor-self-annotation=ptype=crashpad-handler --database=/home/larry/.config/google-chrome/Crash Reports --url=https://clients2.google.com/cr/report --annotation=channel= --annotation=lsb-release=LMDE 5 (elsie) --annotation=plat=Linux --annotation=prod=Chrome_Linux --annotation=ver=100.0.4896.75 --initial-client-fd=4 --shared-client-connection larry 7522 0.0 0.0 277312 13336 ? Sl 06:58 0:00 /usr/libexec/gvfsd-http --spawner :1.17 /org/gtk/gvfs/exec_spaw/1 larry 32030 0.0 0.0 6180 716 pts/0 S+ 15:43 0:00 grep http Thanks again. Edited April 11, 2022 by foxclone Quote Link to comment Share on other sites More sharing options...
foxclone Posted April 11, 2022 Author Share Posted April 11, 2022 (edited) @gizmola - I just checked the status of Apache2 and got the following error: Quote larry@t430:~/Downloads$ apache2 --status [Mon Apr 11 16:39:20.266821 2022] [core:warn] [pid 36331] AH00111: Config variable ${APACHE_RUN_DIR} is not defined apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot Could this be part of the problem? Apache is installed in /etc/apache2. I'll set it and see what happens. NOTE: I just found out only the config files are located in /etc/apache2. Don't know where the runtimes are. Edited April 11, 2022 by foxclone Quote Link to comment Share on other sites More sharing options...
Solution foxclone Posted April 11, 2022 Author Solution Share Posted April 11, 2022 @gizmola - Disregard all previous messages. Got everything working. Some files were owned by me but were in Root group. Thanks for everything. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 13, 2022 Share Posted April 13, 2022 No worries. 👍 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.