I've got a server that is running Linux Debian and have apache2 and php5 installed but I have no control over its apache configuration. If I create a .htaccess file on the server to do for instance a basic authentication on a directory it works. However if I want to use any extension to be executable as PHP such as file.abc with AddType it makes it downloadable. Although PHP extensions such as php1, php2, php3, php4, php5 and phtml are perfectly executable as PHP on this server.
My Question is If Basic Auth is working but any.ext cannot be executable as PHP does that mean AllowOverride is set to None? Then how basic Auth is working? And am I able to make any.ext executable as PHP on this server?
Related
I have a simple website hosted on a shared Linux server (by a company whose logo is an alligator). The default PHP version is 5.6.30. The cpanel for the server provides a page called MultiPHP Manager that enables me to update my site to PHP 7.x (same problem appears whether it's 7.0, 7.2, 7.3, or 7.4).
After updating to 7.x, the PHP JSON module seems to be missing (not reported in phpinfo()) when I run PHP through the web server (CGI, I think), but there is JSON support at the shell level.
I made this test file:
<?php
if (function_exists('json_decode')) {
echo "JSON enabled";
}
else echo "JSON NOT enabled";
If I get a bash shell with ssh and run php json.php, it works (says enabled). But, if I run this file via the web server in public_html, it comes back disabled.
The tech support for the hosting service has been useless.
Ok, I believe I've figured this out.
This host uses suPHP to run PHP. By default, suPHP will not look in public_html or the home directory for a php.ini file. So, you need to add these lines to the .htaccess file in public_html:
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/username/public_html
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>
Once that's in place, you can add this line to the php.ini file in the public_html folder:
extension=json.so
And, of course, if you require other modules, you will have to add extension= lines for those as well. What a pain . . .
I just installed multiple PHP versions on my server using FastCGI. Although I can only use them when the module PHP5 is disabled. When the latter is enabled, this configuration of my virtual host seems to be ignored :
<Directory /var/www>
AddHandler php-cgi .php
Action php-cgi /cgi-bin-php/php-cgi-5.5.17
</Directory>
Everything works fine when PHP5 is disabled but everything is executed using the module PHP5 when it is available. Would you have any idea?
Thank you
Ps: I am obviously on Apache (2.4) on Debian 7
After a moment of reflection, it makes sense that when the PHP module for Apache is available, Apache2 uses it, since it is part of it. My main issue was actually to prevent having to specify a handler for each website I have on the server, and if none is defined, use a default PHP version with FastCGI.
To get this working, I eventually added something like this in my fastcgi.conf:
<Directory /var/www>
AddHandler php-cgi .php
Action php-cgi /cgi-bin-php/php-cgi-5.5.17
</Directory>
With this I was sure to have at least PHP5.5 running for each site, without having to specify the handle in the virtual host. Problem was, what about Phpmyadmin that runs under /usr/share/phpmyadmin? Then I removed the <Directory> tag and it works.
I don't know if that is the best solution but please let me know if the above is correct or if there would be a better way to perform what I need.
Thank you
I had downloaded Apache Tomcat for developing Java Servelets, then I thought of using PHP also, I referred this for help on setting up Apache Server for PHP, and it says:
To configure Apache to run PHP, the httpd.conf file needs to be
modified. This file is located in the apache installation directory
under the conf folder. Open the httpd.conf file in EditRocket and do
the following:
A. Add the following line after all of the LoadModule statements:
LoadModule php5_module "c:/php/php5apache2_2.dll"
B. Search for AddType, and add the following after the last AddType
line:
AddType application/x-httpd-php .php
C. Add the PHP location to the end of the httpd.conf file. For
example, at the end of the file, add the following:
PHPIniDir "c:/php"
I looked under the C:\apache-tomcat-7.0.4\conf, but there is no file as httpd.conf.
Is there any other version which I'll have to download? Or can Tomcat run it with some plugin or something?
According to Apache Tomcat Howto, Tomcat is not capable of running PHP as it is designed only for JSP and static. Further reading shows that in order to provide your hosting for JSP, you need to install Apache webserver, and then install a web server adapter, and then modify Tomcat XML.
Modify Apache's httpd.conf file.
Install a web server adapter.
Modify Tomcat's server.xml file.
The link is old, but there are other references, and most of them will tell you to install mod_proxy in apache and send it to tomcat for your jsp app portion.
I would suggest further reading at the documentation for how to make it work, as I don't have first hand experience with it for a full explanation. Also look here for better information on how to forward apache requests to your tomcat apps.
I completed a php/mysql project for a client and yesterday went about to deploy it onto the client's box - and promptly failed. To be honest, it's my fault I didn't do enough checking before I started - but the project is fully self-contained and I didn't need anything currently on the client's server.
I developed the project using php 5.3 and PDO for mysql connection. When I got access to the client's server, turned out that they have VERY old installation that was last upgraded in 2008 (yes, seriously). They have Apache 2.0 and php 5.2, which is configured/compiled without PDO and with minimum everything.
I do have root access to the server, but I can't go and blindly start upgrading things. They've got a whole live site, with live shopping cart, etc. on that server and any general upgrade of php would require thorough testing. Therefore I'm looking at ways to run my new project using a separate install of php 5.3, which I compiled from sources with all required stuff included and installed into a separate directory (/opt/php53).
I am thinking along the lines of enabling fastcgi on the server and then using that to run php form my separate install. If I do this inside apache <Directory> where my project is install, it should only affect that one directory - and should leave everything else as is. Things are made more complicated because I don't have any kind of test server where I could play/test configurations - I have to work on the live server directly.
I'm wondering whether this fastcgi approach is valid or maybe there are some other options I should consider.
You can try to use different ports on fastcgi for the various PHP versions.
Another approach: http://linuxplayer.org/2011/05/intall-multiple-version-of-php-on-one-server
I've done some further digging/experimenting (taking advantage of the fact that I'm in UK and the client and its customers are in the USA - so it's still night there). The following setup seems to have worked - this utilises php-cgi without recourse to fastcgi - and I still get a good response time.
1) Leave pretty much everything intact in apache httpd.conf file - that includes existing libphp5.so that utilises existing 5.2 installation.
2) Install php 5.3 into a separate directory - in my case /opt/php53.
3) In httpd.conf, add the following (or ensure it's already there)
ScriptAlias /cgi-bin/ /var/www/mainsite/cgi-bin
AddHandler cgi-script .cgi
<Directory /var/www/mainsite/newapp>
Options -Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
AddHandler php5-cgi .php
Action php5-cgi /cgi-bin/php.cgi
DirectoryIndex index.php index.html
Order allow,deny
Allow from all
</Directory>
4) In directory /var/www/mainsite/cgi-bin/ create file php.cgi with the following content:
#!/bin/bash
PHP_CGI=/opt/php53/bin/php-cgi
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=1000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI
5) Restart apache: /etc/init.d/httpd restart
After this, I placed a file with <?php phpinfo(); ?> into the root of the web server and into my newapp directory. Executed from the root of the server it produced (among other things):
PHP Version 5.2.5
Build Date Dec 11 2008 19:04:47
Server API Apache 2.0 Handler
When executed from the newapp directory, it produced:
PHP Version 5.3.28
Build Date Feb 13 2014 17:00:43
Server API CGI/FastCGI
Which is exactly what I want.
There are some tutorials out there telling me how to override PHP configuration when it is running in CGI mode. But I'm still confused because lots of them assume that the server is running on Linux. While I need to do that also on Windows.
My hosting is indeed using Linux but my local development computer is using Windows XP with Xampp 1.7.3. So I need to do that in my local computer first, then I want to change the configuration on hosting server.
The PHP in my hosting server is already run as CGI while in my local computer still run as Apache module.
At this point, the processes that I understand are:
Change PHP to work in CGI mode. I did this by commenting these two line in "httpd-xampp.conf":
# LoadFile "C:/xampp/php/php5ts.dll"
# LoadModule php5_module modules/php5apache2_2.dll
My PHP is now running as CGI. I checked this with phpinfo(). It tells me that the Server API is now CGI/FastCGI. Now I want to override php configuration.
Create "cgi-bin" directory in DocumentRoot. My DocumentRoot is in "D:\www\" (I'm using apache with virtual host). So it is now "D:\www\cgi-bin".
Change the default "cgi-bin" directory settings from "C:/xampp/cgi-bin/" to "D:\www\cgi-bin":
ScriptAlias /cgi-bin/ "D:/www/cgi-bin/"
<Directory "D:\www\cgi-bin">
Options MultiViews Indexes SymLinksIfOwnerMatch Includes ExecCGI
AllowOverride All
Allow from All
</Directory>
Copy 'php.ini' file to "D:\www\cgi-bin" and modify upload_max_filesize setting from 128M to 10M.
Create 'php.cgi' file in "D:\www\cgi-bin" and put these code inside the file:
#!/bin/sh
/usr/local/cpanel/cgi-sys/php5 -c /home/user/public_html/cgi-bin/
That's it. I'm stuck at this point. All of tutorials tell me to create 'php.cgi' file and put shell code inside the file.
How to do the 6th step on Windows? I know the next step is to create handler in .htaccess file to load that 'php.cgi'.
And also, because I will also need to change PHP configuration on my hosting server (Linux), is the 6th step above right? Some tutorial tells to insert these lines instead of above:
#!/bin/sh
export PHPRC=/site/ini/1
exec /cgi-bin/php5.cgi
I'm sorry if my question is not clear. I'm a new member and this is my first question in this site.
Thank you.
If your server is already running PHP as cgi, and you do not need to run multiple PHP configurations, steps 5 and 6 are not necessary. Just change the default php.ini