r/PHPhelp • u/oneyozfest182 • Jun 02 '17
PHP 5 Website Updating to PHP 7 - 500 Internal Server Error
Total PHP newb here, and learning more daily, but an old friend who is no longer accessible helped make a site for me many years ago, back in the PHP 5 days, and now after PHP 7 is out and 5 is losing support, I was forced to update to PHP 7 for some of my other sites on the shared hosting, but now that one old site is completely broken and I was wondering if anyone might be able to help me out with getting it running again on PHP 7. :( Thanks in advanced for anyone willing to help.
1
u/damiankw Jun 02 '17 edited Jun 02 '17
Depending on the site this is no small task. Go through and enable all warning/errors on the php server and wait for it to bring up errors about your site, look at all of the logs.
I went through a similar thing recently with a website for work, went from 5 to 7, pretty much everything core broke and I had to update the code. LDAP connectors, MySQL connectors, SQL Server connectors all had to be updated, which meant editing every single page.
Yours may not be as bad at all, but without knowing what code it uses its going to be hard to help you out :)
1
u/oneyozfest182 Jun 02 '17
These are the errors I get with error reporting on:
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; MySQL has a deprecated constructor in ../public_html/htp/store/includes/dbhandler.php on line 32 Fatal error: Uncaught Error: Call to undefined function mysql_connect() in ../public_html/htp/store/includes/dbhandler.php:61 Stack trace: #0 ../public_html/htp/store/includes/dbhandler.php(51): MySQL->connectToDb() #1 ../public_html/htp/store/index.php(35): MySQL->MySQL('OMITTED', 'OMITTED', 'OMTITED', 'OMITTED') #2 {main} thrown in ../public_html/htp/store/includes/dbhandler.php on line 61Please note the errors do give me full paths, but I replaced the beginning with ../ just to make the error reports shorter and easier to read here.
2
u/greg8872 Jun 08 '17
Additionally to mysql_ based functions going bye bye (finally!):
Methods with the same name as their class will not be constructors
it used to be you could do the following:
class Whatever { function Whatever() { // Things done when an instant of the class is created } } $we = new Whatever(); // creates an object and does anything in the above functionNow you need to specially use
__constructinstead ofwhateverto contain things that happen when creating a new object. Look though all your code for anything that defines a class, and anywhere in the class there is a function defined by the same name, change it to__constructsuch as:class Whatever { function __construct() { // Things done when an instant of the class is created } } $we = new Whatever(); // creates an object and does anything in the constructor function
2
u/[deleted] Jun 02 '17
Requires some fiddling and command line experience but if you can you should scan your code with phan PHP7 backwards compatibility flags:
https://github.com/etsy/phan/wiki/Incrementally-Strengthening-Analysis#just-backward-compatibility
and fix the reported bugs.
Good luck.