It appearsh that the httpd.conf file can be called something else.
For example, my httpd.conf (Apache2.2, Windows 7) is called something like "httpd-LIVE.conf" and another "httpd-TEST.conf".
Could this cause any issues? Are we free to rename httpd.conf to anything we want as long as extension is .conf?
Thanks
http://httpd.apache.org/docs/2.2/en/configuring.html:
The main configuration file is usually called httpd.conf. The location of this file is set at compile-time, but may be overridden with the -f command line flag.
So no, it seems you can not rename it to just anything, at least not without “telling” the httpd executable about it on either compile time or each start.
Related
I updated my laptop from Mojave to Catalina last night, and this morning I realised that I had lost all my Apache vhosts, my vhost file was replaced with the default file.
I had all my vhosts in /usr/local/etc/httpd/extra/httpd-vhosts.conf
I would like to know which is the right way to do this (store my vhosts), so I (hopefully) won't lost my vhosts in a future update.
Thanks!!
P.D. I'm using "native" Apache, not Homebrew.
Catalina moved the root directory files as part of the upgrade. See https://apple.stackexchange.com/questions/371852/where-does-the-upgrade-to-macos-catalina-move-root-directory-files
From the answer: This took me a long time to figure out, but any file that was formerly at, e.g., /my-cool-directory was moved to /Users/Shared/Relocated Items/Security/my-cool-directory.
You might try checking in your /Users/Shared/Relocated Items/Security folder for your original Apache files.
It depends on what you do include in your httpd.conf file.
You can try use a custom created vhosts file eg. Include /private/etc/apache2/extra/mycustom-httpd-vhosts.conf next time.
After the last catalina update my custom files where not moved out of their places.
I had the same issue with updating to catalina. All my changes were gone.
By default the httpd.conf includes config files in the other directory:
Include /private/etc/apache2/other/*.conf
I place my vhosts and userdir configs in this directory now. It looks like it works just fine. Another custom file I had in there was not touched by the update.
Does anyone know how I can find the httpd.conf file because I may have accidentally changed some things inside and i can't Ctrl+z because I opened it in notepad file instead of notepad++. i would reinstall the whole wampserver but I have tons of data and files to take the risk. I just need the original file of httpd.conf of Apache 2.4.9. I couldn't find it online.
Use a program such as 7-zip to extract all the files from the wamp installer. Go find the httpd.conf file and copy it over. Also you could just install it temporarily on another windows computer to retrieve the file.
It's good practice to always make a backup of conf files before modifying them, they are specific to your release of apache and the environment it's meant to be used in.
I somehow botched the default syntax highlighting and filetype recognition for my apache httpd-vhosts.conf file, such that every time I open it in vim, the syntax and filetype are both set to "conf". All of the other files in the ../conf.d/ directory are recognized properly, i.e. as syntax and filetype both set to "apache". I've tried the following:
manually setting both in vim, i.e.
:set syntax=apache, :set filteype=apache
This works for the session, but they both reset back to "conf" when the file is reopened
Looking for the ~/.vimrc
I don't seem to have one, since I typically edit this file as root
yum remove and reinstall of vim
no change.
I know that there are a lot of posts regarding similar issues with vim syntax and filetype problems, but I cannot figure out how to resolve mine. My guess is that there is a mapping somewhere that says this one particular file should be recognized as a "conf", but that's all I've got. tia.
edit: to clarify, what I would like to know is how this one file got "stuck" on the "conf" syntax and filetype, whereas all of the other .conf files are "apache" syntax and filetype.
I would recommend using a modeline. Put this at the top of your file:
# vim: ft=apache
If you do not have a .vimrc file, you can create one. Keep in mind that each user has a separate .vimrc in their home folder. You can also look for the system default vimrc (without a dot) located in your vim installation folder. To find out where that is, type :echo $VIM in vim.
If you do create a new .vimrc for your user, you can set all .conf files to have apache highlighting as follows:
au BufRead,BufNewFile *.conf set filetype=apache
Is it possible to keep variables in php.ini file. Like that we do with the web.config in .net. I like to keep a flag type variable in the php.ini and use it to different projects.
It's not possible to set user-level variables within a plain php.ini file (or the .htaccess equivilents). There are some PECL modules that do allow that, such as hidef (http://pecl.php.net/package/hidef) - though these would need to be installed on every installation you use.
Including (or pre-including) a file with auto_prepend_file is quite possible - though that would be on every PHP request.
What is frequently done is setting an environment variable as part of the webserver process, which can be read from PHP. In Apache this is quite easy, with the SetEnv module.
SetEnv PRODUCTION_SERVER 1
And accessing it in PHP:
if ($_ENV['PRODUCTION_SERVER']) {...} // or getenv('PRODUCTION_SERVER')
Have you looked at get_cfg_var()?
I needed to do something similar, and this was able to do it for me.
Nope.
You could use the auto_prepend_file directive to automatically include a file that said, although as it uses the include_path, you'd need to specify the full path.
However, it's probably more transparent just to explicitly include/require the relevant file.
One technique that I have found useful for passing a limited number of global variables to a bootstrap script is to take advantage of the SetEnv directive in an .htaccess file. The advantage is that the variable you set will be made available to any script in that directory, plus any scripts in child directories under it.
You could use a SetEnv varibale with the location of a configuration file, such as:
in .htaccess:
SetEnv init_path /home/hendepher/TestApp/init/init.php
In your .php scipt:
<?php
if(!getenv('init_path')) throw new Exception('Must set init_path in .htaccess');
require_once getenv('init_path');
.
.
.
?>
If you have a test directory that requires different initialization o global variables, simply add another .htaccess file in your test directory:
SetEnv init_path /home/hendepher/TestApp/init/testing_init.php
Doing it this way, as opposed to using the 'auto_prepend_file' directive, is that your global configuration script is not run by all the php applications on your server: some may not need it.
The accepted answere also worked for me, with one change.
I didn't test this on earlier versions, but in my environment (php 5.4.22) this doesn't show up in $_ENV, but rather in $_SERVER.
In my .htacess file:
SetEnv PRODUCTION_SERVER 0.
My php code:
$production="PRODUCTION";
if (!isset($_SERVER['PRODUCTION_SERVER']) || $_SERVER['PRODUCTION_SERVER'] != 1){
$production="DEVELOPMENT";
}
I don't think that's a good place to store variables. php.ini is for storing configuration for PHP itself not your applications. You should consider putting the shared variables into a .inc file and including that instead.
Have you considered hidef?
Allow definition of user defined constants in simple ini files,
which are then processed like internal constants, without any
of the usual performance penalties.
Complementing #Ascherer answer, use get_cfg_var() to save custom variables in custom php.ini (variable created by you, not an official PHP ini directive). For example:
In php.ini: custom_variable = "abcde"
In any php script: get_cfg_var('custom_variable') returns abcde
I use this in in a small project in local dev. As I run the local server via php -S localhost:8000 -c php.ini (not running an Apache server locally), it's a good option to call some configuration constants. In production, these constants are set in .htaccess.
I have a feeling that Apache is using a different php.ini file that the one I am editing. I make a change in my php.ini file, restart Apache, and the change doesn't take affect. So I don't know what to do anymore.
Any ideas?
Update: Found out it's using the right php.ini file...but I still don't know what to do!
To find the file that's being run by PHP, create a phpinfo file (just <?php phpinfo();?>) and look for the 'Configuration File (php.ini) Path' directive.
from the command line, run
php -i |grep "php.ini"
This will describe the location php is loading its ini file from. You can reconfigure the php.ini location by recompiling php.
The output from phpinfo() will contain this. When using PHP as an Apache module, it can be configured using PHPIniDir in httpd.conf (or similar).
To get the php.ini file which is being used by Apache you will probably have to add phpinfo() into a .php file and open it in the browser. As php -r "phpinfo();" | grep php.ini will outout the same as php --ini would. Which php.ini is used for the CLI.
Question for you, what platform are you running on unix or windows?
If it is unix based, check if your php.ini is residing in the same directory as /etc/httpd. Again, installation of apache can vary so check...or issue the command "find / -name php.ini -print" (without quotes) to see which one is it you are using
Ok. Since you said you have found the correct php.ini, sounds like something is missing when you edited the php.ini and reloaded apache. Look in the log directory /var/log/httpd for error_log and check to see if there was errors...that would be a start!