Differences between local and remote servers - php

I am developing a website with Lumen framework.
Everything is configured and works perfectly locally. However, this is not the case on the remote server.
Examples:
When I recover a data from my database, even if the column contains only integers, the result in local is integer, but in remote : string. I have to specify (int) before the integer values to be sure they are integer.
Locally, all my classes belong to namespaces. Everything works locally and in remote, sometimes I find myself with Class 'blabla\blibli' not found
Locally, I use Xampp (PHP Version 5.6.14, MySQL version 5.0.11-dev) and remove, I am on a shared server OVH (PHP Version 5.6.15, MySQL version 5.1.73).
Have you ever been confronted with that? Is there a way to fix this? May be a configuration file to write?
EDIT : Given the comments below, it seems that the answers to my questions actually depends on the operating system use.
Locally, I am working on a Windows machine, while in remote, it is a machine running Linux. Windows seems less of a hassle with certain rules, such as case sensitive.

When I recover a data from my database, even if the column contains
only integers, the result in local is integer, but in remote : string.
I have to specify (int) before the integer values to be sure they are
integer.
This happens because PHP doesn't know how to interpret the query result. There is no information on how to interpret column values. To fix that and to have correct type representation in PHP, you must have MySQL Native Driver installed (mysqlnd).
Here's a link to documentation page that explains how to do it.
Locally, all my classes belong to namespaces. Everything works locally
and in remote, sometimes I find myself with Class 'blabla\blibli' not
found
As per comments, it appears you're developing on one OS and deploying on another OS. Since Windows are actually MUCH MUCH WORSE than Linux (and this isn't me being a fan of Linux, it's a simple fact), they tend to forgive a lot when it comes to case sensitivity and what not.
Windows being forgiving for such things doesn't mean they're better or that there's less hassle with Windows (from a sys admin POV, Windows are a nightmare). It just means that you can't be lazy and expect OS to forgive everything and guess how you intended your code to work.
Be consistent
Set your development environment to match your deployment environment. You can use virtual machines for that. If you prefer developing under Windows, you can use Oracle Virtualbox to run a Linux OS, set up Samba and in Windows you can map a Linux drive. That lets you run your IDE under Windows, and all the code is saved to Linux box. Your web server and php should run under Linux and you can access it via your browser that runs under Windows
Set up tests. Run them before you deploy. That will tell you whether you might have missed or omitted something
Be consistent
Good luck.

Related

Remote Symfony2 + Netbeans workflow (feat. git)

I'm hoping someone have encountered this problem before and will be able to help
So, the problem goes like this: There's 2 developers, each one of them needs 2 versions of a website (development + production). Due to very different operating systems, triple configuration difficulities and administration restrictions on them it's impossible to run projects locally. But there's a bunch of problems while running them remotely:
How to run Symfony2 CLI commands in Netbeans (since those commands need access to db)?
How to differentiate between production/development? I have allowed external access to db for 2 IP addresses, but theres only one parameters.ini file. And once it's used to connect to localhost (when run by http), and second it's used to connect via remote host (when CLI command is run in netbeans)
More info you may ask, so here it goes:
Dev #1: Kubuntu 12.04 x64 3.2.0-25-generic NB#7.1.2
Dev #2: Windows 7 x64 NB#7.1.2
Server: Ubuntu Server 12.04 x64
SQL: PostgreSQL
webserver: Apache2
Our workflow now looks (or at least should look) something like this:
Dev #1 does something locally, but on run changes are being moved to the server so he can check how it went on beta1.sitename.com.
Each change is commited to user branch in git when suitable.
After testing changes are baing merged to master, tested, pulled to a sitename.com, and then tested again.
After this the cycle repeats :)
PS. Valid answer would also be a hint how proper workflow in that kind of situation should be. I've tried already with post-* git handles, and it didn't work really well either...
First of all I would highly recommend trying to solve the development machine issue. There is vagrant which can be used together with chef or puppet (or a specialiced virtual base machine) to move the development environment into a virtual machine executed on the developers pc. This would also solve many issues regarding the remote server.
If this cannot be done, here are some thoughts:
Netbeans commands won't work remotly. Have your developers ssh into the machine and execute their commands their.
I don't get your development/production environment problem. Their should a at least on virtual host with different config/cache/logs for each developer so the configs can be set correctly. The parameters.ini should not be in your git repository (You can handle this by creating a parameters.ini.dist and ignoring the parameters.ini file) so you can have different parameters.
Another interesting thing (presented on the symfony live 2012 Paris) is that you can do SET_ENV SMFONY_PARAMETER_NAME inside your apache vhost and then use %parameter.name% inside your config files (mind the two underscorse). This could be usefull in your case.
There really is no workflow I know of which could handle multiple developers on one machine with different configs and the like. It's just a mess and you either solve your problems with complex scripts which are run everytime something happens or by finding a better solution like virtual machines or different vhosts with different directories on your servers.

