Solved

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

Posted on 2014-04-01
6
465 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
Comment Utility
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
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:ZergRush
Comment Utility
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 82

Expert Comment

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

Author Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now