run php as lower version - php

I have a local development server and a remote server.
The remote server runs php 5.4, my local server runs XAMPP with php 5.6.
I originally wrote the the php for 5.6, but there are some scripts that produce an error in 5.4.
The obvious solution would be to install XAMPP with php 5.4 locally, but I have multiple site development projects on my computer, some of which which are written in 5.6 and are deployed on 5.6.
Is there a way to make 5.6 at least act like 5.4 so I can test the site locally and find all the errors before deployment?
I thought putting 'AddHandler application/x-httpd-php54 .php' in my root .htaccess might work but it didn't.

There is no way to make 5.6 act like 5.4.
You must have to done changes in your code.

It's impossible.
Think about using virtualization for easy multiple environments.
Vagrant is tool for that, after installation only one command like vagrant up gives you ready to use LAMP server, you can deploy multiple VM with different PHP versions etc.

Related

Whats the best way to setup multiple PHP versions + NGINX on macOS?

I'm really struggling with multiple PHP versions on macOS (my local workstation).
Currently, I have a website written in PHP 5.6 that is hosted in NGINX. In the past days, I was using LAMPP (php 5.6) to start apache and PHP. But I had some issues because NGINX isn't exactly the same as Apache.
So I wanted to have a more realistic workstation... Today I installed the NGINX and PHP 5.6 (and php-fpm) on my mac, but I didn't work properly then I uninstalled everything and I'm trying again.
Anywaaaaays: whats the best way to set up my local machine and have both PHP 5.6, PHP 7.2 and NGINX?
You should take a look at docker, seriously it so easy and you can run containers with different versions
https://hub.docker.com/_/php/
If you are using a Mac, try using MAMP (https://www.mamp.info)
They have option to use NGINX server. see attached screenshot

Multiple PHP / Apache Versions on MacOs

At the moment I'm using two machines for Web (Win10) & iOS development (MacOS) and looking to combine them into a one computer that I would use on a daily basis.
My current challenge is to ensure that I can develop and run two or more environments on the same machine (not necessary at the same time, a simple switch would do the job).
I've tried MAMP and AMPPS and they both do the job, with an exception to the PHP-CLI version.
Every time I run php from the console it opens up the latest version completely ignoring the one that is specified by the MAMP or AMPPS.
What is the best way to ensure that php-cli always points to a currently active version of the PHP as stipulated by MAMP or AMPPS?
On Windows I was using https://ospanel.io/ that had it's own internal terminal window that would automatically load the current version of php-cli.
I am fully aware of docker/vagrant but they would be an overkill in this case.
Thanks
Unfortunately there is no simple answer to my question. As a solution:
Get multiple version installed
Design a script that changes the PATH environment to the right version as required.
alternatively a script that rewrites a symlink to a required version of the PHP.
For MAMP user, you must edit the file /usr/local/etc/httpd/httpd.conf and set the PHP version you prefer to use in your stack. I only installed one version of Apache HTTPD with multiple PHP versions - you have to specify the version.
If you don't, the default is the Mac's pre-installed PHP version.

Do I still need XAMP with php version 5.6

I am returning to php after a long time (although I have a very basic understanding of php in general), and understand that I can run a php server locally by running the command now with version 5.6:
php -S localhost:8080
Do I still need to install XAMP or WAMP as many of the online tutorials are suggesting or am I okay to just use the above command?
Note: I have postgresql installed on my computer already and do not use mysql, if that matters at all
You need a webserver which you prefer depends on you. XAMPP is the most used for private but you could also take a look at BigApache, EasyPHP, PHPTriad, MampServer, WampServer.
Xampp is a combination of below
Apache server
Mysql server
PHP
and others.
This is a pretty famous and most used package. But if you want to install everything manually then thats even better you can control your server in any way you want. Go for it and you will learn more about it.
If you want a very flexible development environment you need to use a package like EasyPHP Devserver (http://www.easyphp.org/) or equivalent.

PHP on an IIS server

I have designed a PHP based website which needs to run on a local server. Unfortunately I have developed this on a WAMP server using Apache. The machine on which this website will be placed on only supports the IIS server and I am not allowed to install Apache on this this machine.
How do I run PHP code on an IIS server?
See this link: http://php.iis.net/
99% of stuff is compatible. There can be some problems though (for example if you use mod_rewrite, or some file operation functions behave a little differently).
You can get it installed and include the right infrastructure (IIS, WinCache, and FastCGI, and URL Rewrite) with a single click using Web Platform Installer:
To install PHP 5.2 use:
http://www.microsoft.com/web/gallery/install.aspx?appid=PHP52
To install PHP 5.3 use:
http://www.microsoft.com/web/gallery/install.aspx?appid=PHP53
http://php.iis.net/
With IIS 7, a lot of the apache/iis gaps have been closed. Like mod_rewrite is available in IIS 7 (http://www.iis.net/download/urlrewrite)
Here's how I got PHP 5.3 running on IIS 6:
http://www.howtoadvice.com/PHPIIS

PHP 5.2 and 5.3 together

I have XAMPP with PHP 5.2, but my new projects need PHP 5.3
How to have PHP 5.2 and 5.3 together?
I have winXP.
You can do one of the following:
Ensure your older apps can run on 5.3 while not using 5.3 specific features. This is probably the
best route as it will tighten your
code and it will run on more
platforms, especially in the future
when more production environments
use 5.3 only.
If this is for development purposes only you can also consider:
multiple installations
of XAMPP and switch between them
when necessary via simple folder
rename (somewhat tedious)
php-switch (very tedious)
setup two apache servers on the same machine running different PHP versions
You've two choices: run two servers on a different port, or use CGI.
You can get XAMPP with PHP 5.3.1 here: http://www.apachefriends.org/en/xampp-windows.html#641
Edit \xampp\apache\conf\httpd.conf, and change Listen to Listen 8080 for example.
Then run \xampp\apache_start.bat to start that server instance. Optionally, change DocumentRoot to your project directory.

Categories