How to make PHP5 emulate older version? - php

I'm writing a web app on my system using PHP5, but the app needs to be compatible with PHP4. Is there any way to emulate PHP4, or at least issue warnings?
Thanks.

As a general rule, if you avoid functions and arguments that were added in PHP5 (as shown in the documentation for each function), then it should work just fine with PHP4. PHP is good at backwards-compatibility like that.

There is no way to emulate PHP4 that I'm aware of. You need to run your code in a real PHP4 environment. Here's what I'd suggest:
Grab an old distro which includes a PHP4 package. Apparently, Ubuntu Dapper (6.06) does.
Install it into a VM (VirtualBox or VMWare) on your box.
Create a shared directory for the VM which points to your app dir on the real box.
Inside your VM, create a symlink from the webroot to the mount point of the shared directory.
Once that is done, you can more or less forget about the VM. All you need to do is keep it running. Change your code in your app dir as before. You can run it from your browser with the IP of the virtual machine.
(Perhaps you could even install an old version of XDebug in the VM and do proper remote debugging from within your IDE. But I don't know if XDebug is compatible with PHP4 at all.)

No, there isn't. You will have to install PHP 4 on the machine to provide the runtime environment. Or, even better, convince the client that PHP 4 in 2012 is... outdated.

Related

I have developed am application using PHP7 but on the server there is PHP5 and we cannot upgrade the PHP there

Please help me, I have developed an application using Yii2 Framework which requires PHP5.6 or greater, and while deployment of the application on the test server I have noticed that on the test server we are using PHP5.5, So please tell me what can I do? The test server is running Ubuntu.
(Minimum requirement of Yii2 is PHP5.6 and we are using PHP5.5)
Thank You.
if I recall correctly, PHP 5.5.X and 5.6.X are not that different. So if you can deploy your application and it runs properly, you should be fine. If you are using composer, it might be harder (or impossible) to spoof your PHP version, though.
My two cents:
You tagged AWS (and therefor probably EC2), so why don't you just update your PHP version? Why don't you run your application on PHP 7.X anyway? It is a great improvement - performance-wise.
You can try a few things...
1) Do you need to have the dev modules from Composer on the test server? If not do a composer install —no-dev
2) Another switch worth trying on the test server is “--ignore-platform-reqs” I don’t recommend it and even though composer install the files the application might not work.
3) If the above isn’t a fix for you, modify your Composer file to put in the constraints of your environments, change your local environment to match the test server, and re-factor the application if necessary. I’d do that instead of rewriting a whole app in Yii1.
You might want to edit your question and add the information about your composer.json file. Do you commit the composer.lock file to source control?
Additionally, not wise for your company to use anything older than PHP 5.6. And PHP 5.6 will have security support ended in Dec 2018. http://php.net/supported-versions.php
Read the following PHP documentation linked below, particularly the backward incompatibility changes and deprecated features. If you use any of those, you need to change your code. If you don't, then you should be fine. You need to test it.
http://php.net/manual/en/migration56.php

There is something like pip+virtualenv for php? [duplicate]

