"Old" php scripts don't work in fresh installed LAMP

Hello, I hope I choose right forum to ask this question. Couple of the days before, my system (OpenSuSE 13.2 KDE) crashed, no matter why. I have had LAMP, configured with Yast-pattern. Everything worked just perfect, but I made backup of my php scripts that made my little web application. When my system crashed, I reinstalled it, and wanted to bring my php scripts back in folder they have to be. After I brought them back in … htdocs, no one worked! I made one test-script to see if php installed right - it worked! Why old php scripts not work? I also tried to copy/paste some of the old: html parts (included) worked, but php again - not! Why? What is wrong?

Since I said I installed LAMP using YaST pattern, you can conclude that I use last stable versions phpmyadmin, php and mysql programs. My linux is 32-bit.

Thank you for answer my question.

When I say: “no one worked”, i think it is white screen and script doesn’t work what id did bebore.

Old php scripts often use short open tags, meaning they started with <? hurpderp; ?> which is nowadays not enabled by default in PHP, instead they use <?php hurpderp; ?>

So, edit /etc/php5/apache2/php.ini and find short_open_tag and enable it ( short_open_tag = On ), then restart Apache2.

Or, when this is the case, better change your scripts to the new way of doing this (already for years). It can always happen that this workaround is removed one day in the future.

Maybe I didn’t be clear: script worked on the same operating system, they were back up on home folder also, so when I reinstalled system, I just copied and pasted folder with that scripts. Nothing more happened. “New script” is test script to see if I set server right. Scripts made on reinstalled OS work, but those I restore from back-up folder don’t. By the way: I did the thing you suggested (to enable one thing), and nothing new happened. What to do next?

Thank you for answer my question.

It’s hard to say, perhaps you are missing a php module or there are permission issues.

I would start by looking at **/var/log/apache2/error_log **for errors and enabling PHP debugging; edit /etc/php5/apache2/php.ini and find: display_errors and enable it, then restart Apache2.

It should now output any php errors to your browser when you open one of the pages that used to work.

When I understand you correctly, you copied the scripts from somewhere in htdocs to someones home directory and later you copied them back? I do not know which user did the copying, but did you at least check of ownership and permissions are now correct? You could e.g. compare with your “new script”.

Scripts were in my htdocs folder and i wanted to save them from erasing (destroying) that would happen during reinstalling of system. I copied scripts from htdocs in my computer to home folder of my computer. After reinstalling, I got scripts back to htdocs folder.

No, I did not check ownership. What is that I have to know about it? I don’t know how to check, change ownership…

Thank you for answer my questions.

Who did copy it and how was it done. Saying “I copied” is of no value because the computer does not know any “I”. The computer has users, known by a username (and identified by a userid).

And the actions you describe should either be done by the user that belongs to the role of web manager, or by the superuser (root). And in the last case, root should take care to preserve file ownership and permissions.

To check, as root, please go to the directory where those scripts are and display the information of the “new script” and of one of the old scripts (to compare). That goes something like this:

su -
cd /srv/www/htdocs
ls -l name-of-old-script
ls -l name-of-another-script
exit

For you to fill in the correct names of course.
You may post that here for advice.

As I already said, I made one script just to test if php works. It is very simple script. phpinfo.php (everyone knows what is in it). So:

  1. when I put the name of php test script (originally written, not copied), that works correctly, by the way), output of your suggested line is:

-rw-r–r-- 1 root root 22 Apr 26 09:19 phpinfo.php

  1. When I apply your suggestion on some script copied from backup folder, output is:

-rw-r-----+ 1 root root 248 Apr 23 20:18 mysqli_connect.php

What to do? Thank you for answer my questions.

Well, apparently you lost the read permission for the world. And as normally Apache is running as user wwwrun (thus not user root) and group www (thus not group root), it is not allowed to read those files.

Quick solution:

su -
cd /srv/www/htdocs
chmod -R a+r *
exit

It is not as I would like it, but most probably it was like this all the time, so be happy with it.

And as an afterburner:
Can you please use CODE tags around copied/pasted computer text in a post. It is the # button in the tool bar of the post editor. When applicable copy/paste complete, that is including the prompt, the command, the output and the next prompt.

And as a suggestion:
When you realy are managing a Linux system, specially as it is more then just a single user PC like this one with a web-server running, try to find documentation about the basics of Unix/Linux. You should know about file ownership and permissions. There is more then enough about this on the Internet.

Regards,