Ever wondered if there is any difference between Windows and Linux with respect to the development of PHP applications?
A question I hear often is “Can I develop applications on Windows and hosting on Linux?”. It’s a common question because many developers, because they have fear of dealing with an unknown operating system, end up opting for hosting that run the same OS that their local machines have.
Make your WordPress site’s Load Blazing Fast Just by moving to Nestify. Migrate your WooCommerce Store or WordPress Website NOW.
I decided to write this article to help clarify a bit more the difference between the two types of hosting.
Important: when I refer to Linux, I’m not talking only of it but of all Unix-like systems, such as Mac OSX, FreeBSD, OpenSolaris, etc.
Linux or Windows?
Many developers, especially beginners, are a little afraid to choose Linux hosting, especially when using Windows, either for fear of not knowing how to solve problems on the server or by even pure ignorance.
The fact is that, as a programmer, it is unlikely that you will be directly responsible for server maintenance, which makes the choice of virtually irrelevant operating system most of the time (taking into account the “put the application online“). Now you may be wondering: “If it makes no difference, can I choose anyone?”. The simplest and quickest answer is cost.
Most Linux distributions do not include cost of licenses, meaning you do not have to pay to use them. This, in a way, reduces those costs which can result in more affordable values for those who hire the services (but not always). I also believe that it is important to highlight “security”. The probability of a Linux server to be infected with a virus or malware is much smaller than a Windows server.
In my humble opinion, the only reason you would have to choose an Windows hosting is if you use Microsoft technologies such as .NET, Access and FrontPage. If you administer the server, you also have access to the Windows graphical user interface.
I can develop in Windows and host it on Linux? Or vice versa?
The answer is yes! However, you should be very attentive to some details which I will list below.
Most of them relates to the file system. It is necessary that you are aware of it.
File system
File systems, structures in which data is stored in the system behave differently on Windows and Linux. I suggest you to always develop it in a Linux environment, because it has a larger number of specifications.
One of the first things to note is the issue of file permissions. On Linux, the permissions system is different from Windows. The permissions are changed with the command chmod and are formed usually by 3 numbers indicating the relationship with the file owner, the group and other users. The files can be writable, read and execute, in any combination, and how they will behave depends directly on these permissions. When you run some specific commands or need to manipulate or perform reading files, you may run into permission problems.
There is also a difference in directory separators. While Unix-like systems use the forward slash (/) to separate directories in Windows backslash (\) character is used. It is essential to be aware of this, because in Linux backslash plays a different role (escape characters). To resolve this problem in a simple way, there is a predefined constant in PHP called DIRECTORY_SEPARATOR . It will return to the separator character that is in the appropriate directories of the operating system that is running the application.
Related to directories, there is a parting of the ways, when you need to specify more than one directory on the same string ( / first / directory: / second / directory ). In Linux, this is done with the character : and in Windows ; . The constant that references of this character is PATH_SEPARATOR , available for PHP.
Command Line
For obvious reasons, how the command line works also changes between operating systems. This will directly influence the way you develop your scripts and sends commands to the terminal by means of functions like exec () .
Commands sent to the terminal in Linux are run directly on the bash, with the user who is running the web server. In Windows, the command is run with cmd / c your_command. Keep this in mind when putting together their routines.
Textual Characters
The line break is another factor that changes from one operating system to another. When you write plain text files and need to jump from one line to another, may find difficult. On Linux, the line break occurs with LF (line feed), represented by the character \ n . Some older systems use CR (carriage return), with the character \ r . In Windows, this is done with a combination of the two CR + LF, or \ r \ n. Also there is a predefined constant to return with the proper line break. It’s called PHP_EOL (end of line) and is available since PHP 5.0.2.
Using a VM to test the application before deployment
If you have a lot of differences between the development machine and the target machine, I suggest you use an intermediate machine before putting the application into production.
A simple way to do this is by using a VM (Virtual Machine) that has exactly the same settings as the production server. That way you do not risk the application in an environment in the “real world” just to test their impact.
You can also use a sandbox within your main server, but do not recommend you do that. Better to leave well separate things.
And then? What I choose?
I sincerely hope that by now you already have enough information to make your choice. If you do not, I think it would be a good idea to research a little more about it on Google.
If you want to know my recommendation for the choice of an environment to host your application, I suggest Linux for all the facts cited. Even if you want to use a VPS, learning Linux commands will only further contribute to your career and development as a professional.
Did I missed something? You want to suggest any improvement? Leave a comment.
Note:
If you are looking for Managed VPS Hosting that is isolated from other users on the server, We provides you with everything for which you have been waiting for. Our hosting is built on a blazing-fast SSD latest hardware That’s Highly tuned for optimum performance. The hosting includes daily backups, anytime money back, 99.97% uptime and 24×7 support.