I am a complete newb to Apache Servers. So far, I understand that Apache configuration is made in httpd.conf but there is one environment variable called SetEnv that has been bugging me. In one demo code I am looking at, there is
SetEnv APPLICATION_ENV "development"
and in another folder, I can see a "development" folder with other php files in it with database configurations. So, I am kind of not very clear as to the use of SetEnv. Does it point to files that will show DB configs?
SetEnv sets an internal environment variable in apache that you can use in apache modules or pass to CGI scripts.
Syntax is :- SetEnv variable value
So in SetEnv APPLICATION_ENV "development" you can use APPLICATION_ENV as a variable and apache will use it's value="development" instead.
Related
My perl code has a error on the first line #!/usr/bin/perl when deploying on linux server. But it work properly in my local b/c I used this line #!C:\xampp\perl\bin\perl.exe.
Can somebody tell me the reason?
Ah I have solved this problem by enable mod cgi in my web server. In my case I use apache2 so I added some configs like:
Explicitly using Options to permit CGI execution
You could explicitly use the Options directive, inside your main server configuration file, to specify that CGI execution was permitted in a particular directory:
<Directory "/var/www/mypro">
Options ExecCGI
</Directory>
The above directive tells Apache to permit the execution of CGI files. You will also need to tell the server what files are CGI files. The following AddHandler directive tells the server to treat all files with the cgi or pl extension as CGI programs:
AddHandler cgi-script .cgi .pl
After that load cgi module:
a2enmod cgi
Restart my apache server. It worked!
If you use another web server like nginx you can find some way to enable cgi in your config file.
I want to disable the parsing of PHP files in a specific directory, and found out how to do that here. The problem is that my server uses PHP-FPM, and I get Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration when I try to use php_flag in my httpd.conf file.
How can I disable parsing of PHP files in a given web-accessible directory with an htaccess/httpd.conf file that is located above web root on a server using PHP-FPM?
Since Fedora 27 switched to php-fpm recently, I, too, ran into this problem. Unfortunately, the old ways of doing things with mod_php do not apply to php-fpm.
I did find another question here that definitely seemed more relevant:
Apache: Disable php in a directory
The gist of it was was to use a <directory> and <filesmatch> block in your config file, and use SetHandler ! for every directory you didn't want PHP code interpreted.
e.g.:
<Directory "/path/to/no/phpfiles">
<Files "*.*">
SetHandler !
</Files>
</Directory>
This is tested and working on Fedora 27, PHP-FPM 7.1.12.
Unlike using the fpm configs directly, this technique works recursively, so placing it at the top level of a tree of stuff you don't want PHP interpreting works as expected.
I disable .htaccess files in my configurations, but this technique should still work. However, <directory> is not valid inside a .htaccess file. Hopefully just removing it, and leaving:
<Files "*.*">
SetHandler !
</Files>
Should be sufficient.
How can I disable parsing of PHP files in a given web-accessible
directory with an htaccess/httpd.conf file that is located above web
root on a server using PHP-FPM?
You can't persay the way you're trying it without mod_php (which you don't want) which is why you're getting that error. PHP-FPM is not an Apache module. It runs independent of Apache. That's actually it's purpose to be used on heavily loaded sites and it can control all the PHP processes.
One way you might be able to achieve this is to specify the exact path you want to run PHP, in your virtualhost file with the Directory directive. Instead of just having the PHP handler stuff, enclose it with the Directory directive with the actual path you want it to run. Here is an example.
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html/
ErrorLog /var/www/example.com/error.log
CustomLog /var/www/example.com/access.log combined
<Directory /path/to/php/only/folder/>
#then you PHP handler stuff
<IfModule mod_fastcgi.c>
AddType application/x-httpd-fastphp5 .php
Action application/x-httpd-fastphp5 /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi_example.com
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi_example.com -socket /var/run/php5-fpm_example.com.sock -pass-header Authorization
</IfModule>
</Directory>
</VirtualHost>
Then restart Apache. This should limit it to that directory. You might have to remove the php handler info from the other config so it's not overwritten.
Note I have not tested this solution.
There is a .htpasswd file in a code base I am working on. The corresponding path to in .htaccess is correct in the production environment but the path does not suit my local environment since the server path is different.
Production: AuthUserFile /var/www/sites/some_dir/.htpasswd
Local Dev: AuthUserFile /path/to/htdocs/some_dir/.htpasswd
Is there a way to make the path to .htpasswd variable, or, if you understand what I am trying to do is there some other way to accomplish this? Thank you in advance.
We realize that over the Vhost config
dev.domain uses our dev htacces file AuthUserFile /usr/local/www/default.htaccess
For security reasen we generate separate file. Sure you can use the system login for access but we think you open there a door which you can't get safe.
prodution domain uses an other htaccess file
You can generate/update the user in the htaccess by the command
htpasswd passwdfile username
In our case we type
htpasswd /usr/local/www/default.htaccess myusername
In the vhost we only set the passwdfile parameter
AuthUserFile /usr/local/www/default.htaccess
We hope we could help you
Similar to Domain specific htpasswd conditions.
Look at the IfDefine directive for Apache. It lets you define a variable on your production and/or development platform with which you can filter your apache commants. See this link for an example: http://cweiske.de/tagebuch/relative-htpasswd-path.htm.
I have a mod_perl2 module that writes some files to the working directory. The standard working directory of mod_perl2 or Apache2 seems to be "/". Of course, Apache is not allowed to write files in this directory.
Can anyone tell me how I can change the working directory or the directory mod_perl2 writes to?
I use Apache2 Prefork on SLES 10.
Can you do a perl chdir(script-dir) at the beginning of the script ?
On a second thought that would defeat the purpose when you try to use in threaded scenario where changing the working directory might break the threads.
You could try RegistryPrefork module ?
# httpd.conf
PerlModule ModPerl::RegistryPrefork
Alias /perl-run/ /home/httpd/perl/
<Location /perl-run>
SetHandler perl-script
PerlResponseHandler ModPerl::RegistryPrefork
PerlOptions +ParseHeaders
Options +ExecCGI
</Location>
Can a default locale value be placed in file php.ini or .htaccess?
The equivalent of the PHP function
setlocale(LC_MONETARY, 'it_IT');
for example.
It can. Take a look at intl.default_locale.
There's nothing in the php.ini file to help you. But as an alternative you could try setting environment variables from file .htaccess:
SetEnv LC_ALL it_IT.UTF-8
But these settings only take effect for the CGI and FastCGI versions of PHP at best, not for the usual mod_php installation.
Sadly there is no way at this time to set this configuration PHP-wide.
I've been looking at the code and the ENV method doesn't work since LC_* variables are not treated like the other ones.
You can patch PHP to use your locale instead of the default 'C' one or make a module if you really need to.
But the actual way to go is to do it at the script level.
Using auto_prepend_file in php.ini lets you run add some code before any script executed, so it looks like a nice place to use setlocale.