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

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

Related

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.

Why my php code doesnt work?

php is not working in my computer. I have installed Apache server and save the file with .php extension in htdocs but still its not working.
I have written these code:
<?php
echo "Hello World!";
?>
it shows nothing. I have opened .htaccess file and got,
# This folder does not require access over HTTP
# (the following directive denies access by default)
Order allow,deny
what can I do now.please help me.
Open the Apache server log and take a good look at it. That's what it's there for. It logs everything. Is in /logs in your Apache programs directory.
You either don't have php installed into Apache correctly (likely), don't have Apache set up correctly, or don't have PHP set up correctly.
You'll want to look at conf/httpd.conf for Apache configuration, and php.ini for php configuration.
Sort out Apache first. Try to serve a simple .htm or .html page. i.e. put a simple text file with .htm file extension, e.g. myfile.htm, in your DocumentRoot (see conf/httpd.conf) and see if you can browse to it.
You might want to set 'ServerName localhost', and then browse to localhost/myfile.htm
From the Apache log you will also be able to tell if php is loading correctly. If not comment out the list of extensions, e.g. extension=php_gd2.dll, and try it again. I've had it not load because some of the libraries were not present. If you get it to work with all commented out, then one way or another figure out which ones are causing the trouble and leave them out.
Important: You must shutdown Apache and restart it after any configuration changes. (Not re-boot, but rather the Apache server monitor widget.)
Also did you install 32 bit versions of both Apache and php? If you try to mix x64 with x32 it won't work. And as I recall there are specific recommendations about which versions to use with which at the php download site. Pay attention to the details there.
I recomend you to add the php module to apache
a.Running PHP 5 as an Apache Module
To configure Apache to load PHP as a module to parse your PHP scripts, use an ASCII text editor to open the Apache configuration file, "httpd.conf". If you use Apache 1.x, the file is found in "c:\Program Files\Apache Group\Apache\conf\". Apache 2.0.x users can find it in "C:\Program Files\Apache Group\Apache2\conf\" while Apache 2.2.x users can find it in "C:\Program Files\Apache Software Foundation\Apache2.2\conf\". Basically, it's in the "conf" folder of wherever you installed Apache.
Search for the section of the file that has a series of "LoadModule" statements. Statements prefixed by the hash "#" sign are regarded as having been commented out.
If you are using Apache 1.x, add the following line after all the LoadModule statements:
LoadModule php5_module "c:/php/php5apache.dll"
If you are using Apache 2.0.x, add the following line after all the LoadModule statements:
LoadModule php5_module "c:/php/php5apache2.dll"
If you are using Apache 2.2.x, add the following line instead:
LoadModule php5_module "c:/php/php5apache2_2.dll"
This steps can be found on this link
Thank you everybody who tried to give my answer and helped me. It was a surprising experience for me that how quick you answered my question!! It was my ignorance to follow your suggestions. I've solved the problem by installing xampp. Now php is running fine in my computer.I am new in PHP programming and I will ask your help in future also. So be helpful to me always. I will be grateful to you. Thanks again.
Kallol Das,
Bangladesh.

How can I add additional PHP versions to MAMP

