Apache (httpd) Wont start because "could not open error log" - apache

ok guys, im stumped. I install centos 7.2 on a vm, installed httpd, enabled it as a service, then started it
then created and edited a config file as follows
<VirtualHost *:80>
ServerAdmin admin#mydomain.com
ServerName www.mydomain.com
ServerAlias mydomain.com
DocumentRoot /var/www/mydomain.com/public_html
#ErrorLog /var/www/mydomain.com/error.log
#CustomLog /var/www/mydomain.com/requests.log combined
</VirtualHost>
So.. When I uncomment the "ErrorLog", which I believe is correct, and there is a file called error.log in directory "/var/www/mydomain.com/"
Httpd.service doesn't want to start, with the error:
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/mydomain.com/error.log.
AH00015: Unable to open logs
I tried doing chown on the error.log file, to apache:apache, and root:root, and the user for the site, but that didn't work.
I also made sure to 755 the directory for www, so the error.log file should be able to be opened by that. Help me out please

Turns out that the error and access logs needed to be placed in /var/log/httpd/ instead of where they were.

All the directories in the path leading up to the error.log must have the executable and readable bit set for the apache user or group, in order for apache to be able to write to the log file.
In order to debug the permissions, you could su to the apache user, and try touching the file:
sudo -u apache touch /var/www/mydomain.com/error.log

Related

How to suexec public_html/cgi-bin without the "~user/" in url

Apache 2.4.29 (Fedora)
Perl v5.26.1
I have a website which is run, for several reasons, out of the public_html directory of the user "jaf". Apache is set up to run cgi scripts in this directory tree as the local user ("jaf"). So, for instance "http://billyard.ca/~jaf/cgi-bin/simpletest.cgi" successfully executes as user "jaf" (rather than the default "apache"). What I am trying to achieve, unsuccessfully so far, is the following:
To get apache to run all cgi called by "http://billyard.ca/cgi-bin/" as if they were called by "http://billyard.ca/~jaf/cgi-bin/" (i.e., omit the "~jaf/") yet still operate within the "~jaf/public_html" directory as user "jaf" rather than "apache". I've added the following to the apache configuration:
<VirtualHost *:80>
Servername billyard.ca
SuexecUserGroup jaf jaf
DocumentRoot "/home/jaf/public_html"
ScriptAlias /cgi-bin/ /home/jaf/public_html/cgi-bin/
</VirtualHost>
This works "billyard.ca/~jaf/cgi-bin/simpletest.cgi".
This fails "billyard.ca/cgi-bin/simpletest.cgi"; it gives me a 500 internal server error and suexec reports "command not in docroot".
To get selinux to allow this (right now I have to go into permissive mode otherwise I get apache "premature end of header" error messages)

VHost Not Working using AWS AMI httpd

