With a market share of more than 80%, PHP is the go-to scripting language for many programmers when it comes to creating dynamic content. Whether you’re operating your own weblog, running an internet forum, or designing an online shop, it’s likely that the software behind this will be written via PHP. Our PHP tutorial for beginners will introduce you to the basics of the popular scripting...Learn PHP: a PHP tutorial
PHP 7 accelerates many dynamic websites by over 100% compared to PHP 5.6 through OpCode caching and an optimized Zend engine.
A higher page speed leads to faster page load and an improved user experience for your website visitors. At the same time, improved speed is a relevant factor in Google rankings of your website.
Not only the page speed has an impact on your Google ranking. Learn more about search engine optimization (SEO) in our A to Z on search engine optimization.
SEO with rankingCoach from IONOS!
Boost your Google ranking by optimizing your website without prior knowledge!
Speed improvements in PHP 7
PHP 7 achieves the enormous increase in speed primarily through improvements to the Zend Engine, extended OpCode caching, an improved data structure and thus reduced memory requirements and more efficient memory management.
How OpCode Caching Works
Normally PHP scripts are compiled at runtime. Part of the computing time is required to convert the code. With OPcache, this calculation is performed only once and the precompiled, machine-readable (calculated) script is stored in a cache. The script can be loaded from this cache at lightning speed if required. In most cases this leads to considerable speed improvements.
Larger websites can handle many more requests simultaneously with OPcache activated which is an important advantage for corporate websites and eCommerce applications.
Preparing to switch to PHP 7
PHP 7 offers very good compatibility with older PHP versions – so the probability that existing applications and scripts will work is high. However, we recommend testing websites, plugins, and scripts with PHP 7 before using PHP 7 in production environments.
Here is an example: The introduction of type hints and the words “int”, “string”, and “float” reserved for the first time still causes problems for certain CMS at the beginning. Joomla!, for example, is not compatible with PHP 7 in version 3.4 because it uses the type name “string” in a way that is not allowed in PHP 7. The Joomla! community has meanwhile corrected the use.
IONOS customers can view or change the PHP version for each domain individually in the PHP settings of the IONOS Control Center.
Changing the PHP version usually takes a few seconds to a minute. We recommend that you test your scripts after the change. You can undo the changes in your PHP version at any time.
Enable OPcache via php.ini
After switching to PHP 7, you can enable OpCode Caching (OPcache) for your websites. You have to create a new directory for the cache on your online storage and adapt the php.ini in the root directory of your website.
Creating the Web Space Directory for the cache
Log in to your online storage via SFTP
Create a new directory in the root directory. In the future, the cache for your websites will be stored in this directory.
Please note that in order to protect the data in the cache, you must create a directory with a leading point (e.g.: ../.opcache). This directory is then automatically protected by your Apache web server.
Store absolute path in php.ini
In the next step you have to enter the absolute path to the created .OPcache directory in php.ini.
The path should look like this: /customers/websites/my-path/htdocs/.opcache
Open the main directory of your website via SFTP and open the file php.ini.
Add the following entry here:
Please note: Use the absolute path to your .opcache .OPcache directory under opcache.file_cache=.
The entire content of php.ini should look like this after this step.
zend_extension=opcache.so; opcache.enable=1; opcache.memory_consumption=32; opcache.interned_strings_buffer=8; opcache.max_accelerated_files=3000; opcache.revalidate_freq=180; opcache.fast_shutdown=0; opcache.enable_cli=0; opcache.revalidate_path=0; opcache.validate_timestamps=1; opcache.max_file_size=0; opcache.file_cache=/customers/websites/my-path/htdocs/.opcache; opcache.file_cache_only=1;
Save the php.ini file and upload it back to your online storage.
How to check if OPcache is active for your website
After you have activated the OPcache for your website and accessed it a few times, you can simply check whether the cache works correctly.
Log on to your online storage again via SFTP and open the directory ../.opcache you created earlier. You should see the cached content of your website in the directory.
SSL certificates from IONOS
Protect your domain and gain visitors' trust with an SSL-encrypted website!
PHP 8 was released at the end of 2020. Unlike PHP 7, the new PHP version uses a just-in-time compiler, which boosts performance a little compared to OPcache.