Apache set specific PHP binary - php

I have googled this and found lots of hits which appeared to be the same as I was asking but turned out not to be.
I have 2 different versions of PHP installed, and I would like to specify exactly which php binary apache uses when it starts up.
How could this be done?

Here is an example to indicate version 5.3 should be used and the route to php.ini. Add the following lines to .htaccess:
AddHandler application/x-httpd-php53 .php
SuPHP_ConfigPath /PathTo/DirWithPHP.ini

Personally, I have a machine where php runs as a cgi. I just keep multiple separate installs. Apache looks in /ws/php for the binary
/ws/php
/ws/php5.3
/ws/php5.4
/ws/php5.5
switching versions is a simple folder rename.
There's other ways, but this works and is very simple.

Related

load mutiple version of php on apache on xampp in windows environment

I was to load multiple version of php on xampp, and using ht-access add handler, so my one application should run in 5.3 php version using its htaccess and another application should use 5.4 php version.
can anybody please help me to deal with this?
Thanks
Amit
One way to do this is to have your main version of php set up with mod_php and run all of the others through fast cgi on different ports (i.e. 81, 82, 83 etc).
The best method is to change the PHP settings in
/apache/conf/extra/httpd-xampp.conf
to reflect the new version of PHP you want to use
In my case I unpacked PHP5.4 to C:\XAMPPLITE\PHP5.4 and then updated key lines in this file such as:
SetEnv PHPRC "C:\\xampplite\\php5.4"
LoadFile "C:/xampplite/php5.4/php5ts.dll"
PHPINIDir "C:/xampplite/php5.4"
You also need to ensure that the correct version of php5apache2_2.dll is installed
To ensure this I copied the new version of php5apache2_2.dll to the Apache modules directory with a unique name, and then modified the configuration to match that:
copy php5.4\php5apache2_2.dll apache\modules\php5apache2_2-5_4.dll
and in the httpd-xampp.conf file
LoadModule php5_module modules/php5apache2_2-5_4.dll

How to configure PHP on Mac for developing

I'm doing the installation for PHP on Mac, following this tutorial .
I checked my httpd.conf, which is a little different from mine for the following items.
Load Module php5_module
AddModule mod_php5.c AddType
application/x-httpd-php .php
What I have is Load Module php4_module, I don't have the item 2 and item 3, so I added these to my httpd.conf file. But after I restart my apache server with apachectl restart, it says that This webpage is not available. I checked the console of Chrome and found this GET http://localhost/info.php net::ERR_CONNECTION_REFUSED.
And I also found that:
If I didn't add item 2 and item 3 to the configuration file, the PHP
script just shows on browser, seems it's not parsed.
If I just add itme 3, when I accessed info.php from my browser,
it's downloaded instead of being displayed.
Anyone knows what's going on here? Did I miss any more configuration?
By the way, it will be grateful if you can provide a proper tutorial for beginner to set up the envrionment for learning PHP, just found so many articles online, but no one can work correctly.
Have a look at akrabats tutorials on how to install PHP on a mac. You can find the one for Maverics at http://akrabat.com/setting-up-php-mysql-on-os-x-mavericks/ and there is also one for yosemite.
Alternatively you could use homebrew or phpbrew to install php beneath the one delivered with MacOS as they are updated more frequently.
And there is also a third was by using the PHP-installer provided by liip at http://php-osx.liip.ch
Besides that I'd definitely recomend having a look at VirtualBox and Vagrant as lots of PHP-projects provide a vagrantfile to ensure all developers have identical development-environments. But that's a totaly different story!
If your intention is to learn PHP, regardless of the underlying OS, I would recommend that you install VirtualBox and install Linux so that you can follow any of the many 'LAMP on linux' tutorials e.g. http://community.linuxmint.com/tutorial/view/486
This will probably be more straightforward to get up and running, and won't pollute your Mac environment to the same degree.
Thanks for all your help. I found one useful tool to set up PHP environment quickly. It is XAMPP, which is really easy to set up the environment. Now I can start learning PHP freely. But, of course, I will study the configuration about all of this after I have a basic knowledge of PHP.
Thanks again for all your kindly help, hope will discuss with you later in the details.
Update: 6/26/2019
There have been a few changes in PHP and Apache since the other answers were written. Currently php7 has defaults built in. They are documented in the file php.ini.default. That file is not read by the PHP engine because the suffix .default hides the file from the PHP engine. If you want to change the PHP configuration then rename php.ini.default to php.ini. found at
/etc/php.ini.default
Apache just requires 2 things. Open the file
/etc/apache2/httpd.conf
Uncomment the line
LoadModule php7_module libexec/apache2/libphp7.so
and add the following to http.conf
# Set Apache to hand off php files the the PHP processor
<IfModule php7_module>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>
I put mine in the Supplemental configuration section near the end of the file.

jQuery $.post() returns PHP code

I've got this jQuery function:
function phpmail(){
$.post('mail.php',{name:$("#name").val()},
function(out){
alert(out);
});
}
and this PHP script in mail.php:
<?php
$name=$_POST['name'];
echo $name;
?>
However, each time when I click a button, I get PHP code and not the variable, so can someone explain me what I'm doing wrong?
I'm testing this on my local computer using WAMP.
maybe you test it using wrong url (on the browser)..
it should start with http://localhost/
not file:///c:\wamp\bla
This is a serious issue. You should make sure that php is correctly installed on your instance, otherwise anyone could see your code. Also make sure that your web server is not treating your cgi files as plain-text/html
This has nothing to do with either your PHP or JavaScript code. The problem is that your web server is misconfigured. It isn't recognizing ".php" as PHP code and therefore not parsing it.
You need to tell your web server that files with a ".php" ending are to be handled by PHP. You don't mention which web server you're working with so it's difficult to give you precise instructions for that but for what it's worth, here's the relevant portion of my Apache configuration.
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
# ...bunch of irrelevant stuff here
</IfModule>
Of course, in order for PHP to work at all, the module must be loaded like so:
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
However, if you're running Linux, it is strange if you have to configure this yourself. But then again I don't know what you're running.
Web servers differ quite a bit from each other, so it's difficult to give you good instruction without more information on your runtime environment. Are you running Apache or IIS or Lighttp etc.? - Are you running on Windows or Linux or Mac? If Linux, which distribution, Debian or Fedora Core or Ubuntu?
Do you config you Web Server(Such as Apache or nginx) correctly? Do you handle the php file as the plain text??

Making a CakePHP 1.2 page work on localhost

So I need to copy a site from a webserver and run it from my localhost.
The site is created with CakePHP 1.2.3.8166 (it says in VERSION.txt).
I am new to CakePHP, so i started with the 2.0 tutorial and i have also a fresh install of 1.2.11 and both work perfectly. (I just had to fix the mod_rewrite issues by enabling AllowOverride All).
However when i tried to run my downloaded site i just got "page not found" error.
With a little searching, the solution was to remove the first "/" in
"RewriteRule ^$ /app/webroot/ [L]" and other places in the .htaccess files.
So now my page looks wired, like this:
http://pastebin.com/ZMX3RjZG
Clearly the page does't load properly and i don't know what is wrong.
Now i am stuck, anyone have come across similar problem?
I run:
Windows 7 Pro 64bit,
PHP 5.3.6,
Apache 2.2.19
Any help appreciated.
Based on the second code sample you've provided and the way the rendered content is garbled I would say that shorthand tags aren't enabled in your version of PHP.
This shorthand notation might be the root of your problem:
<?= //Some PHP script ?>
There are two solutions, either change all the shorthand tags to the full declaration:
<?php //Some PHP script ?>
Which might be quite an undertaking as you're working with an existing project. It all depends on the size of it and if this shorthand notation is present in all of the files (the Cake core uses the full declaration). Or you could enable shorthand in your php.ini and restart the Apache server.
More information on shorthand tags can be found in the PHP manual.

Setting up local server with PHP

I'm trying to setup an Apache/PHP/Postgresql server locally on my machine. I'm using Windows vista business 32bit. I tried to install everything manually (one thing at a time, apache, postgresql and php (all the latest stable releases)) and after I get everything up and running.
Whenever I try to run a script on my machine, I get a "What do you want to do with the *.php file?" dialog. The dialog is the browser's open/save dialog
I'm just trying to get the output of phpinfo() to make sure everything is up and running...
I already tried to mess around a bit with the Apache conf file, but since I don't know much about what I'm doing, I reinstalled everything again and the problem is still there. I kinda get the feeling it must have something to do with the PHP thingy isn't correctly installed.
When i try to get the output of phpinfo as in:
<pre><?php
phpinfo();
?></pre>
I get the browser's "Open/Save" dialog for the *.php file.
You should have something like this in your httpd.conf file:
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "c:/php"
Make sure that's in place, and don't forget to restart apache!
In Windows, the default location for your conf file is C:\Program Files\Apache Group\Apache2\conf\httpd.conf
You can also have a look at the official page of PHP in the install section.
There is a closer link if you are on Windows.
And you can also use some precompiled installer for this like XAMMP and install Postgres after all is set up and running with the web server and php.
are you on Windows?
I use Wamp server, which is an excellent way of getting Apache, MySQL and PHP installed and configured without any hassle on Windows.
If you want to use Postgres instead, provided that you've got it installed separately it will work fine. (one great thing you can do with Wamp is add and remove PHP extensions via a GUI pretty much on-the-fly, and pgsql is one of them).
Maybe somebody can help, but you'd be much better off if you'd provide some relevant details.
What sort of system are you using? Be specific.
What do you mean by "everything up and running"?
What are you doing when you "try to run a script"?
What installation procedures did you use? (If you were following them off a script or how-to, we at least need to know where to find the script or how-to.)
We don't automatically know these things. What seems obvious to you may not be clear to us, and what seems irrelevant to you may turn out to be crucial.
In httpd.conf, make sure the PHP module is being loaded and that that line isn't commented out. (Comments in httpd.conf starts with #.)
Also what OS are you running?
I had the same problem, You need to configure apache and add the php module...
e.g I compiled the php from source as well as the apache. After doing so I then copied the libphp5.so from php/lib dir in to the apache/modules dir. Than you have to add php in the http.conf
LoadModule php5_module modules/libphp5.so
AddHandler php5-script php
you can then restart apache....it's not the most elegant of solutions but it works.

Categories