I'm currently creating an application using AWS AMI, and it comes w/ an httpd 2.4.10. Here was the steps I followed on creating the vhost
sudo mkdir /etc/httpd/sites-available
sudo mkdir /etc/httpd/sites-enabled
edited /etc/httpd/conf/httpd.conf to have IncludeOptional sites-enabled/*.conf
created realtydig.conf inside /etc/httpd/sites-available
symlinked it to /etc/httpd/sites-enabled
sudo apachectl restart
sudo service httpd restart
*still the default httpd page is the one showing, vhost not pointing to domain
here's the vhost
xml
<VirtualHost *:80>
ServerName beta.realtydig.com
DocumentRoot /var/www/realtydig/laravel
<Directory "var/www/realtydig/laravel/public">
AllowOverride all
</Directory>
</VirtualHost>
I would like to understand, what happened wrong. It seems to be loading up since error occured w/ some of my previous typos when i was trying to restart the application.
If "nothing happened" then I assume that you see just white empty page in browser. Usually some other vhost will be see if current vhost is not activated.
DocumentRoot must be pointing to the public folder like this
DocumentRoot /var/www/realtydig/laravel/public
You can debug by creating test.html inside the DocumentRoot and try to access it from the browser.

Wamp server can't start (orange icon)

I can't start wamp server on win7. I'm using vhosts, everything was fine untill I restart wamp server.
httpd-vhost.conf:
<VirtualHost *:80>
ServerAdmin *.*#*.com
DocumentRoot "C:\Users\Rossko\Documents\PHP\wamp\www\***.local"
ServerName ***.local
ErrorLog "C:\Users\Rossko\Documents\PHP\wamp\apache\apache2.4.9\logs\***.local-error.log"
CustomLog "C:\Users\Rossko\Documents\PHP\wamp\apache\apache2.4.9\logs\***.local-access.log" common
in Apache error log is nothing and port 80 is empty. Why is still orange and failed to start? Any idea? I have more virtual hosts in httpd-vhost.conf than projects in www/ folder (not enough time for copy) Is it possible that the error is coused by this?
First, if Apache fails to start, look at the Windows Event Log under
Event Viewer -> Windows Logs -> Application
And then look for Errors report from a Source of Apache
If Apache fails before it can open its error log, errors are written to the Event log.
Second a good way to test your http.conf file and any files that are included within httpd.conf is to do this :-
Launch a command window (Dos Box)
C:
CD \Users\Rossko\Documents\PHP\wamp\apache\apache2.4.9\bin
httpd -t
This should validate the httpd.conf file and all included files, if there are errors they will be reported with a filename and a line number.
Fix the error and then try the httpd -t command again until it responds with an OK message.
If you have defined more Virtual Hosts than you have actually created DocumetRoot folders for, it should just report a cannot find file type message in the Apache error log on startup. It should not actually stop Apache from starting.

“Warning: DocumentRoot [/var/www/vhosts] does not exist” although I've created /var/www/vhosts?

I've installed apache and config my virtual host on my CentOS 6.4.
But when i restart apache ( using this command : sudo service httpd restart ) it's warning me that "Warning: DocumentRoot [/var/www/vhosts] does not exist". I've check the directory /var/www/vhosts, it already created and permission is 0777. What wrong i did? any help please...
-> this is my virtual hosts configuration.
DocumentRoot /var/www/vhosts
ServerName trien.cba
ServerAlias trien.cba
ErrorLog /var/log/httpd/trien.cba.error.log
CustomLog /var/log/httpd/trien.cba.access.log common
AllowOverride All
Order allow,deny
Allow from all
Options -Indexes
....
-> and this is the warning:
[root#test-cba ~]#sudo service httpd restart
Stopping httpd: [ OK ]
Starting httpd: Warning: DocumentRoot [/var/www/vhosts] does not exist
Warning: DocumentRoot [/var/www/vhosts] does not exist
I think you are probably running with SELinux enabled. This requires additional steps to make resources accessible (which is good for security).
These questions have guidelines on how to enable your DocumentRoot:
https://serverfault.com/questions/293866/apache-says-documentroot-doesnt-exist-when-it-does
https://serverfault.com/questions/323511/selinux-on-rhel6-httpd-config-documentroot-path-does-exist-does-not-exist
If you don't want to work with SELinux, you can disable it by setting SELINUX=disabled in /etc/selinux/config. The following links might help if you want to learn more.
http://wiki.centos.org/HowTos/SELinux
http://fedoraproject.org/wiki/SELinux
Try moving your vhosts folder inside the html folder and change the SELinux security context by running
chcon -R --reference=/var/www/html /var/www/html/vhosts

Problems configuring VirtualHost in Apache2 on Ubuntu 12.04

After reading through various tutorials [1] I still can't get my VirtualHost settings to work as desired. I'm getting a 403 Forbidden when I try to use a VirtualHost with a directory below my user directory as its DocumentRoot.
What I've done so far
Created file /etc/apache2/sites-available/workspace with following content:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName project-site
DocumentRoot /home/user/Workspace/project/site
</VirtualHost>
Edited file /etc/hosts now yielding:
127.0.0.1 localhost
127.0.1.1 my-machine
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
# VirtualHosts added by me
127.0.0.1 project-site
Enabled virtual hosts using sudo a2ensite workspace
Restarted Apache using sudo services apache2 restart
Tried opening http://project-site and http://project-site/test.html (where test.html is present in /home/user/Workspace/project/site/) in my webbrowser
What happens
Restarting Apache I get the following messages on the command line:
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Sun May 13 10:33:37 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
[ OK ]
Opening either http://project-site or http://project-site/test.html a "403 Forbidden" is served.
What should happen
I'd like to have the contents of /home/user/Workspace/project/site being served when I browse to http://project-site.
What I learned so far
From reading similar questions on this site I learned that this is probably a permission problem [2]. Files in /home/user/Workspace/project/site might not be readable by www-data. But how do I know or correct this?
Furthermore .htaccess files were mentioned [3] being located in
/home/.htaccess
/home/user/.htacces
[...]
/home/user/path/to/project/.htaccess
and possibly not readable. I never created them, I don't want them, will I need them?
The second answer to another question [4] made me use NameVirtualHost responsible for the warning on restart of Apache. Is it necessary and if, how do I use it properly?
Any help is much appreciated! Tell me, if you need to know anything else to locate the problem.
Ressources
http://www.thegeekstuff.com/2011/07/apache-virtual-host/, http://httpd.apache.org/docs/2.2/vhosts/name-based.html, http://mintarticles.com/read/software-articles/multiple-virtual-hosts-in-xampplampp-in-ubuntu,977/, http://www.pgorecki.pl/content/virtual-host-na-localho%C5%9Bcie-apache-ubuntu, ...
Apache VirtualHost 403 Forbidden
Ubuntu, Apache, virtualhost and Access forbidden
VirtualHost configuration
I found the following solution, not satisfying me, but solving my primary problem. Indeed it is about permissions like suggested in [1]. My /home/user directory was not accessible to the webserver. In order to grant minimal possible permissions I used
chmod 701 /home/user
to make it accessible. Additionally I recursively gave group ownership to www-data for the webroot of the virtual host like recommended in [2], but I'm not sure, whether this is necessary.
sudo chown -R user:www-data /home/user/Workspace/project/site
sudo chmod -R g+s /home/user/Workspace/project/site
I'm going to ask for a more elegant solution in a separate question.
Regarding the other problems mentioned, I found out the following with the help of [3] besides other resources:
It is not necessary and may cause an error to have NameVirtualHost *:80 in the virtual hosts description, if it appears in one of apaches other configuration files.
To let apache know about its fully qualified domain name being localhost one creates a file /etc/apache2/conf.d/fqdn with content ServerName localhost.
https://stackoverflow.com/a/7576526/948404
https://stackoverflow.com/a/9133067/948404
https://help.ubuntu.com/community/ApacheMySQLPHP