Updating for Dynamic Web Sites for PHP7 and MySQL
This article applies to: Academic Websites (Dynamic)
New Academic Web Hosting Environment
The new Academic Web Hosting Dynamic server provides a Linux/Apache/MySQL/PHP (LAMP) web hosting environment. As part of the migration to the new server, the software supporting the service has been updated to more current versions as outlined below.
We recommend upgrading your PHP applications or rewriting them to use the options provided by new versions of PHP as soon as possible.
Update PHP and MySQL on Your Website
Many of the sites hosted by the academic web hosting dynamic service use the PHP programming language and are supported by the MySQL database engine.
Many websites hosted by the service still use an older set of PHP MySQL functions which was removed from the PHP programming language with the release of PHP 7.0.0 in December 2015. We kept an older version of the PHP programming language installed on the service to support this. However, this older version is not available on the new web server.
Short-Term PHP MySQL to MySQLi Solution
In general, the MySQL database API compatibility can be done by replacing "mysql_" with "mysqli_" for all database API function calls. There may be a few remaining constants that will also need to be replaced. The academic web hosting support team has provided a short-term solution for customer websites relying on the older PHP MySQL extension as described below. We still recommend upgrading your PHP applications or rewriting them to use the options provided by new versions of PHP as soon as possible.
The short-term solution relies on a 3rd-party PHP extension called "PHP MYSQL to MySQLi."
On customer websites which we identified as relying on the older PHP MySQL extension, we deployed the short-term solution detailed here.
The long-term solution is for you to replace the old deprecated MySQL database API with a newer MySQL database API. Function calls for the old deprecated MySQL database API can be identified by finding functions that start with
The simplest solution is to replace the old
mysql_ function calls with the newer mysqli database API. You can do a global search and replace of
Depending on the complexity of your code, you may need to replace PHP constants that are part of the old deprecated MySQL database API. You may also need to update database object constructor calls to use the newer PHP7 constructor format. See Other PHP Changes.
Some other alternatives are to change your code to use the PDO database API, or to use a third-party PHP database library.
How to Determine What Needs to be Fixed
You can check to see if your website is compatible with PHP7 using a tool like PHP 7 Migration Assistant Report (
php7mar). It generates a list of lines of code that need remediation for each file on your website. How to Check if Your Application is Compatible with PHP 7 explains the process.
Run the compatibility report before making code changes to determine what needs to be fixed. Then, run the report again after you make your code changes to verify that they took effect.
If you need help with running PHP7 compatibility reports, please contact firstname.lastname@example.org
Other PHP Changes
The change to how PHP handles MySQL was not the only change to PHP in recent years. You may need to update other parts of your PHP applications as well.
Documentation on how to upgrade PHP applications from older versions is also available.
Changes to Security Configuration
For customers who rely on Cornell NetID authentication for their sites, we have modified the .htaccess configuration files to work with Apache HTTPD 2.4 and to work with Cornell's new WebSSO solution. Additional information:
- Details on changes required to adjust .htaccess configuration for Apache httpd 2.4
- Details on changes required to adjust .htaccess configuration for WebSSO