apachectl -t -D DUMP_VHOSTS not showing aliases - apache

I'm running various version of apache 2.2.15 and 2.4(.6 and .7) on a number of servers (some ubuntu some centos) with similar configurations (2.4 and 2.2 differences are handled), but with different sites on each.
I have a script which uses apachectl -t -D DUMP_VHOSTS to get a list of the virtual hosts configured on a particular server, and it works fine to get me a list of virtual hosts, and my script happily handles the differences from output from 2.2 and 2.4
However, I need to include aliases in the output from my script. Searching the internet tells me that the above should list aliases under each vhost. It doesn't, on any of my servers. https://bz.apache.org/bugzilla/show_bug.cgi?id=51680 even says it was included in the main source at 2.4.1. https://ma.ttias.be/apachectl-linux-get-entire-apache-vhost-configuration-one-output/ shows what looks like 2.2 output with aliases
Can anyone tell me how to make this work?
Thanks
EDIT:-
ezra-s asked for an example of what I'm seeing, this is typical, and comes from Ubuntu 14 running 2.4.7
/var/www/html$ apachectl -t -D DUMP_VHOSTS
VirtualHost configuration:
*:80 <host>.simon.uk (/etc/apache2/sites-enabled/simon.uk.conf:1)
*:8080 <host>.simon.uk (/etc/apache2/sites-enabled/simon.uk.conf:42)
*:443 ubuntu.<domain removed> (/etc/apache2/sites-enabled/ssl_proxy.conf:12)
As mentioned in comments I tracked the output down to server/vhost.c:dump_a_vhost() in the apache source. In there is code that ultimately shows the above summary, over the detailed output with aliases, when there are no NameVirtualHosts defined. Guess what, they were depreciated in 2.4 so can't be defined anymore.
I've logged this as a bug at https://bz.apache.org/bugzilla/show_bug.cgi?id=61019

Related

Apache configuration: how to get quick feedback?

When writing configuration files for Apache web server I would like to have a quick feedback loop.
I, for example have a script that doesn't seem to work. It is either not picked up, or the variables I use are not set, or maybe overriding is not allowed. How to debug this?
I expected to at least print some debug log statements like REQUEST_URI: %{REQUEST_URI}. Can't find such a thing.
apachectl is a front end to the Apache HyperText Transfer Protocol (HTTP) server. It is designed to help the administrator control the functioning of the Apache httpd daemon.
Here is a link to the documentation.
Different platform might use different binary names such as apache, apache2 or apache2ctl. To test the configuration - just run:
apachectl configtest
# or, depending on your OS
httpd -t
EDIT
If you are trying to debug your virtual host configuration, you may find the Apache -S command line switch useful. That is, type the following command:
httpd -S
This command will dump out a description of how Apache parsed the configuration file

Apache2 Problems after updating OSX to High Sierra

For the week I have had major issues with Apache. My development environment on my mac stopped working after I updated to High Sierra. I tried for hours fixing this myself but couldn't find a solution.
Server version: Apache/2.4.29 (Unix)
Basically what is happening, whenever I try to restart apache I get this message:
AH00558: httpd: Could not reliably determine the server's fully
qualified domain name, using 10.0.0.50. Set the 'ServerName' directive
globally to suppress this message
I have tried a ton of different ways of configuring my vhosts file as well as my httpd config but have seen no improvement.
The document root path was not pointed where my website existed before. After finding that out and pointing it at the correct location the "It Works!" message I was getting every-time disappeared and now I am only greeted with a message that says
Not Found
The requested URL / was not found on this server.
This message happens no matter what path I put for the DocumentRoot section so I'm not sure what the real problem is.
Also, I have my apache set up to use localhost, however it continues to use 10.0.0.50 as it's IP of choice. I have never seen this IP before and I am confused on where it came from.
TLDR: I am having tons of problems with apache after updating to High Sierra, have tried to uninstall/reinstall. Apache is using 10.0.0.50 as the IP, DocumentRoot seems to have problems, config seems to be messed up.
Check configuration:
httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.79. Set the 'ServerName' directive globally to suppress this message
Syntax OK
To fix that:
sudo vi /etc/apache2/httpd.conf
Before:
ServerName www.example.com:80
After:
ServerName localhost
Check configuration again:
httpd -t
Syntax OK

Apache plugin not working for Let's Encrypt

