LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to edit php files properly (https://www.linuxquestions.org/questions/programming-9/how-to-edit-php-files-properly-4175512606/)

anon091 07-29-2014 08:01 AM

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.

NevemTeve 07-29-2014 08:41 AM

/var/log/apache2/error_log is your friend (location of the file may be different on your system)

anon091 07-29-2014 08:42 AM

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!

michaelk 07-29-2014 08:46 AM

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.

anon091 07-29-2014 08:49 AM

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.

NevemTeve 07-29-2014 09:36 AM

Regarding comments:

// instead of this

## use this

anon091 07-29-2014 09:39 AM

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.

suicidaleggroll 07-29-2014 09:49 AM

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:

?>
and then switch back to php with
Code:

<?php
"//" is a valid comment in php, but not in html. Maybe the problem is you're in an html section of the code and are trying to use "//"? Although I'm not sure why /* */ would work in that case.

anon091 07-29-2014 09:56 AM

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.

pwalden 07-29-2014 02:30 PM

I use phpedit. It is fairly lightweight and includes a php syntax checker. No more unbalanced quotes or parenthesis.

anon091 07-29-2014 02:38 PM

Thanks for the suggestion.

NevemTeve 07-29-2014 10:42 PM

Simple idea: after editing, try the file with php-cli:
Code:

$ php somefile
if you have syntax errors, it will tell you

anon091 07-30-2014 07:39 AM

I like simple :-)
So does that essentially just validate the syntax, or does it do other stuff to the file as well?

sundialsvcs 07-30-2014 08:48 AM

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.

anon091 07-30-2014 09:03 AM

Thanks


All times are GMT -5. The time now is 07:56 PM.