Changing any PHP line gives error 500 (server)

Asked

Viewed 119 times

3

Colleagues.

I have serious problems with a certain server, which only happens with it. We have a system from which we changed the directory and all the links are working perfectly and are in the root directory of the server. We moved from 2016 to 2017, but two weeks ago, any line we moved or even commented, gives error 500, to the point of deleting all the code and leave only:

<?php
echo "OK";
?>

After numerous searches, I came across a forum where asked to open Notepad++, view all characters and see if the code appears LF, and may also appear LF and CR. The old directory pages appear this way:

inserir a descrição da imagem aqui

And in the new directory where we migrate the system and is giving this problem:

inserir a descrição da imagem aqui

How can I fix this? The server where the files are allocated is Linux.

  • Any line regarding error_log?

  • 3

    Looks like a coding error. I’m not sure bad try to create a new file to test because it might be the encoding used when creating with an editor this conflicting with a new editor (or different encoding in the same editor). If a new (test only) file created in an editor UTF-8 run this there the problem otherwise may be the PHP or in the system.

  • 1

    You are going up the files via FTP?

1 answer

5


This CR means Carriage Return and LF means line feed, the LF is used to generate "new lines" (line break), the CR up to the Mac 9 was used as line breaking, but from the 10 (Mac OS X) started using LF, I believe that today all systems internally use only LF, only the Windows editor Notepad.exe still saved and reads line breaks like this "CR+LF" (formed by both), may be by backcompatibility, in fact this does not affect anything since LF be present shortly after the CR.

What I suppose is that your script when editing and saving is disappearing with the LF because it is using some configuration in the Notepad++, another possibility is that you are uploading the files via FTP with some configuration that is failing, it may also be because if the upload is in ASCII sometimes there may be loss of characters (if there is in the middle of the file some unsupported character).

Note that I am not stating that the CR be the fault on the Linux server, but I believe it can be directly or indirectly, so much so that in my Debian (a type of Linux) worked normally using only CR, that is it may be that the CR together with another character is that causes failure as can be another character that has been lost without any relation to the CR

Notepad++

Abra in the Notepad++ Settings > Preferences > New Document > Format (Line ending), thus:

new line

See if this selected CR LF or LF or CR, probably CR, if you’re trading for LF or CR LF, of course this may not solve the problem of files that have already been edited, so to fix this, do the following on Notepad++:

  • Make a backup of all documents
  • Open all files that you want to edit, that are not from the backup so that they stay in tabs like this:

abas

Then press Ctrl+H and something like:

replace

  • Select the option Extended (\n, \r, \t, \0, \x)

Now we’ll trade them all CR and CR+LF for LF only

  • Type in Find what: \r\l (to avoid conflict in the next steps)
  • Type in Replace with: \l
  • Push the button Replace All in All Opened Documents

  • Type in Find what: \r

  • Type in Replace with: \l
  • Push the button Replace All in All Opened Documents

In this case I only used the LF that is already enough for the case, but can do so (chance want CR LF):

  • Type in Find what: \r\l (to avoid conflict in the next steps)
  • Type in Replace with: \r
  • Push the button Replace All in All Opened Documents

  • Type in Find what: \r

  • Type in Replace with: \r\l
  • Push the button Replace All in All Opened Documents

Select the option in Notepad++ File > Save All (or Ctrl+Shift+S), ready now things should be fixed, even if it fails is because it is probably using FTP, in this case follow the next step:

FTP

If you’re using FTP Filezilla or similar maybe the upload via ASCII is making some character conflict and something gets lost, it can also be some configuration of the FTP itself, if it is Filezilla go to Edit > Settings... > Transfer > File Types:

filezilla

In Default transfer type change from Auto or ASCII for Binary and tighten OK, then try uploading again and see if it’s working.

Extra

Personally to work with PHP, despite being something totally optional, I prefer Sublimetext, since well configured, if you have any interest here I left some tips:

  • 1

    Perfect William Birth. Thank you very much for the clarifications.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.