how to make xampp environment behave the same as my remote shared hosting environment?

i don't know how to say that in technical terms. and i think this is the reason to why i cant get good answer from Google.
i have xampp on my local winxp machine. i use it for developing websites locally then upload these files to my clients shared hosting accounts.
the problem that in 2 years i have always found differences between how xampp works and how the web server work.
some code work locally but dont remotely and the opposite. also flash behave differently on xampp than the remote web server.
is there is a way i can get the server configuration and use it with xampp like get the server php.ini and use it with xampp?
In fact XAMPP may behave different than your production system's web server.
This might be annoying at first, but it is definitely manageable.
Some thoughts:
Run
<?php
echo phpinfo();
?>
on both systems and check different features.
If a feature of PHP is marked as experimental, just drop it.
In case you need to deploy on different production servers, prepare a script called grabProperties.php and add code which checks essential properties you know to be in use. Output the result in some normalized way, so you may use another script to compare results and prepare a nice report.
Certain features activated in XAMPP are not enabled on most web hoster's server - e.g. Flash support. Before using these features, first ensure they are present on your production system.
You are always free to change php.ini. Thus, you may enable or disable modules in such a way, that you dev system mimics your production system's settings.
I wonder, that Flash problems relate to PHP itself. More likely, problems relate to erroneous code.
That said...
I do write PHP for quite some time. Upgraded XAMPP on dev and Apache/PHP/MySQL on production system several times. But not a single application failed to work after the upgrade.
Several times, I moved from dev Windows and production Linux to dev Mac OS X. Even there, everything worked fine immediately.
Needless to note, that not a single line of code needs to be changed between dev and prodution systems.
The essential point to to write high quality code is based on a defensive style.
Check as much input parameters of as much methods as possible (see assert()).
Log all errors to a log-file and visualize it using your admin backend (see set_error_handler()).
Use type-hints as often as possible (see type-hinting)
Set the maximum error level and code in such a way, that not a single warning appears.
Still unsatisfied?
In case you are still unsatisfied with XAMPP, prepare a virtual machine with VirtualBox, install some Linux edition and enable apache, mysql and php.
If your hoster's server is on linux - which is very likely - there should't be a big problem configuring the virtual LAMP server in a similar way.

Organizing PHP development in a team (environment, configuration, etc)

