Using custom php.ini in a specific folder - apache

I've got full control of my Apache / WHM / CPanel server. I have a default PHP.ini file set up for everything and that is just fun for the production server.
On the same server, I have a staging/testing server - and on it I want display_errors to be ON instead of OFF (as it is in the production site of course). How can I tell the server to use a local PHP.ini file in that directory?
Thanks!

add an htaccess file to the dir with the rule php_flag display_errors on

In complement to #i_forget answer: You can use the php_admin_value & php_value & php_flag & php_admin_flag directives to alter specific settings on a Virtualhost or on a directory.
<Directory /path/to/foo>
php_value include_path ".:/var/www/foo/lib:/usr/share/php5/apc"
php_admin_flag file_uploads on
php_admin_value upload_tmp_dir "/my/tmp/upload/"
</Directory>
php_admin_value is safer than php_value (idem for flag) as the application cannot use ini_set to alter the value.
Here's it's one a Directory tag, so it could be as well on a .htaccess but you should'nt use .htaccess files if you have access to the configuration, use AllowOverride None :-). It could be as well on the VirtualHost, so before the the Directory tag.

Related

You don't have permission to access /phpmyadmin/ on this server. To access another pc localhost in windows 7

I am trying to access another PC Localhost on my PC in same LAN using IP address of that PC, and I am use WAMP Server to connect phpmyadmin of another pc.
I am successfully connected to WAMP server(e.g URL http://192.168.1.8/), but if I try to click on phpmyadmin(http://192.168.1.8/phpmyadmin/) then following network error occurred.
Forbidden
You don't have permission to access /phpmyadmin/ on this server.
Apache/2.4.9 (Win32) PHP/5.5.12 Server at 192.168.1.8 Port 80"
Please note that I trying to access another PC Localhost not my PC Localhost.
I am tried each and every thing to solve this problem can not solve that problem.
I change httpd.conf file according to required changes
i.e Require local to Require all granted.
I also change in phpmyadmin.conf file
i.e Deny from all to Require all granted
but not improve the problem
Please tell me the solution of that problem.
phpMyAdmin is secured in its Alias definition in WAMPServer by default, to protect the beginner from accidentally giving access to things without understanding the consequences.
So to allow another PC on your internal network to access phpMyAdmin on the server PC you will need to edit \wamp\alias\phpmyadmin.conf
It should look something like this :
Alias /phpmyadmin "c:/wamp/apps/phpmyadmin4.6.0/"
<Directory "c:/wamp/apps/phpmyadmin4.6.0/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
<ifDefine APACHE24>
Require local
</ifDefine>
<ifDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from localhost ::1 127.0.0.1
</ifDefine>
# To import big file you can increase values
php_admin_value upload_max_filesize 128M
php_admin_value post_max_size 128M
php_admin_value max_execution_time 360
php_admin_value max_input_time 360
</Directory>
Amend it to this to allow access
Alias /phpmyadmin "c:/wamp/apps/phpmyadmin4.6.0/"
<Directory "c:/wamp/apps/phpmyadmin4.6.0/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
<ifDefine APACHE24>
Require local
Require ip 192.168.1 <-- New Line
</ifDefine>
<ifDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from localhost ::1 127.0.0.1
Allow from 192.168.1 <-- New Line
</ifDefine>
# To import big file you can increase values
php_admin_value upload_max_filesize 128M
php_admin_value post_max_size 128M
php_admin_value max_execution_time 360
php_admin_value max_input_time 360
</Directory>
If you are using Apache 2.4.x you only need the first new line
If you are using Apache 2.2.x you only need the second new line
NOTE: Never use Require all granted or Allow from all unless that is actually what you intend to do i.e. give access to anyone in the universe!

phpmyadmin still accessible on /phpmyadmin after changing alias

I'm trying to secure my web server by changing the url of phpmyadmin (/phpmyadmin).
I have edited the file /etc/phpmyadmin/apache.conf :
Alias /secure-db /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc Off
php_flag track_vars On
php_flag register_globals Off
php_admin_flag allow_url_fopen Off
php_value include_path .
php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/
</IfModule>
Now, I can access phpmyadmin via /secure-db, and also via /phpmyadmin
I do not understand why /phpmyadmin is still available. Of course, I did restart apache.
By the way, I'm using ISPConfig 3.0.5.4p1
Any idea? Is there another kind of vhost somewhere?
EDIT :
I had another file "phpmyadmin.conf.bak.20140429" in the same folder which contained the alias /phpmyadmin. After removing it I could not go to the url /phpmyadmin. So I guess that this backup file was read by apache.

mod_rewrite ignores existing files

There is a number of similar questions, but none of them help.
I have the following rule in my .htaccess
RewriteRule ^images/.*$ - [F]
so for folders like /images/goods/ or /images/nonexistentfile.jpg I get 'Forbidden' which is what I want. The problem is if an existent file is requested, my rules are ignored and the file is served. In fact if I make a deliberate mistake in .htaccess I don't get an Internal Server Error as I would when requesting folders or non-existent files. What should I look for?
apache2.conf
<VirtualHost 1.2.3.4:8080>
ServerName domain.com
DocumentRoot /var/www/s3/data/www/domain.com
SuexecUserGroup s3 s3
CustomLog /var/www/httpd-logs/domain.com.access.log combin$
ErrorLog /var/www/httpd-logs/domain.com.error.log
ServerAlias www.domain.com
ServerAdmin example#domain.com
AddDefaultCharset utf-8
php_admin_value open_basedir "/var/www/s3/data:.:/tmp"
php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f example#domain.com
php_admin_value upload_tmp_dir "/var/www/s3/data/mod-tmp"
php_admin_value session.save_path "/var/www/s3/data/mod-tmp"
AddType application/x-httpd-php .php .php3 .php4 .php5 .phtml
AddType application/x-httpd-php-source .phps
</VirtualHost>
anything else I should post here?
I had a similar issue.
I put the following .htaccess in to the images folder to forbid access to jpg files (in my case)
IndexIgnore */*
<Files ~ ".*\.jpg$">
Order deny,allow
Deny from all
</Files>
It looks like you're htaccess file isn't being applied. Try adding an AllowOverride directive in your vhost config:
<Directory "/var/www/s3/data/www/domain.com/">
AllowOverride All
</Directory>
By default, AllowOverride should be set to All, but it's possible your host set it to something else at the server config level.
in case someone has the same problem, it is painfully trivial. The default ISPManager installation puts nginx in front of Apache for static files...

open_basedir restriction in effect and subdomains

For security reasons I have put my yii folder below the html root, so my structure looks like this
/conf
/httpdocs
/httpsdocs
/yii
when running the site I get an error open_basedir restriction in effect that yii.php which is called by index.php out of httpdocs is not in the allowed path. Because this site is a subdomain do I edit the vhosts.conf of the main domain or of the subdomain?
What would the proper setting be to allow
/var/www/vhosts/example.com/subdomains/mysubdomain/yii
Path to be accessible?
EDIT
So my /var/www/vhosts/example.com/conf/vhost.conf file looks like this now:
AddHandler fcgid-script .php
<Directory /var/www/vhosts/example.com/httpdocs>
php_admin_value open_basedir ".:/var/www/vhosts/example.com/subdomains/mysubdomain/httpdocs:/tmp/:/var/www/vhosts/example.com/subdomains/mysubdomain/yii"
FCGIWrapper /var/www/vhosts/example.com/bin/php-cgi .php
Options +ExecCGI +FollowSymLinks
allow from all
</Directory>
I've reconfigured and restarted the web server but I still get the error:
Warning: require_once() [function.require-once]: open_basedir restriction in effect.
File(/var/www/vhosts/example.com/subdomains/mysubdomain/httpdocs/../yii/yii.php) is not within the allowed path(s):
(/var/www/vhosts/example.com/subdomains/mysubdomain/httpdocs:/tmp)
in /var/www/vhosts/example.com/subdomains/mysubdomain/httpdocs/index.php on line 26
In the virtualhost:
php_admin_value open_basedir ".:/var/www/vhosts/example.com/subdomains/mysubdomain/httpdocs:/my/own/tmp:/var/www/vhosts/example.com/subdomains/mysubdomain/yii"
I found the answer. You have to specify the different modules or else simply editing the vhost file doens't have much of an effect. This is to turn off the open_basedir but you can edit the settings accordingly.
<Directory /var/www/vhosts/YOURDOMAIN.COM/subdomains/YOUSUBDOMAIN/httpdocs>
<IfModule sapi_apache2.c>
php_admin_value open_basedir none
</IfModule>
<IfModule mod_php5.c>
php_admin_value open_basedir none
</IfModule>
</Directory>
then
# /usr/local/psa/admin/bin/websrvmng --reconfigure-vhost --vhost-name=YOURDOMAIN.COM
# apachectl stop
# apachectl start
Full article can be found here: http://prattski.com/2008/09/13/plesk-open_basedir-fix/

phpmyadmin - list files in directory

I have apache+mysql+phpmyadmnin under Gentoo.
phpmyadmin-3.2.2
It worked fine before, but now, when I'm loading http://localhost/phpmyadmin I get a list of flies in phpmyadmin-directory, and when I chose index.php, I get it's own code.
What I did wrong?
It means that apache does not recognizes neither of your files as php executables. Maybe you run an 'emerge update world' and then an 'env-update' which install a new apache2 version and then re-write the old apache config file. As LiraNuna mentioned, you need to check that the phpMyAdmin directory contains the proper instruction to load the proper PHP module. In this way apache will know how to handle the php files.
This is what I have on /etc/apache2/vhosts.d/default_vhost.include under the phpMyAdmin Directory definition:
Alias /phpMyAdmin /var/www/localhost/htdocs/phpMyAdmin
<Directory /var/www/localhost/htdocs/phpMyAdmin>
Options Indexes FollowSymLinks
DirectoryIndex index.php
# Authorize for setup
<Files setup.php>
# For Apache 1.3 and 2.0
<IfModule mod_auth.c>
AuthType Basic
AuthName "phpMyAdmin Setup"
AuthUserFile /etc/phpmyadmin/htpasswd.setup
</IfModule>
# For Apache 2.2
<IfModule mod_authn_file.c>
AuthType Basic
AuthName "phpMyAdmin Setup"
AuthUserFile /etc/phpmyadmin/htpasswd.setup
</IfModule>
Require valid-user
</Files>
<IfModule mod_php4.c>
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc Off
php_flag track_vars On
php_flag register_globals Off
php_value include_path .
&lt/IfModule>
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc Off
php_flag track_vars On
php_flag register_globals Off
php_value include_path .
</IfModule>
</Directory>
This should solve your problem.
Is mod_php5 installed? If so, do you have the php handler set up to handle .php files?
<IfModule mod_php5.c>
AddType application/x-httpd-php .php .phtml .php4 .php3
AddType application/x-httpd-php-source .phps
</IfModule>
If you are not using mod_php5, do you use any form of CGI? Do the .php files have execute permissions?