Many of the most popular websites and CMSs will benefit significantly when you switch from PHP 5.6 to PHP 7—performance increases of over 100% are often possible with PHP 7. WordPress websites, for example, run more than twice as fast with PHP 7!
How does PHP 7 boost your website’s speed?
PHP 7 achieves an enormous increase in speed through improvements to the Zend Engine, opcode caching as well as an improved data structure, which reduces memory requirements and ensures more efficient memory management.
Usually, PHP scripts are compiled at runtime. In this process, part of the computing time is needed to convert the code. With OpCache, this calculation is only performed once, and the pre-compiled, machine-readable (calculated) script is saved in a cache. The script can be loaded from this cache at lightning speed as needed. In most cases, this significantly improves the speed.
Large websites in particular can handle a considerably larger number of requests at the same time when OpCache is enabled—this is especially important for company websites and e-commerce.
A few things to consider before you switch to PHP 7
PHP 7 is generally very compatible with older PHP versions. Nevertheless, we recommend testing websites, plugins and scripts with PHP 7 before employing PHP 7 in live systems.
Example: The introduction of type hints and the now-reserved words “int”, “string” and “float” is currently causing problems for certain CMSs. For instance, version 3.4 of Joomla! is not compatible with PHP 7 because the type designation “string” is used in a manner that is not permitted in PHP 7. The Joomla! community has since corrected this usage and will publish a compatible version, Joomla! 3.5, at the beginning of 2016.
Activating PHP 7 in the 1&1 Control Panel
You can activate PHP 7 for each domain individually and quickly switch between different PHP versions as needed. To activate, select Configure PHP version next to the chosen domain in the 1&1 Control Panel.
Activating OpCache for your websites
Once you have activated PHP 7, you can activate OpCache for your websites. To do this, you create a new folder in your webspace to store the cached files and add some lines to the php.ini in the root folder of your website.
Create a folder for the cached files
Log in to your Webspace using SFTP and create a new folder for the OpCache files in the root directory of your webspace.
Important: To protect the data inside the OpCache, please always create a folder starting with a point. The Apache webserver will automatically protect this folder.
Something like /.opcache will work fine.
Please note: In the next step, you will add a link to this new folder to the php.ini of your website. For this link you must use an absolute path. You can learn how to find the full path to your webspace in the 1&1 Help Center.
The path should look like this: …/homepages/mypath /htdocs/.opcache
Adjust the php.ini
- Open the root folder of your website using SFTP.
- Open the php.ini file.
- Add this content to your php.ini:
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=2; opcache.max_file_size=0; opcache.file_cache= .../homepages/mypath/htdocs/.opcache; opcache.file_cache_only=1;
Please note: For opcache.file_cache= please adjust the path to your opcache folder to use the absolute path to your webspace.
- Save the php.ini file and upload it to your webspace.
Verify if OpCache is working correctly
After enabling OpCache for your website and accessing the website for a few times, you will find that the /.opcache folder in your webspace will contain new (cached) files. This confirms that OpCache is working for your website.