Solved

DOS formatted PHP files processed as plain text, other files processed normally. Why?

Posted on 2014-04-01
6
469 Views
Last Modified: 2014-04-01
I've moved approximately 100 PHP files to a new LAMP server.  When the PHP files are called they are not processed, the code prints out as plain text.  If I create a new PHP file on the new server and copy/paste the code, it processes fine.  

When I open up the PHP files on the new server or the old server, with nano, I receive a notification "[  Read ## lines (Converted from DOS format).  ] "

What's going on here?  Why can't my new server handle these files?

New Server
RHEL6.5 Santiago - 64Bit
Apache 2.2.1
MySQL 5.1.73
PHP 5.3.3
0
Comment
Question by:ZergRush
6 Comments
 
LVL 23

Accepted Solution

by:
savone earned 165 total points
ID: 39970921
Try running the files through dos2unix.

http://linuxcommand.org/man_pages/dos2unix1.html

If you do not have dos2unix installed, just yum it.

yum -y install dos2unix
0
 
LVL 34

Assisted Solution

by:gr8gonzo
gr8gonzo earned 165 total points
ID: 39971165
Check to see if your php files start with <? or <?php. If your new server doesn't have short tags enabled in the ini, then the first / shorter tag won't get treated as valid PHP.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39971398
What @gr8gonzo said is the most common cause of that problem.  I don't believe that the PHP interpreter cares about \n or \r\n line endings in the code.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:ZergRush
ID: 39971414
I've run the files through dos2unix. The converted files no longer display the "Converted from DOS format" notice in nano but are still printing as text.  The files I am testing with contain only "<?" and "?>".
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39971422
"<?" is a 'short_open_tag'.  Try changing it to "<?php" and see if your files work.
0
 

Author Comment

by:ZergRush
ID: 39971451
My mistake, gr8gonzo was right, I read that wrong.  I'll change the ini.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question