I'm trying to secure my CentOS 7 VPS with Let's Encrypt. I've followed the guidelines in https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-centos-7 . I've set up virtual hosts, installed server dependencies and the Let's Encrypt client. But when I try to set up the SSL certificate with:
./letsencrypt-auto --apache -d example.com -d mail.example.com
I get the error:
The apache plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError()
The Apache Plugin for Let's Encrypt is not working, but how do I make it work?
Same error on CentOS 7 and Apache 2.4. Checked through my configuration, had a couple of IfModule lines that were not closed with /IfModule. Apache is OK with them, but apparently certbot parser isn't. Hope this helps others.
appretnly they are a bug in the letsencrypt-auto script, you can use this command to do the job.
sudo certbot --authenticator standalone --installer apache -d <yourdomain> --pre-hook "systemctl stop apache2" --post-hook "systemctl start apache2"
This answer is not working. In my cases i checked apache config file and found the following line at the end of it <IfModule mod_ssl.c> It was not making sense. On removing it the renewal went on without a problem

How to change the apache user for a virtual host in Centos 7?

I am trying to set up a web server on Centos 7. I have created a virtual host by editing /etc/httpd/conf/httpd.conf. The root directory of the virtual host was set to /var/www/html/domain.com. I am able to open domain.com in the browser with no issue.
However, when I use get_current_user() in a PHP file to test what user the server is running under, the output is "root" which is a security concernt.
How do I change the user of the virtual host? When I set up a similar scenario in Ubuntu, I used apache2-mpm-itk module and configured the virtual host with "AssignUserID your_username your_username" and it did the trick. But I don't know how to do it in Centos.
Thanks
You can try to use SuexecUserGroup for that.
I found this method from plesk's configuration.
<VirtualHost *:80>
<IfModule mod_suexec.c>
SuexecUserGroup "anyuser" "anygroup"
</IfModule>
/VirtualHost>
In CentOS, this command gives you the file's owner, not the owner of the process ID. Something like that. It's in the PHP manual. Check out the comments at the bottom. get_current_user() By the way, check your User and Group directives in the httpd.conf and in httpd-vhost.conf. Also, use ps -faux to get a clear idea of the process spawning relationships between the httpd binary and the children it spawns. Just trying to help. ;-)
Also, check out How Apache Starts at the top of this page to make sure you understand how Apache is supposed to work by default. If yours in not working this way, that may be a good thing to know!! ;-)
In CentOS 7 you can use the httpd-itk package. It is in the EPEL repository, so you need to add that first. Something like this should get it:
yum install epel-release
yum install httpd-itk
Once installed you need to load the module by uncommenting the LoadModule line in:
/etc/httpd/conf.modules.d/00-mpm-itk.conf
Restart the httpd, and then you can use the new AssignUserID directive inside your VirtualHost sections.
have you looked into which user/group is specified in /etc/httpd/conf/httpd.conf? It would look something like this:
User apache
Group apache

How to enable mod_rewrite on Apache server

I need to enable mod_rewrite on a Apache server version 2.4.16. The server is running CENTOS 6.7 x86_64 - I tried many different things but nothing worked.
Also, is there anyway I can find out if mod_rewrite is already enabled?
Thanks,
Richard.
A good way to see if it's enabled is by trying to use it.
The apache documentation shows a pretty simple way to test out mod_rewrite . Place the following in an htaccess file:
Redirect "/foo.html" "/bar.html"
And then check if yoursite.com/foo.html redirects properly.
https://httpd.apache.org/docs/2.4/rewrite/remapping.html
a2ensite is not going to work, that's a binary built into the apache package for debian, you mentioned a centos installation.
To determine specifically if mod_rewrite is built into your apache install, use
httpd -M
To list loaded modules and grep for the one you want (rewrite).
[root#server ~]# /usr/sbin/httpd -M | grep rewrite
rewrite_module (shared)
[root#server ~]#
Test 1:
Easiest way to test if mod_rewrite is ON/OFF is to create a php info file
Under “apache2handler” check for “Loaded Modules” section. There will be a list of loaded modules. Check if mod_rewrite is present in the list.
Test 2:
By creating a file called .htaccess and then by typing the following lines in it
Options +FollowSymLinks
RewriteEngine On
How to find if mod_rewrite is enabled in Apache server?
Try with the command:
sudo a2enmod mod_rewrite