I'm used to using python's virtualenv tool to create separate environments that can mimic deployment environments for projects I write.
Now, I'm going to be working on a php project and I'm wondering if there's any equivalent to that? Specifically I'm hoping to be able to run one virtualhost on apache with one (older) version of php, while everything else runs on the normal up to date version.
My development machine is running ubuntu 11.04, so solutions that work on that platform would be preferred.
Assuming that you are using mod_php, there is no way to load multiple different versions into the same Apache instance. You can run multiple different versions if you're running PHP as CGI or FastCGI, but this will itself introduce some differences in behavior from mod_php.
Another alternative to virtual machines is docker.
As loading different versions of php within apache with mod_php seems not to be posible, the easiest way of mimicking deployment and development setups will be with a virtualmachine, which you stated you would like to avoid.
One way of making the burden of vm's for developers a bit easier is to use something like vagrant. With two files (the vagrant file, and the chef/puppet file) you can "version" your vm's, easily create them and destroy them for each project and when needed.
virtPHP is a tool for creating and managing multiple isolated PHP environments on a single machine. It's like Python's virtualenv, but for PHP. (README)
https://github.com/virtphp/virtphp
You might be interested in this: https://github.com/phpenv/phpenv
(Haven't coded php in years, so this might be outdated)
As far as I remember you just had to point to another directory where your libraries reside (include PATH), using something like:
include_path = .:/usr/local/lib/php:./include (this goes in php.ini, default libararies)
and in your php files:
ini_set("include_path", ".:../:./include:../include");
PHP never really had a robust packaging system and library repository like perl/python/ruby has, PEAR was trying to move in that direction but it is very closed in comparison and was hard to configure in multiproject environments.
Phark is trying to build a brew/bundler port for php, https://github.com/lox/phark, although it's not deployment ready.
As of now, there is no out of the box solution to this problem. The only solution which comes close is Vagrant and puPHPet.com as discussed here: https://drupal.org/node/2055947
Why can't we have an environment like python's virtualenv or ruby's rbenv? It makes up a nice open source project. Multiple instances of PHP can be handy if we want to test out some libraries in sandboxes rather than globally. We can install dependencies for different projects using a package manager like Composer.
Cloudlinux with PHP Selector has this for ages. It is integrated with popular control panels like CPanel, DirectAdmin etc.
Each linux account can have its own version of php and select any extensions they sit fit.
https://www.cloudlinux.com/php-selector

Build a MAMP environment on Mac... Best solution?

I recently bought a new mac... In the past I used MAMP and Bitnami for the setup of my dev environment, but I would like to find a more efficient way, if exists, to manage my apache & php installation...
So...
What is the best way to set up a PHP development environment on a Mac? On StackOverflow I found something on http://www.macports.org/ are they reliable and/or updated to latest versions of apache and php?
I am one of the BitNami developers. I wanted to mention we have released a version of MAMP stack that you can download and run from Mac OS X app store with one click. It is completely free: https://itunes.apple.com/app/mamp-stack/id571310406
I finally found my perfect setup thanks to this blog post: http://echodittolabs.org/blog/2011/09/os-x-107-lion-development-native-apache-php-homebrew-mysql-or-mariadb, which basically uses Lion's built-in Apache and PHP with a Homebrew installation of MySQL and a nice VirtualHosts setup.
You can try AMPPS new MAMP/WAMP Stack. I use it.
I've installed Apache/MySQL/PHP on linux servers several times, and it's usually a piece of cake because of good package managers.
However, I had a terrible experience with MacPorts. Why don't you look at Xampp if it has everything you need.
I think I'm going for an Ubuntu Virtual Machine, for several reasons...
Easy to mantain (all packages available)
Easy to shutdown
MacOS stays clean
I can easily switch env or similar...
For Windows users i recommend "Softaculous AMPPS" since it's easy to update it. For Mac users I recommend "Bitnami MAMPStack". However to test PHP mail function on my Mac, i use "MAMP Pro".

Equivalent of Mongrel/Webrick for PHP Development?

Is there an equivalent in PHP development to using Mongrel/Webrick during Rails development?
I normally use Mongrel on port 3000 to serve up my Rails app during development.
Its been a couple of years since I've done PHP development. From what I recall, the method was to run Apache on the dev machine during PHP development (which involved setting up virtual domain in Apache etc....).
Is this still the case or is there a simpler method these days. Unfortunately a quick Google did not yield anything of interest.
Before I forget, the dev environment is on Debian Lenny. Ubuntu solutions also welcome.
Thanks for any and all suggestions.
I found interesting answer on serverfault:
A built-in webserver will be included in a future version of PHP
You could take a look at lighttpd - that's quick & easy to install and configure with PHP.
If you're on Debian/Ubuntu it's fairly easy to set up an Apache environment. Everything you need is in Synaptic.
Below is how to do it in ubuntu, but if you want really easy, use a VM appliance:
LAMP appliance.
XAMPP may also be workable, but I have only used that in windows.
In ubuntu:
sudo tasksel
select LAMP, and that will set up apache, etc. In the middle of the install it will ask for the mysql password.
Files live within /var/www, but this can easily be changed in vhosts (I use a subdirectory of my home folder which is more often backed up). A quick check of the ubuntu online documentation should show you the correct files to edit (since I think there was a change after hardy).
Subversion and phpmyadmin are a good idea as well, as I'm sure you are aware.
a2enmod will enable mod-rewrite, etc, as that is not enabled by default

start php, apache?

I've just started reading about php, it needs me to install php, apache and MySql to run any php script. can any one suggest me a simplest method to install php, apache and MySql so that i can sun those php script.
I've tried the zip files from php.net, Are those required to run the script offline for practicing the script? what do i do with them? i felt the things given on the same site a bit complex, and was unable to run the script. please help.
I'm assuming you're using Windows - get wamp - it has exactly what you need:
Apache
MySQL
PHP
Wamp comes with a nifty tray controller app which you can use to access the most common tasks, like restarting services, editing config, etc.
Equivalent to Artem's post, just a different organization which packages it differently. And my preference. It is called XAMPP.
If you are using Windows, you could install XAMPP to have the environment setup for you. You'll then need to learn how to bring up the server (basically executing the XAMPP control panel program), copy your PHP scripts into the correct directories (for XAMPP, it'd be C:/[xampp installation dir]/htdocs), access MySQL and creating the necessary MySQL databases (you could access the MySQL via the included PhpMyAdmin).
You can probably refer to a tutorial here (it's a YouTube video, BTW).
Don't have enough rep to comment but wanted to add something to Artem's recommendation of Wampserver. It's what I use on my windows machine, and one of the nicest things about it I find is the ability to have multiple versions of versions of apache, php and mysql installed alongside each other as plug-ins and then select which to have running at any time. It makes it easy for me to emulate the eventual hosting environment for any given project.

Categories