Is it fine to code PHP on Windows and host it later on a server running Linux? Can there be any problems in the migration of such a project?
I would think that there really can't be any problems, especially since I am a beginner in PHP and I won't use any of the advanced functions that may be OS-specific. However, I would like to make sure since I really don't like Linux at all.
Best Answer
Some pointers:
Filesystem case sensitivity
If your file is called HelloWorld.php this:
is legit on Windows and will work. But Linux filenames are case sensitive, you can have files called
HelloWorld.php
,helloworld.php
,hEllOwOrlD.php
in the same directory. So you should develop on Windows as if you were developing on a case sensitive filesystem: use exactly the correct filenames, directory names, extension names -.php
is also different from.PHP
.Directory and path separators
In Windows we say:
But in Linux we would say:
PHP is smart enough to not care, both separators work in both systems. But you should be consistent and go with the slash (/) everywhere as it's also the norm on most systems. There is a nifty predefined constant
DIRECTORY_SEPARATOR
that translates to the correct one, if you want to go that far:The same goes for the path separator, which is semicolon on Windows, colon otherwise. So to be safe you should do:
when in need of a path separator. Although most people think that since PHP doesn't mind which separator you use it's ok, but there is one important catch: The separators will be the system specific ones when you ask the system for directories or paths. So let's say you want to explode the include path into its parts:
File encoding and delimiter
You should set your IDE to set file encoding for all your scripts to UTF-8 instead of Cp*, and the file line delimiter to Unix (
"\n"
instead of"\r\n"
). In most cases it won't really matter but you should be consistent and the best way is the Unix way (which works fine on Windows but not vice versa).