How do I find my httpd.conf file? - apache

*Edit: Anyone who's using MAMP PRO on a Mac running Mac OS X Lion may find it helpful to know that I finally tracked down my httpd.conf file in my personal library at Application Support > appsolute > MAMP PRO > httpd.conf. The reason I couldn't find it with a normal search is that it's a hidden directory. To access it, open Finder, Choose Go > Go To Folder, then type in ~/Library After tracking it down, you may then discover that it's almost impossible to edit your httpd.conf file. ); *
This is a weird one. I'm using MAMP on a Mac and want to modify my httpd.conf file so it defaults my URL's to lower case. So I navigated to Applications > MAMP > conf > apache > httpd.conf and added this line of code:
RewriteMap tolower int:tolower
I then modified one of my .htaccess files accordingly, but nothing happened. (Yes, I restarted my servers.)
I then reopened my httpd.conf file and added this code, which I understand is supposed to display "verbose" messages in my log file:
LogLevel trace8
I then opened my log file # Application > MAMP > logs > apache_error.log. There's code associated with the web pages I most recently visited, but they're just generic messages - not "verbose" messages.
Someone who understands Apache far better than me told me this indicates that the httpd.conf file I modified isn't being used by my server or sites. In other words, there must be another httpd.conf file out there somewhere.
Sure enough, I typed httpd.conf into Apple's finder and found half a dozens files with that name. I don't know where they came from; I recently tried to install Drupal and Aqquia, so that might be where some of them originated.
Anyway, I added the code (including LogLevel trace8) to EVERY httpd.conf file, restarted my servers, and I STILL don't see any changes on my websites, and I still just see generic code in my log file.
I'm completely snowed. It looks like the httpd.conf file in my MAMP folder is out of the loop, yet the Apache log file in the same folder is being used...or can errors be written to more than one Apache log file at the same time?
If I rename the httpd.conf file in my MAMP folder and restart my servers, my sites display fine, further suggesting that this httpd.conf is outside the flow. Yet if I rename a file that sits beside it named mime.types, my web pages don't display.
Anyway, does anyone have any idea how I can figure out what's going on?
If not, then can you advise me on Plan B? If I can't find my httpd.conf file, then I'll have to abandon ship and just do it online. I've found the path to my online httpd.conf file. I don't know how to open online files, but I assume I can copy it to my computer with an ftp program, open it and modify it, then publish it online.
So here are my questions: Am I correct in understanding that I can safely add the code RewriteMap tolower int:tolower to my online httpd.conf file without affecting any of my websites UNTIL I also modify a .htaccess file(s)? And if I modify my online config file, do i have to restart the server, just as I do on my computer?
Thanks.

First, use the ps command to find the full path to the running Apache process:
$ ps ax | grep httpd
28 ?? Ss 3:01.99 /usr/sbin/httpd -D FOREGROUND
On this system, Apache is /usr/sbin/httpd.
Second, run that binary with the -V option to show its configuration. This should include the path to the config file.
$ /usr/sbin/httpd -V
...
Server compiled with....
..
-D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"
On this system, the running copy of Apache reads its config from /private/etc/apache2/httpd.conf.

Related

WAMP virtual host displays in Chrome, but Internet Explorer says "Page can't be displayed"

