简体   繁体   中英

Hosting PHP

For doing development, does it matter what OS PHP is running on? In other words would it be fine to develop a PHP application on Windows and deploy on Unix (or vice versa)?

In other words, do PHP applications run identically on Windows and Unix?

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.

I had one more too, but I think I need a coffee, my brain just stopped.

Edit: Oh yeah, I remember:

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.

The core PHP language runs identically, but with any language, you'll run into OS issues if you develop one one platform and deploy on another. There are differences in paths (file locations), web server configuration (what keys are available in the $_SERVER superglobal), what extensions are available if they use OS functionality (some PHP extensions are platform specific).

However, these issues are fairly specific. They can be frustrating, but you'll solve each one of them once and then move on. In practice most web developers end up using a development machine that has configuration differences from their production servers, and learning to work around those issues is helpful and results in a more portable application.

There are some differences between PHP on Windows and Linux like the ability to exec processes.

For the most part they are the same but there are certain functions that either don't work on Windows or behave slightly differently. You'll need to refer to the PHP manual pages in each case to see what. Linux is really the native OS for PHP. That being said, the differences are minimal.

You should watch for platform specific functions like fork (Unix only).

http://us3.php.net/pcntl_fork

One other thing, you didn't specify it in your post but I'm going for the original WAMP stack here...

Be advised that in MySQL, identifiers are case-insensitive on Windows but case-sensitive on Linux.

As stated above, there are some functions that don't exist in Windows, though do in Unix.

One thing I would be wary of when first starting out is permissions: Windows will generally let the PHP script read / write anything anywhere, whereas the Unix installation will not (especially as the actual web server may be running as an entirely different 'user' than the user that owns the script).

There is quite a few difference with file IO between linux and windows (outside of just the case sensitivity). The usual one that gets most people is most windows (DOS) files end the line with \\r\\n, unix ends with \\n and macs end with \\r. Simple enough to code around though.

i run Drupal (several versions with a wide assorted add-in modules) on windows / xampplite all the time and deploy to a unix box .. never spotted one iota of difference.

And I've also run SugarCRM, Joomla, Pligg, Zend Framework, CMS Simple, WordPress, Mantis, PhPBB and others I can't remember right now the same way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM