How to edit php files properly
Someone suggested a change to one of our php web pages, so I vi'd the file, commented out the two lines he wanted changed, typed in the two almost identical lines, then saved. Now when I go to load the php page, it doesn't load!
Did I do something wrong or very bad? Even if i comment out the lines i added and uncomment the two old ones, it still won't load. |
/var/log/apache2/error_log is your friend (location of the file may be different on your system)
|
Thanks. It seems like whenever I try to comment out individual lines with two slashes, that's what kills it. I just removed the stuff for now to avoid chaos. I'll have to add them back in then see what the log says. Thanks!
|
Maybe. Happens to me too... It is possible that when the file was edited you might of changed something else besides those particular lines. Check the error log files.
|
Thanks. It's very weird. I take out those 2 lines I added in, it doesn't load. I delete the two slashes before the two lines that I commented out, and it loads again. it doesn't like my slashes. I'll have to fiddle with it some more when I get some downtime on that system. Good to know where to look though. Thanks.
|
Regarding comments:
// instead of this ## use this |
OK, I'll give that a try too. This php file is littered with // though, so I'm not sure why mine wouldn't work. it did accept the /* */ to comment out the two lines though. Very odd.
|
php for websites often switch in and out of php on the fly. You can switch out of php and into regular html with a
Code:
?> Code:
<?php |
That's an interesting little tidbit. And I wonder if that might have been the case. and I see an error in my original post, I believe it actually just loaded a blank/all white page, it didn't "not load" as in "this page can't be found" type warning, so maybe it was telling me the html was busted so it skipped all the other stuff.
|
I use phpedit. It is fairly lightweight and includes a php syntax checker. No more unbalanced quotes or parenthesis.
|
Thanks for the suggestion.
|
Simple idea: after editing, try the file with php-cli:
Code:
$ php somefile |
I like simple :-)
So does that essentially just validate the syntax, or does it do other stuff to the file as well? |
Something else that you ought to be doing is ... source-code control! :eek:
In other words, you make the change to the file, and then you "commit" a branch containing the change into the source-code control system (say, "git"), tagged to the particular trouble-ticket or work-order that prompted the change. You then "check out" that branch onto a test server, and thoroughly validate the change. If the change is good, it's merged onto the appropriate test-branch (and validated again). In due time, the test-branch is merged into a branch off of production corresponding to a "release candidate." The only way that the production files can get changed is by "checking out" a particular approved release-candidate branch onto that server. Files are never changed directly, and the "correct state" of the server always corresponds exactly to a particular branch and a particular tag within that branch. Thus, the server can always be reverted to any other known good state in a matter of milliseconds. |
Thanks
|
All times are GMT -5. The time now is 07:56 PM. |