We've been battling this problem for some time now, and can't seem to find a perfect solution that would satisfy all the requirements of making life easier for developers.
Right now we have the following setup:
Linux development server (as everything we produce runs on linux, and it uses some linux-specifix libraries)
Windows desktops (as the office network is on windows)
Every developer has a home folder on the dev server with a virtual host set up to run their code. This folder is shared using Samba.
Zend Studio IDE that is set up to use that location (as a network drive) to work on projects
Remote debugging to be able to run applications on the dev server and be able to step through the code
So the main problem we are having is that everything is slow...
Zend is slow to index the project, as it has quite a bit of files (including externals like full framework) that need to be transferred through SMB.
Remote debugging is slow, as Zend studio needs to fetch the file, then send it back to the server to run it (running "Local if available, else server"; otherwise breakpoints don't work)
Tortoise SVN is slow to get file status for the commit (command line remedies the problem, but it's much less user friendly, especially with more complicated things like conflict resolution while merging)
Branching out to any of the solutions that would have multiple server configurations brings up a problem that there is a chance of having different configurations everywhere, which will introduce additional layer of uncertainty and possibly bugs in production.
Development and debugging under windows is not possible because of linux dependencies in the code (like POSIX functions).
So how do organizations solve these problems? What kinds of set up are you using? What kinds of problems are you facing, and how to you resolve them?
One solution that works in some situations is to :
Have the code on your local disk, on the physical computer running windows
This code is the one you're modifying with your IDE
So, IDE is working as fast as possible : no SMB access for each file.
Also have the code on the Linux server
So Apache runs fast : the code is present on the server
Use some kind of synchronisation mecanism, to push every modification made on a file on the Windows machine to the Linux server, via the SMB share.
Using Eclipse, the FileSync plugin does a good job, over the SMB share.
WinSCP can also be used, to keep a remote and local folder synchronized, over an SSH connexion
Advantages :
All local operations are fast
All server operations are fast
Drawbacks :
You must always use the tool that ensures synchronisation (For instance, with FileSync, everything must be done in Eclipse -- and nothing in any other software)
Note : for SVN, no need to use Tortoise : there are plugins that integrate into Eclipse (Subversive, for example)
Not sure about debugging
Modifications done directly on the Linux machine might not (depending on the solution) get synchronized to the windows desktop.
Still, the best (fastest and most powerful) solution is generally to use only one computer -- that would run Linux, in your case, and not Windows.
Your tools will most likely work under Linux
If needed, you can install Windows in a Virtual Machine, for some software that don't run on Linux
It'll encourage everyone in your team to know Linux better ; which is always useful, when your production environment is not Windows ;-)

Quickest way to run a linux dev-environment inside windows

I get more and more trouble from running WAMP on my XP computer to solve my local development needs. It feels like as more and more things just go wrong or could not be installed at all to a Windows version of PHP.
I have been looking for an alternative and found AndLinux plus this link.
Would it be a good idea to get an Ubuntu box running virtually on my XP computer to simulate the production web server?
Yes, in case you don't want to use Linux as desktop OS running it virtually in a VM is quite practical. by using the VM's "shared folder" support you can use the same directory for local development using your Windows IDE and serving requests from the Web Server inside the VM.
In the past - ~5 ears ago or so - I used coLinux and wasn't too happy. On modern systems a small Linux VM just works well.
Regarding virtual machines:
Advantages
Isolation: Everything in the VM is completely separate from the host; no cross contamination.
Easy Testing: Most VM software have snapshot and rollback capabilities.
Mobility: If you wanted to, you could easily move the self-contained VM over to another machine.
Disadvantages
Inconvenient: File transfer between the host and guest. Using "shared folders" alleviates this somewhat.
Virtual Hardware: Not good for graphics-intensive programs or other software that relies on certain hardware features (which shouldn't be a problem in this case).
Generally speaking, the closer you can get to the production environment the better. Developing on Windows isn't wrong, per se, but you need to be able to test in an environment which matches production.
If you have the resources on your PC to do it in a VM, that will work just fine. If you don't, running it natively or using a remote server somewhere would also work.
Hope that helps!
Thanks,
Joe

Cross platform PHP caveats?

I've been given an existing PHP application that was originally deployed on a LAMP host.
Because most of our team are .Net developers, our boss wants it deployed in a windows environment.
Is it madness to expect this to just work?
Here's some additional info of the LAMP host:
Linux 2.4.32
PHP 5.2.6
No non-default modules
In my experience, it can be done and works fine.
The most important things I'd keep in mind are:
Use Apache on Windows, don't use IIS (even if it's possible)
Make sure you use unix style slashes for directories. Those work on both platforms.
Be very careful with case sensitivity. Since Windows is not case sensitive (though it is case preserving), if you include a file and spell it with the wrong case, it will work on Windows and fail on Linux.
Heck even just migrating from one hosted server to a different one usually requires SOME tweaking and adjustments. I don't imagine having to do it in a Windows environment would be much different. I was invloved in the migration of a large PHP app just last week and we (3 people) were able to get things going in about half a day.
It depends what's being done in the application. Two areas to look into though are where the app looks for files in the file system (using Linux specific paths?) and finding windows builds of any php modules (from PECL in particular).
Be very careful that at no point is exec called. A lot of extremely lazy code is written that will use this, and for obvious reasons it may not port well.
Some what i've experienced over the years:
Too old/new DB driver for PHP
Path problems
Change from 32 bit to 64 bit system or vice versa affects PHP internal integer handling (bit calculations returns weird results suddenly)
Locale and localization issues
Missing functions (manual have usually notes that it won't work or behaves differentially in windows)
File name casing
And always check and double check that Apache modules and PHP modules are atleast the same version as in old system.
It's also not too bad to run GNU/Linux virtualized on top of Windows with for example VMWare if code doesn't seem to like running in Windows.

Categories