If I write PHP (php5 if it matters) on Windows and Apache is the same as writing PHP on another OS and Apache? I do not mean things like file paths. Thank you.
It shouldn't matter given that PHP is just a language. Should be the same wherever you go.
Yeah ... Setting it up might be a little different but its usage is the same as it is a scripted language.
As long as you don't exec
system commands or use invalid file paths, most things should port over no problem. I've been using PHP for a while now, developing on a Windows machine and then moving it over to a Linux box, and I can't think of anything that I had trouble with.
Hi johnny. The correct answer is: "it depends".
For the most part PHP will function the same on any operating system. There are quite a few caveats though, typically there are functions that just plain don't work on windows. (e.g. getrusage()). Finding windows libraries for PHP are also rather difficult sometimes, since the death of pecl4win (a site containing windows compilations of all the PECL libraries). This makes adding things like APC (Alternative PHP Cache) quite a chore.
That said, the PHP manual is well documented with regards to what doesn't work on windows.
Mostly, but you have a few things to watch out:
- Under *nix systems path names are case-sensitive, not under Windows.
- Under *nix systems, the path separator is
/
. Under Windows it is\
, but PHP translates/
automatically. Either use theDIRECTORY_SEPARATOR
constant or always use/
. - Under *nix systems, the path traversal schema is different. There is no such thing as a drive letter. There are mount points instead.
- Under *nix systems, file permissions are more strict than on Windows by default.
- Some functions are not available under Windows or behave differently. These are mostly for low-level functions (memory status, system status). Refer to the PHP documentation.
- If you are using
exec()
or any other similar function, the commands won't be the same. Refer to your system documentation.
About Apache:
You might hit some snags at some point in one server uses PHP as a module and the other one uses it via fcgi
. Two Apache configured the same way will behave the same way.
I'm going to mark this as community wiki, as I'm just copying and pasting my answer from another very similar thread:
Almost, but not quite. There are a couple of things you have to watch out for.
1) File names: Windows is a case-insensitive operating system. If you create a file Foo.php, you can include it using include('Foo.php')
OR include('foo.php')
. When you move your project to Linux/Unix, this will break if you don't have the right case.
2) There are some language-specific platform differences, generally when it comes to something that relies on integrated OS functionality. These rarely come up, but you might run into them occasionally. For example, the checkdnsrr() function didn't exist in Windows PHP until version 5.3.0.
3) Installs. The PHP packages you get for Linux/Unix can very widely in what they include in a default install compared to Windows. You need to make sure to test your app on a development box of the opposite platform just to be sure you have all the required libraries compiled/added in, or you'll get some nice fatal errors from an otherwise normal looking app.
There are some differences, as other users noted (I won't repeat those, there are already great answers ; the most annoying point is case-insensivity in files names under windows, IMHO), so if you are using a Linux server to deploy you site in production, it might be useful to test it on Linux once in a while.
If you don't want to install Linux on your machine, and have a powerful enough computer (at least 2 cores, and 2 GB RAM, I'd say), you can use a Virtual Machine, with one of those software (both are free) :
It'll also help you learn some basics about Linux -- which is not a bad thing to know if you are planning on doing PHP development professionnally, as Linux is far more used than Windows, when it comes to PHP webservers.