{"id":2552,"date":"2023-02-03T12:37:53","date_gmt":"2022-03-24T00:08:00","guid":{"rendered":""},"modified":"2025-02-02T00:46:18","modified_gmt":"2025-02-01T23:46:18","slug":"how-to-install-and-configure-php-opcache-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-install-and-configure-php-opcache-on-ubuntu-20-04\/","title":{"rendered":"Linux VPS &#038; VPS Windows Setup Guide | NetCloud24 and Configure PHP OPcache on Ubuntu 20.04"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<header>\n<h1>\u00a0<\/h1>\n<\/header>\n<article>\n<p>PHP OPcache is a powerful caching engine that can significantly boost the performance of PHP applications by storing precompiled script bytecode in memory. This reduces the need for PHP to load and parse scripts repeatedly. In this guide, we will walk you through the steps to install and configure PHP OPcache on Ubuntu 20.04. If you&#8217;re using a , you can still enable OPcache for PHP on Windows VPSwith a similar configuration.<\/p>\n<h2>Prerequisites<\/h2>\n<p>Before proceeding with the installation, make sure you have the following:<\/p>\n<ul>\n<li>An Ubuntu 20.04 server with root or sudo access.<\/li>\n<li>PHP installed on your server (version 7.4 or later).<\/li>\n<\/ul>\n<p>If you\u2019re using , you can also configure PHP OPcache to optimize PHP performance on a Windows-based server. <a href=\"https:\/\/ie.netcloud24.com\">Windows VPSVirtual Private Servers<\/a> provide dedicated resources that are ideal for boosting PHP applications using OPcache.<\/p>\n<h2>Step 1: Update Your System<\/h2>\n<p>Start by updating your package list to ensure you have the latest versions of the required packages:<\/p>\n<pre><code>sudo apt update\r\nsudo apt upgrade -y<\/code><\/pre>\n<h2>Step 2: Install PHP OPcache<\/h2>\n<p>If PHP is already installed on your server, OPcache may already be included. To verify if OPcache is installed, run the following command:<\/p>\n<pre><code>php -m | grep opcache<\/code><\/pre>\n<p>If you don\u2019t see &#8220;opcache&#8221; in the output, you can install it with this command:<\/p>\n<pre><code>sudo apt install php-opcache -y<\/code><\/pre>\n<p>Once installed, restart your web server (NGINX or Apache) for the changes to take effect:<\/p>\n<pre><code>sudo systemctl restart apache2  # For Apache\r\nsudo systemctl restart nginx   # For NGINX<\/code><\/pre>\n<h2>Step 3: Configure PHP OPcache<\/h2>\n<p>After installing OPcache, you need to configure it for optimal performance. Open the PHP configuration file for editing:<\/p>\n<pre><code>sudo nano \/etc\/php\/7.4\/apache2\/php.ini  # For Apache\r\nsudo nano \/etc\/php\/7.4\/fpm\/php.ini   # For NGINX with PHP-FPM<\/code><\/pre>\n<p>Find and update the following OPcache settings, or add them if they don&#8217;t exist:<\/p>\n<pre><code>[opcache]\r\nopcache.enable=1\r\nopcache.memory_consumption=128\r\nopcache.interned_strings_buffer=8\r\nopcache.max_accelerated_files=10000\r\nopcache.revalidate_freq=60\r\nopcache.fast_shutdown=1<\/code><\/pre>\n<p>Explanation of key settings:<\/p>\n<ul>\n<li><strong>opcache.enable<\/strong>: Enables OPcache.<\/li>\n<li><strong>opcache.memory_consumption<\/strong>: Sets the amount of memory allocated to OPcache (in MB).<\/li>\n<li><strong>opcache.interned_strings_buffer<\/strong>: Amount of memory for interned strings (in MB).<\/li>\n<li><strong>opcache.max_accelerated_files<\/strong>: The maximum number of cached files OPcache can store.<\/li>\n<li><strong>opcache.revalidate_freq<\/strong>: How often OPcache checks for script changes (in seconds).<\/li>\n<li><strong>opcache.fast_shutdown<\/strong>: Enables fast shutdown to improve performance.<\/li>\n<\/ul>\n<p>Save and exit the configuration file, then restart your web server to apply the changes:<\/p>\n<pre><code>sudo systemctl restart apache2   # For Apache\r\nsudo systemctl restart php7.4-fpm   # For NGINX with PHP-FPM<\/code><\/pre>\n<h2>Step 4: Verify OPcache Configuration<\/h2>\n<p>To confirm that OPcache is enabled and working correctly, you can create a PHP info page. Create a file named <code>info.php<\/code> in your web server\u2019s document root:<\/p>\n<pre><code>sudo nano \/var\/www\/html\/info.php<\/code><\/pre>\n<p>Add the following content:<\/p>\n<pre><code>&lt;?php phpinfo(); ?&gt;<\/code><\/pre>\n<p>Save and exit the file. Then, open your browser and navigate to <code>http:\/\/your_server_ip\/info.php<\/code>. Look for the OPcache section to see if it is enabled and properly configured.<\/p>\n<h2>Benefits of VPS Hosting for PHP OPcache<\/h2>\n<p>Using  or <a href=\"https:\/\/ie.netcloud24.com\">virtual private server hosting Windows<\/a> allows you to fully utilize the benefits of PHP OPcache, which significantly improves the performance of PHP-based applications. A <a href=\"https:\/\/ie.netcloud24.com\">UK Windows VPS<\/a> or <a href=\"https:\/\/ie.netcloud24.com\">Microsoft SQL VPS Windows<\/a> provides dedicated resources, making it an ideal solution for optimizing high-traffic websites.<\/p>\n<p>Hosting PHP applications on a <a href=\"https:\/\/ie.netcloud24.com\">Windows VPSVirtual Private Server<\/a> ensures that your server has the flexibility, control, and performance needed to handle OPcache and other performance-enhancing configurations efficiently.<\/p>\n<h2>Conclusion<\/h2>\n<p>PHP OPcache is an essential component for optimizing PHP applications by caching precompiled scripts in memory, reducing execution time. By following this guide, you can easily install and configure OPcache on Ubuntu 20.04 for better performance. For scalable hosting solutions, consider using <a href=\"https:\/\/ie.netcloud24.com\">Windows VPS Hosting UK<\/a> to take advantage of dedicated resources and enhanced performance for your web applications.<\/p>\n<\/article>\n<footer>\n<p>\u00a9 2024 VPS Hosting Solutions<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 PHP OPcache is a powerful caching engine that can significantly boost the performance of PHP applications by storing precompiled script bytecode in memory. This reduces the\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-2552","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=2552"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2552\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=2552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=2552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=2552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}