Use PHP 7 with OpCache to boost your website’s speed

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!

php7-teaser-2016-02

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.

OpCache explained

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.

Activate PHP 7 in 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.

You might also be interested in

Please rate this post :

50 thoughts on “Use PHP 7 with OpCache to boost your website’s speed

  1. I had an issue configuring OpCache in my 1and1 server.

    I followed this article but drupal 8 kept saying opcache was disabled, and also php opcache_get_status() function returned enabled=false.

    I just fixed it by removing the last line that was supposed to be added to php.ini:
    opcache.file_cache_only=1;

    Hope it helps!

  2. joan says:

    I can’t find the “php.ini” file on my 1and1 ultimate account. Did you create a new one? could somebody explain me this, please?

    thanks.

    1. 1and1help says:

      Hello joan,

      The global php.ini is not accessible from your webspace. Following the instructions in the article, please create a new, custom php.ini and upload it to your webspace.

      Thanks and best,
      Michael, 1&1

  3. Ernie Cole says:

    I do not have a PHP.ini file anywhere in my files directories

    1. 1and1help says:

      Hi Ernie Cole,

      as mentioned above to joan: The global php.ini is not accessible from your webspace. Following the instructions in the article, please create a new, custom php.ini and upload it to your webspace.

      Thanks and best,
      Michael, 1&1

  4. Joseph Mason says:

    I changed this to PH7.0 and it does not work. I wish to remove the content in this domain and put something else there. How do I do it?

    1. 1and1help says:

      Hi Joseph,

      If you would like to remove the content of your website, you may delete the content in the folder where your website is pointed. You may then upload your new content to the same folder and your website will be updated with the new content. This does not directly relate to the version of PHP you are using or the php.ini file.

      If you would like to delete the cached content, you may delete all files found in the .opcache folder or whatever folder you configured. This content will be regenerated when your website is visited next.

      Best,
      Michael, 1&1

  5. Calah Gowdy says:

    Can I just have someone do this for me? I uploaded a theme to WordPress and tried to upload the demo content, but it told me this:

    max_execution_time: 30 *RECOMMENDED 180
    max_input_vars: 1000 *RECOMMENDED 2000

    I don’t feel comfortable making changes myself. I’ve already upgraded to PHP 7.

    1. 1and1help says:

      Hi Calah,

      you can change the value for “max_input_vars” in your own, local php.ini.

      Just put

      max_input_vars = 2000

      in the already existing php.ini file in your WordPress root path. [Edit: If this does not work- maybe into the php.ini in /wp-content/themes/ as well]

      The value for “max_execution_time” is given by the server and your tariff.. We can’t increase this number for you, sorry. But from my experience, most of the themes should also run smoothly with this setting. To achieve limits like the recommended 180s, you would need to switch to an own 1&1 Managed Server.

      Best regards,
      Michael, 1&1

  6. Vladimir says:

    Hi
    I updated to PHP v7 and get this error on my webpage: Database connection error (1): The MySQL adapter ‘mysql’ is not available

    I chnaged to PHP 5.5 and all works fine.

    I understand I need to change PHP.INI. How can I do that please?

    Thanks
    vladimir

    1. 1and1help says:

      Hi Vladimir,

      the ‘mysql’ function was removed completely with PHP 7. Please use ‘mysqli’ instead. http://php.net/manual/en/class.mysqli.php

      For PHP 5.6 ‘mysql’ still works but it is not recommended to use it anymore (deprecated since PHP 5.5). http://php.net/manual/en/intro.mysql.php

      So if you still need to use ‘mysql’, you might stay with PHP 5.6 for now.

      Best regards,
      Michael, 1&1

  7. Luke says:

    I updated to PHP 7.0, but now WordPress is telling me I must increase my PHP memory from 40M to at least 96M in order for my theme (Evanto Jupiter) and Visual Composer to work… Can anyone give me simple steps for this?

    1. 1and1help says:

      Hi Luke,

      the limit for PHP memory is set by the tariff you have. With 40M this seems to be a very old hosting package.

      You can achieve better limits with performing a tariff change in your 1&1 Control Panel: http://help.1and1.com/account-and-billing-c65577/orders-and-upgrades-c37675/switch-to-a-different-package-a598297.html

      For 96M or better, a tariff change into Unlimited Pro would be necessary.

      Best regards,
      Michael, 1&1

  8. Moeeza says:

    Hello.
    I Can not edit php.ini with fileZilla . Can you please help me !

    1. 1and1help says:

      Hi Moeeza,

      what exactly happens? The php.ini can be edited with a text editor like Notepad ++ or other plain text editor software.

      Best regards,
      Michael, 1&1

  9. Pat Read says:

    Hi. I am using PHP 5.2 as I found a year ago that moving to a higher PHP caused the search function to stop working on my website. How can I re-test out a higher PHP but having the option to go back and stick to 5.2 with extended support ? In the control panel there is only the option to switch between 5.5, 5.6 and 7.0. I am worried if I select any of the others in the control panel and find my search doesn’t work that I can’t go back to 5.2 again without waiting for days for support to change it. Our site is very important and I can’t have hours or days of search downtime. Is there any easy and quick way I can test a higher PHP ? But having the option to change it back myself to 5.2 instantly if I find search doesn’t work ? I am using Prestashop 1.4. I realise it is an old build but I have useful modules that don’t work with newer versions of Prestashop and it does everything I need for my older aged customer base.

    1. 1and1help says:

      Hi Pat Read,

      we only offer the older PHP versions from the settings in Control Centre, if the PHP Extended Support option for that specific version is existing in your contract.

      We can book the PHP 5.2 Extended Support with a monthly fee for you if you like. Simply contact us via e-mail (help@1and1.co.uk) with your costumer and contract id and mention this posting here.

      Best regads,
      Michael, 1&1

      1. Pat Read says:

        Thanks. I just did a check and my website is indeed using PHP 5.2. So does this mean that will change in January unless I contact support and ask them to keep it ? As I thought I was already on Extended Support for 5.2.

        1. 1and1help says:

          The January situation is only about PHP 5.5.

          Anyway, we can only guarantee you that PHP 5.2 continues to work long term if you order the PHP 5.2 Extended Support.

          Michael, 1&1

  10. Susan says:

    I updated to PHP 7.0, and now when I go to my site I get “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.” What do I do? (Please explain in the simplest terms). Thanks.

    1. 1and1help says:

      Hi Susan,

      please read here:

      https://community.1and1.com/11-extended-support-for-older-php-versions/#comment-168961

      Unfortunately, there is no real easy way to explain this. 😉

      You might stay with PHP 5.6 for now, if you can’t update to a newer WordPress version (though we are recommending highly to always use an up-to-date version).

      Best regards,
      Michael, 1&1

      1. Martin Joseph says:

        Am actually using WordPress 4.7 and still get the same error when I upgrade to php7. What could be the problem? Or is it the apache version? Sorry am a beginner in this but I know how to edit files in wordpress.

        1. 1and1help says:

          Hi Martin,

          do you use “WordFence” as a WordPress plugin? Seems like some WP users experienced this issue in combination with WF in the past: https://wordpress.org/support/topic/your-php-installation-appears-to-be-missing-the-mysql-extension-which-is-require-33/

          Try to de-activate the plugin as a first step.

          Best,
          Michael, 1&1

  11. SAMBA says:

    hello i need to increase php size but i don ‘t find the road for it

    1. 1and1help says:

      Hi SAMBA,

      you can set your PHP memory limit via custom php.ini or .user.ini (last one since PHP 5.4): http://php.net/manual/en/ini.core.php

      Please keep in mind that there are technical limits depending on your hosting tariff. These can’t be overruled by your custom php.ini.

      Best regards,
      Michael, 1&1

  12. Eric Duggan says:

    Hi:

    I am attempting to get OpCache running on PHP7 on my Joomla 3.6.2 site. I created a local php.ini file with the recommended script and the absolute address included. The result was an Error 500 – Internal server error result. If I delete the last line of the script or if I edit the last line to read: opcache.file_cache_only=0; the website loads normally but nothing shows up in the /.opcache folder. I suspect that OpCache is not operational. Any suggestions? Thanks.

    1. 1and1help says:

      Hi Eric,

      please keep in mind that you overwrite our PHP settings with your own php.ini. If you don’t define values like “memory_limit” or “upload_max_filesize” in this custom php.ini, the stock limits of the PHP developers are set (and they are pretty low). This could cause your Error 500s.

      So please try to add also the following lines into your php.ini:

      memory_limit = 256M
      post_max_size = 64M
      upload_max_filesize = 64M

      Regards,
      Michael, 1&1

      1. Eric Duggan says:

        Thanks for your response Michael. Unfortunately, the addition to the php.ini file did not correct the problem since I was once again confronted with the Error 500. I assume that the correct syntax for the added lines would remove the white space around the “=” and terminate each line with a semi-colon. Do you have any other suggestions?

        Many thanks again.
        Eric

        1. 1and1help says:

          Hi Eric,

          do you use other caching tools in your Joomla! installation besides Zends Opcache? Maybe you try to deactivate them before using Opcache.

          Besides that you might run the debug mode in Joomla! to see which exact error message comes with the 500: https://docs.joomla.org/How_to_debug_your_code

          EDIT: I tried this now by my own. Please do not use this “…/” before the absolute path. This is only something the author of the article added to show that there might be something before the “/homepages” path. On a classic shared hosting package this is not the case!

          Best,
          Michael, 1&1

          1. Eric Duggan says:

            Thanks Michael. I removed the “…/” from the absolute address and the error 500 has gone away and the /.opchache folder is now showing some activity. You have been very helpful!

            Eric

  13. Regis says:

    Hello,
    I changed from PHP 5.6 to PHP7, but now with my ezloms.com using Drupal 7, I have the following message:

    Fatal error: ‘break’ not in the ‘loop’ or ‘switch’ context in /homepages/htdocs/com/../modules/taxonomy_menu/taxonomy_menu.module on line 324

    How to fix this ?
    Thanks for your help!
    Regis

    1. 1and1help says:

      Hi Regis,

      seems to be a bug of Drupal 7 in combination with PHP 7. Read here: https://www.drupal.org/node/2782369 As you can see, there is a fix available for that.

      Best regards,
      Michael, 1&1

  14. Andris says:

    This is a Drupal 8 site that I wish to develop. I have created the custom php.ini with the lines you give in this article. I have also entered the correct absolute directory name for the cache folder. I placed the php.ini file in the root directory of the webspace – again as per instructions in answer to other queries following this article.
    I see no difference in Drupal. It is still telling me that OPcache is not enabled.
    I have PHP7 enabled for this site.
    Anything further that I should be doing?

    1. 1and1help says:

      Hi Andris,

      the very first comment of this article should help: https://community.1and1.com/php-7/#comment-135769

      I tried it like this today- and the Drupal 8 check says now:
      “PHP OPcode caching Activated”

      UPDATE: I investigated a bit deeper. Please do not use this “…/” before the absolute path. This is only something the author of the article added to show that there might be something before the “/homepages” path. On a classic shared hosting package this is not the case! Now you can use the “opcache.file_cache_only=1;” and it caches the files.

      Regards,
      Michael, 1&1

  15. Matt says:

    Hi, I have a 1&1 Beginner Package. I updated one of my domains to PHP 7, created the directory, and added the php.ini file, but Drupal 8 is still saying that Opcache is “not enabled” on the status report page. Am I missing something?

    1. 1and1help says:

      Hi Matt,

      I tried it a few days ago by myself with Drupal 8 and it worked for me. Most important thing: Please do not use this “…/” before the absolute path at the line “opcache.file_cache” . This is only something the author of the article added to show that there might be something before the “/homepages” path. On a classic shared hosting package this is not the case!

      So it should look like this:

      opcache.file_cache=/homepages/mypath/htdocs/.opcache;

      Regards,
      Michael, 1&1

  16. Christian says:

    Hi,
    I want to parse all HTML files as PHP.
    In the past I used htaccess:
    AddHandler x-mapp-php6 .html .htm
    can I still use it in PHP7 because
    AddHandler x-mapp-php7 .html .htm is not working.

    Does it make any sense in combination with OpCache?

    1. 1and1help says:

      Hi Christian,

      OpCache is realized in a different way on our servers.

      On the webspace you can use PHP up to version 5.5 (same thing for php-cli applications). Code would be ‘AddHandler x-mapp-php5.5 .html .htm’ in this case. PHP versions higher than 5.5 are not yet supported on our servers (php6 is actually 5.4). PHP 5.6, 7 and 7.1 are only supported for running PHP scripts in web browsers.

      Regards,
      Michael, 1&1

  17. William says:

    I’ve had this problem for a while trying to install drupal 8. I followed the instructions correctly but drupal still stated that Opcode caching was disabled.

    I created a info.php file and checked to see if Opcode caching was enabled in php, and it was. But drupal was still not recognizing it.

    What I had to do was edit the .htaccess file and uncomment “RewriteBase /” and that fixed the problem, Opcode caching is now being recognized as enabled by drupal.

    This might be a drupal specific issue or if others are having this issue with other CMSs, it might be worth checking that line in the .htaccess file.

    Thought this was worth posting because it was driving me crazy for a day.

  18. acarrati says:

    Some how I was being charged for extended PHP support. If I upgrade my version will it cost me?

    1. 1and1help says:

      Hi,

      if you upgrade your PHP version to a free one (all the current versions, at the moment PHP 5.6, 7.0, 7.1, are free) in your 1&1 Control Panel (see http://help.1and1.com/article/792330) and cancel the Extended Support option afterwards, we will not charge you this any longer. Here you can find more informations about this topic: http://help.1and1.com/article/792618

      Best regards,
      Michael, 1&1

  19. neil says:

    when i update to php 7 i get the following error on my site
    Parse error: syntax error, unexpected ‘new’ (T_NEW) in /homepages/12/d272531721/htdocs/wp-content/plugins/envato-wordpress-toolkit-master/index.php on line 204
    gone back to 5.6 for now and seems to be working but want to get this sorted so i don’t have this problem again soon

    regards

    Neil

    1. 1and1help says:

      Hi neil,

      looks like the version of your plugin “envato-wordpress-toolkit-master” is not 100 % compatible to PHP 7. You might ask the developer if there is a newer version out with PHP 7 support.

      Best,
      Michael, 1&1

  20. Chris says:

    I tried to activate PHP 7.0 from PHP 5.6, but my website doesn’t work. I got this error message :

    Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /homepages/7/d258184637/htdocs/includes/functions.inc.php:21 Stack trace: #0 /homepages/7/d258184637/htdocs/includes/init.inc.php(21): ConnectToDatabase() #1 /homepages/7/d258184637/htdocs/index.php(11): require_once(‘/homepages/7/d2…’) #2 {main} thrown in /homepages/7/d258184637/htdocs/includes/functions.inc.php on line 21

    Do you have a solution to fix this error ?
    Many thanks
    Chris

    1. 1and1help says:

      Hi Chris,

      “mysql_connect” is not only deprecated but no longer supported in PHP 7.0 (it was deprecated since PHP 5.5).

      So you have to use “mysqli_connect” instead. Read more about this here: http://php.net/manual/en/function.mysql-connect.php

      Best regards,
      Michael, 1&1

  21. Chukwuemeka Ihedoro says:

    I looged into ssh for my website because of cron and found out i dont have php7.0 in my server. how do i enable php7.0 for my cron.

    This is what i got after using whereis php
    (uiserver):u88799345:~$ whereis php
    php: /usr/bin/php4.4-cli /usr/bin/php5.2-cli /usr/bin/php5.4-cli /usr/bin/php5.5-cli /usr/bin/php /usr/bin/php4.4 /usr/bin/php5.2 /usr/bin/php5.4 /usr/bin/php5.5 /usr/lib/php5.4 /usr/lib/php5.2 /usr/lib/php5.5 /usr/lib/php4.4 /usr/local/bin/php /usr/local/bin/php4.4 /usr/local/bin/php5.2 /usr/local/bin/php5.4 /usr/local/bin/php5.5 /usr/include/php5.2 /usr/include/php5.5 /usr/include/php4.4 /usr/include/php5.4 /usr/share/php

    1. 1and1help says:

      Hi Chukwuemeka,

      our developers are working on updates for php-cli right now. We hope that we can offer this newer versions soon. In the mean time, php5.5-cli is the highest PHP version you can use via command line.

      Best regards,
      Michael, 1&1

  22. Cesar says:

    Hello! I have updated to PHP 7 (from 5.6), till now everything fine! What I don’t understand is: 1. Why do I need the OpCache? 2. Through my Control Panel I have gone to the “Webspace Explorer” and I see that there’s already a /.opcache folder (also with the point and the slash)… Do I have to do something more? Where is the php.ini?

  23. olivedev says:

    Symfony already has great performance with PHP 7 even if you have opcache disabled. Here are the benchmarks of Symfony with PHP 7 with caching: https://www.cloudways.com/blog/php-5-6-vs-php-7-symfony-benchmarks/
    If you enable varnish as well it can further boost the speed.

Leave a Reply to Sergio Perales Cancel reply

Your email address will not be published. Required fields are marked *