I installed WAMP and followed this guide to set up virtual hosts. In both Google Chrome and Internet Explorer, http://localhost gets me to "WAMPSERVER homepage" with my virtual host listed under "Your Projects."
Clicking that link to http://mysite.local in Chome brings me to my site as expected.
Clicking that link in Internet Explorer displays the following message instead.
This page can’t be displayed
•Make sure the web address http://mysite.local is correct.
•Look for the page with your search engine.
•Refresh the page in a few minutes.
Since I can see the WAMPSERVER homepage as expected in both browsers, I don't think there's a problem with my WAMP installation. Since my virtual host is working in Chrome, I think it must be configured properly in Apache and in my Windows hosts file.
I just don't understand why Internet Explorer isn't working with my virtual host like I expect it to, and the "Page can't be displayed" message doesn't give me anything helpful to work with.
Does anyone have any suggestions for me? I'd greatly appreciate any pointers or links to other guides I can try. Thanks in advance for any replies!
There's several reasons WAMP/MAMP may not work on a local environment, I'll try to list a few reasons here:
Which httpd.conf?
There are sometimes multiple httpd.conf files that can cause things to go a little bit funny. MAMP/WAMP usually tend to keep all their configuration files within a conf/ directory however, that doesn't mean to say some other httpd.conf file is being used...
You can also run this command on Linux based systems to see which one is being used:
apache2ctl -V | grep SERVER_CONFIG_FILE
vhosts definitions not included in httpd.conf
In the httpd.conf file, there's a line to include the vhosts definitions file, it should be uncommented:
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf // remove the #
Incorrect vhosts definitions
Vhosts need to be defined as follows:
<VirtualHost *>
DocumentRoot "C:/path/to/your/local/site"
ServerName mydomain.local
</VirtualHost>
Hosts file
On OS X/Linux systems this can be found at etc/hosts. Edit that to reflect below (note, you'll need to be root)
127.0.0.1 mysite.local
On windows systems, it can be found in %SystemRoot%\System32\drivers\etc\hosts.
Browser caches
Browser caches always cause an issue with local servers/development. It's worth working with incognito mode on, or deleting all browser caches each and every time you open it up. There's a few plugins available for most browsers that should help too.
Other points to note
Whenever you edit anything to do with httpd.conf, vhosts, hosts file - WAMP/MAMP/Apache needs to be restarted. It's a good idea to shut the server down before doing the changes.
You mentioned that there was a hardcoded link in one/some of your files. It's generally regarded as bad practise to do that for this exact reason. Your code is less portable and can 'break' on other systems. I'd suggest using PHP's __FILE__ or similar to achieve what you want.
Alternatively you could set up local configuration files for your app that are only included when they're present. Have a look at this for a good example of such a set up.
Log everything. Check the logs regularly too.

Difference between httpd.conf, php.ini and .htaccess

I am about to start learning Apache. All resources I am looking into, mention either php.ini, or .htaccess or httpd.conf files for setting configurations and stuff. But none of them are clear on the difference between these 3 files. Can anyone explain the difference and their usage?
httpd.conf (it can actually be named differently on some platforms, but that's the default) is the master configuration file for Apache. You can use Include statements to pull in external configuration files. httpd.conf is read in when Apache starts or if you run a 'reload'.
.htaccss is a per-directory configuration file for Apache. You can enable or disable the use of .htaccess files in your httpd.conf file. Where possible its been recommended to me to turn .htaccess use off, as Apache will check the file every time a request causes it to read the directory.
PHP is, as you probably know, separate from Apache, although often used with it. php.ini is the configuration file for the PHP engine.
Every daemon or application has it's own configuration files. On linux these are often located in the /etc directory. You will have to learn to edit each one according to the program. the /etc/php5/php.ini is different from the /etc/apache2/httpd.conf and so on.
Think of them like different types of files. a Word document is not the same as a JPEG Image or a AVI video.
The PHP.ini controls PHP's settings
The .htaccess controls apache settings for a given folder (and all child folders)
The httpd.conf controls apache's settings.
php.ini is a configuration file where you specify options for things
related specifically to php, for instance CURL
.htaccess is where you specify options for URI routing and folders
options on your server
httpd.conf is a configuration file where you specify options for
things related specifically to apache

Apache 2.2 on XP: How configuration files are managed? Where should they be located?

New to Apache, and suffering...
Seems to be true:
the default configuration is in Apache directory Apache2.2/conf/httpd.conf
Unsure of that:
it can be elsewhere
to create some separation between test/production, it seems that the best option is
to store all test files, including configuration and logs, in the same directory, with subdirectories conf, log, htdocs, and all production files in another directory using a similar structure.
if my upper directory is d:mywww, then the server needs to be started with the associated configuration file, e.g. httpd -f "d:mywww/conf/httpd.conf"
What will happen to the default configuration file if the -f option is used. Will it be ignored?
If instead of the -f option, you use httpd -d "d:mywww/htdocs" to indicate the directory to serve, but not any configuration file, will the default config file be used and the one under d:mywww/conf ignored?
Can someone confirm or deny?
Is there a well known site with a good introduction on setting up Apache, if possible on Windows. I found the Apache documentation a little bit difficult, and Apache Definitive Guide not clear about this kind of questions.
I was new to Apache 2 months ago, and still suffering. Since you got no replies from pros yet, I'll chip in my 2 cents: (all for Ubuntu 10.10)
httpd.conf is used for your personal configurations, so I'd say that it is not the default configuration file as you specify. The default would be, in my case at least, in /etc/apache2/apache2.conf
you can have a bunch of other conf files. In my case, I can place any file with an extension .conf inside /etc/apache2/conf.d/ and it will be picked up by Apache on restart.
Don't know about the rest. Hope it helps you

Difference between ServerRoot, DocumentRoot, and Directory

While playing with Apache, I messed up the paths without making a backup httpd.config file.
The file is located at C:\xampp\apache\conf\httpd.config
I want to keep my web project on the D: drive as a virtual folder. This is the current non-working state. How can I fix this or revert to the xampp defaults?
ServerRoot "C:\xampp\apache"
DocumentRoot "D:\workspace"
<Directory "D:\workspace\AutionWebSite">
ServerRoot = path to the webserver executable/dir
DocumentRoot = path to your files that are delivered by the server
The <Directory> directive is used to configure settings for a specific directory. However, the <Directory> command in your question is not complete.
The default values for DocumentRoot and Directory for XAMPP is "C:\xampp\htdocs"
I would say that the most easiest way for you would be to check your xampp version, make a back up of your document root, which is probably "www" or "htdocs", your configuration files and eventually dump your database. Now install the same version of xammp again and there it is.
And at least the first rule is by playing with "config files", make backups before. The second rule is, make a backup of the whole configuration directory anyway, just for the case. And the last one is, if you are a xammp user, means you are a windows user, so you probably don't have unixoid server administration knowledges, so there is a long way for you to starting to "play" with the apache server.
The only think that you should know is, that you need to set the direction "AllowOverride All", which is necessary, if you use some content management system or other systems, which brings there own .htaccess file. So long you work on windows with xammp and not on a linux or other unixoid operating systems, you cannot understand the complete world of web servers like apache or database servers like postgresql and the sensibility of configuration files.
I understand the necessity of it for understanding of whole web applications respect. to be an full stack web programmer, but before that, i wouldn't change in the future the default server configurations, just check the row "AllowOverride All". Hope this will help your.
Server Root "/Local"
-specifies the default directory hierarchy for the Apache installation.
Document Root"/Local/WWW/apache22/data"
- the directory out of which you will serve your documents.

Where does PHP store the error log? (PHP 5, Apache, FastCGI, and cPanel)

I am on shared hosting and have cPanel, Apache, and PHP is run by FastCGI. Where does PHP store the error log?
Is there another way I can find the error log on a shared hosting environment instead of having to go through entire site structure to look for error_log files?
I have access to the php.ini file (I am using PHP version 5.2.16).
PHP stores error logs in /var/log/apache2 if PHP is an apache2 module.
Shared hosts are often storing log files in your root directory /log subfolder.
But...if you have access to a php.ini file you can do this:
error_log = /var/log/php-scripts.log
According to rinogo's comment: If you're using cPanel, the master log file you're probably looking for is stored (by default) at
/usr/local/apache/logs/error_log
If all else fails you can check the location of the log file using
<?php phpinfo(); ?>
Try phpinfo() and check for "error_log"
Linux
php --info | grep error
The terminal will output the error log location.
Windows
php --info | findstr /r /c:"error_log"
The command prompt will output the error log location.
To set the log location
Open your php.ini and add the following line:
error_log = /log/myCustomLog.log
Thanks chelmertz and Boom for these (comments on the question).
On a LAMP environment the PHP errors are be default directed to this below file.
/var/log/httpd/error_log
All access logs come under:
/var/log/httpd/access_log
How to find your PHP error log on Linux:
sudo updatedb
[sudo] password for eric:
sudo locate error_log
/var/log/httpd/error_log
Another equivalent way:
sudo find / -name "error_log" 2>/dev/null
/var/log/httpd/error_log
It can also be /var/log/apache2/error.log if you are in Google Compute Engine.
And you can view the tail like this:
tail -f /var/log/apache2/error.log
It appears that, by default, PHP does not log errors anywhere. The error_log key in php.ini is commented out in all the installs I've seen.
Generally I:
look for php.ini files. locate php.ini.
Search these files for the error_reporting value;
Which should be set to whatever amalgamation of PHP log levels are enough for you.,
For example: E_ALL & ~E_DEPRECATED & ~E_STRICT
Check the error_log value to make sure it points to an actual place and is not commented out.
The default value doesn't give a full path, only a file name, I don't know where this path resolves to normally. Probably /var/log/.
You should use absolute path when setting error_log variable in your php.ini file, otherwise, error logs will be stored according to your relative path.
error_log = /var/log/php.errors
Other solution would be writing simple script which would list all error logs files from directory tree.
php --info | grep error
This is helpful.
NGINX usually stores it in /var/log/nginx/error.log or access.log (on Ubuntu in any case).
The best way is to look in your httpd.conf file and see what the default is. It could also be overridden by your specific virtual host. I start by looking at /etc/httpd/conf/httpd.conf or /etc/apache2/httpd.conf and search for error_log. It could be listed as either /var/log/httpd/error_log or /var/log/apache2/error_log, but it might also be listed as simply logs/error_log.
In this case it is a relative path, which means it will be under /etc/httpd/logs/error_log. If you still can't find it, check the bottom of your httpd.conf file and see where your virtual hosts are included. It might be in /etc/httpd/conf.d/ <- as "other" or "extra". Your virtual host could override it then with ErrorLog "/path/to/error_log".
If you have build Apache and PHP from source, then the error logs by default is generated at your ${Apache install dir}/logs/error_log, i.e., generally /usr/local/apache2/logs/error_log.
Else, if you have installed it from the repository, you will find it at /var/log/apache2/error_log.
You can set the path in your php.ini also and verify it by invoking phpinfo().
Wherever you want it to, if you set it in your function call:
error_log($errorMessageforLog . "\n", 4, 'somePath/SomeFileName.som');
If you use the php5-fpm log default, it should be under:
/var/log/php5-fpm.log
Search the httpd.conf file for ErrorLog by running cat <file location> | grep ErrorLog on the command line. For example:
cat /etc/apache2/httpd.conf | grep ErrorLog
Output:
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
ErrorLog "/private/var/log/apache2/error_log"
Find the line that starts with ErrorLog and there's your answer.
Note: For virtual hosts, you can edit the virtual hosts file httpd-vhosts.conf to specify a different log file location.
cPanel Error logs are located in:
/usr/local/cpanel/logs/
/usr/local/apache/logs/
By default Apache logs are located inside:
/var/log/apache
or
/var/log/apache2
If anyone is using a custom log location then you can check it by running this command:
cat /etc/apache2/**conf**/httpd.conf | grep ErrorLog
If you are getting an error that the apache2 directory does not exist then you can run this command to find correct location by:
whereis apache
or
whereis apache2
When configuring your error log file in php.ini, you can use an absolute path or a relative path. A relative path will be resolved based on the location of the generating script, and you'll get a log file in each directory you have scripts in. If you want all your error messages to go to the same file, use an absolute path to the file.
See more in Error Handling Functions.
something like this :
sudo locate error.log | xargs -IX grep -iH "errorlog" X
or
sudo locate error_log | xargs -IX grep -iH "errorlog" X
or
sudo find / -iname "error?log" 2>/dev/null | xargs -IX grep -iH "errorlog" X
I can guarantee you, I am not the only person who has been driven to madness at least once in a frustrating search for a log file. It seems like it should be the easiest thing to find in the whole system.
A definitive guide on where the PHP error log is stored would be a complicated bit of work. The official PHP manual does not even try to address the whole topic, because there are dependencies on systems outside PHP, such as the operating system (Linux vs. Windows, which distribution of Linux), including settings within Windows and Linux that affect the name and location of the PHP error log.
Until someone takes the time to write a complete, cross-system guide, the best you are going to get is general directions where you can inquire. Every PHP developer has had to endure agony in this pursuit, with one exception. If you work in one place and the information is provided when you first need it, then you have the information need forever, that is, until you find yourself in a new working environment. There are such fortunate people.
If the information is not given to you on a silver platter, so to speak, you have some hunting to do. The hunt is not the longest you will face in your career, but it is not the simplest either.
As is evident from the many answers already posted, a smart place to begin is the output of phpinfo(). To view it, create a PHP file containing this:
<?php
phpinfo();
Either browse to that file or run it from the command line. If you do both, you likely will find the error_log is in different places, depending on command line vs. web server use of PHP. That is because the PHP interpreter that runs on a web server is not the same PHP interpreter that runs from the command line, even when the command line is on the same machine as the web server. The answers already posted in here mostly are making an unstated assumption that PHP is running as part of a web server.
The default for error_log is no value
Whatever the value is, it comes from the php.ini files used to configure PHP. There can be many php.ini files. Finding your way among them is confusing at first, but you do not need to deal with this to find your PHP log.
If the output from phpinfo() shows a full path to a file, that is where the log is. You are lucky.
The trick is there usually is not a full path indicated in phpinfo(). When there is not a full path, the location depends on:
Whether error_log is no value. If it is, the log file location will depend on the operating system and the mode PHP is running. If PHP is running as an Apache module, on Linux the log often is in /var/log/apache2/error.log. Another likely spot is in a logs directory in your account home directory, ~/logs/error.log.
If there is a file name without a path, the location depends on whether the file name has the value syslog. If it syslog, then the PHP error log is injected into the syslog for the server, which varies by Linux distribution. A common location is /var/log/syslog, but it can be anywhere. Even the name of the syslog varies by distribution.
If the name without a path is not syslog, a frequent home for the file is is the document root of the website (a.k.a., website home directory, not to be confused with the home directory for your account).
This cheat sheet has been helpful in some situations, but I regret to have to admit it is not nearly universal. You have my condolences.
For CentOS 8 it is var/log/httpd/error_log.
You are on a shared environment and cannot find error log. Always check if cPanel has option Errors in your cPanel dashboard. If you are not being able to find the error log, then you can find it there.
In the cPanel search bar, search Error, it will show Error Pages which are basically lists of different HTTP error pages and other Error is where the error logs are displayed.
Other places to look in a shared environment:
/home/yourusername/logs
/home/yourusername/public_html/error_log
You can go in File Manager and check the logs folder.
Check the log file in a public_html folder.
Check "php phpinfo()" file for where the log is stored.
Mine for some reason stored it in:
/var/log/php-errors.log
I'm using Ubuntu Server 16.04 (Xenial Xerus) and PHP 7.1.28.
WordPress
WordPress will direct error_log() messages to /wp-content/debug.log when WP_DEBUG_LOG is set to true.
See WordPress documentation for WP_DEBUG_LOG
For PHP-FPM, just search the configuration file for error_log:
cat /etc/php-fpm.d/www.conf | grep error_log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
In a shared cPanel environment you cannot find the error log, if your hosting provider doesn’t provide any option in the cPanel dashboard. You can search "error" and see if your provider have any.
Otherwise normally you will find a file called "error_log" in your public_html file, which have all the PHP error recorded.
You can see the php errors for an account under:
/home/username/logs/domain_tld.php.error.log
You can set php error log globally and locally.
Globally through WHM:
WHM -->> MultiPHP INI Editor --> "Editor Mode"
Select the version of PHP you would like to set the error log
Edit the parameter error_log.
error_log = "/some/path"
Change the filename to the desired error log file
Save changes
Locally though cPanel:
CPanel -->> MultiPHP INI Editor --> "Editor Mode"
Select the version of PHP you would like to set the error log
Edit the parameter error_log.
error_log = "/some/path"
Change the filename to the desired error log file
Home directory will set the option for all domains, addons, and subdomains configured on the account
A specific domain will limit the change to that domain, or, in the case of an addon domain, the addon and the matching subdomain
Save changes
If PHP-fpm is enabled:
WHM --> MultiPHP Manager
Find the domain you'd like to change the error log location for
Click "Edit PHP-FPM"
Change the log location in "The error log file (error_log)" relative to the folder "logs" within the user's home directory
Save changes