The current version of MAMP that I have only has php 5.2.17 and 5.4.4. I need 5.3.X. Is there a way to add additional versions that can be selected in the MAMP interfaces php preferences? This is for the free version of MAMP, not MAMP PRO.
Thanks
Found a quick fix in the MAMP forums.
Basically it seems MAMP is only allowing 2 versions of PHP to show up. Quick fix, rename the folders you're not bothered about using, for me this meant adding an "X" to my /Applications/MAMP/bin/php/php5.4.10_X folder. Now 5.2.17 and 5.3.20 show up in the mamp prefs.
Done!
Edit - if the PHP version you require isn't in the PHP folder, you can download the version you require from http://www.mamp.info/en/downloads/
Edit - MAMP don't seem to provide links to the alternative PHP versions on the download page any more. Use WayBackMachine https://web.archive.org/web/20180131074715/http://www.mamp.info/en/downloads/
If you need to be able to switch between more than two versions at a time, you can use the following to change the version of PHP manually.
MAMP automatically rewrites the following line in your /Applications/MAMP/conf/apache/httpd.conf file when it restarts based on the settings in preferences. You can comment out this line and add the second one to the end of your file:
# Comment this out just under all the modules loaded
# LoadModule php5_module /Applications/MAMP/bin/php/php5.x.x/modules/libphp5.so
At the bottom of the httpd.conf file, you'll see where additional configurations are loaded from the extra folder. Add this to the bottom of the httpd.conf file
# PHP Version Change
Include /Applications/MAMP/conf/apache/extra/httpd-php.conf
Then create a new file here: /Applications/MAMP/conf/apache/extra/httpd-php.conf
# Uncomment the version of PHP you want to run with MAMP
# LoadModule php5_module /Applications/MAMP/bin/php/php5.2.17/modules/libphp5.so
# LoadModule php5_module /Applications/MAMP/bin/php/php5.3.27/modules/libphp5.so
# LoadModule php5_module /Applications/MAMP/bin/php/php5.4.19/modules/libphp5.so
LoadModule php5_module /Applications/MAMP/bin/php/php5.5.3/modules/libphp5.so
After you have this setup, just uncomment the version of PHP you want to use and restart the servers!
MAMP takes only two highest versions of the PHP in the following folder
/Application/MAMP/bin/php
As you can see here highest versions are 7.0.10 and 5.6.25
Now 7.0.10 version is removed and as you can see highest two versions are
5.6.25 and 5.5.38 as shown in preferences
I'm using the free version of MAMP on mac (27 of April of 2021, MAMP version 6.3) and the #LiveSource answer helped me to find a solution.
My MAMP is not showing more than 2 option on the dropdown and on the /Applications/MAMP/bin/php has 7 options of PHP version. So the MAMP will display the latest 2.
To solve it I changed the name of all PHP version folders that I would not like to use. This way only 2 folders will be compatible with MAMP and my desired versions will display on the dropdown.
I added a _X in the end but you can add anything.
After doing the change, close the MAMP and open it again.
See the screenshots of the solution working.
First stop the Server if its running. Go to "/Applications/MAMP/bin/", rename the PHP Version you don't need (MAMP is only allowed to use 2 PHP Versions), e.g. "_php5.2.17". Now MAMP will use the php versions that are left. Go to the MAMP Manager and then settings, then switch to the php version you need.
One problem with this solution I encountered was the httpd process (took me a while to figure that out xD). If you have the httpd process running in the background, then the php switch won't work, until you stop those processes (sometimes MAMP has an awkward problem to stop the server, thats why this process can be still alive). Start your Activity Monitor on your Mac (Shortcut: Press Command+Space and type in activity...), go to the Search Function and type in "httpd", close all those processes. Now you should be able to switch your PHP Version with the MAMP Manager.
Maybe easy like this?
Compiled binaries of the PHP interpreter can be found at http://www.mamp.info/en/ downloads/index.html . Drop this downloaded folder into your /Applications/MAMP/bin/php! directory. Close and re-open your MAMP PRO application. Your new PHP version should now appear in the PHP drop down menu. MAMP PRO will only support PHP versions from the downloads page.
Additional Version of PHP can be installed directly from the APP (using MAMP PRO v5 at least).
Here's how (All Steps):
MAMP PRO --> Preferences --> click [Check Now] to check for updates (even if you have automatic updates enabled!) --> click [Show PHP Versions] --> Install as needed!
Step-by-step screenshots:
The easiest solution I found is to just rename the php folder version as such:
Shut down the servers
Rename the folder containing the php version that you don't need in /Applications/MAMP/bin/php. php7.3.9 --> _php7.3.9
That way only two of them will be read by MAMP. Done!
Honestly try using Docker had such a headache with MAMP and php versions.
Use this to get it up and running its simple.
https://github.com/harshalone/docker-compose-lamp
git clone https://github.com/harshalone/docker-compose-lamp.git
cd docker-compose-lamp/
cp sample.env .env
// modify sample.env as needed
docker-compose up -d
// visit localhost
In the bin folder you will see your php versions.
Change the version you want to use in your .env file PHPVERSION=php7.4
You can watch this tutorial. Wish I had started using docker earlier it will save you a tonne of issues and time.
https://www.youtube.com/watch?v=MTeY3npy1gU
The file /Applications/MAMP/bin/mamp/mamp.conf.json holds the MAMP configuration, look for the section:
{
"name": "PHP",
"version": "5.6.28, 7.0.20"
}
which lists the the php versions which will be displayed in the GUI, obviously you need to have downloaded the PHP version from the MAMP site first and placed it in /Applications/MAMP/bin/php for this to work.

Apache set specific PHP binary

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.

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