<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OpCache Archives - Linux Windows and android Tutorials</title>
	<atom:link href="https://www.osradar.com/tag/opcache/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.osradar.com</link>
	<description>tutorials and news and Seurity</description>
	<lastBuildDate>Fri, 02 Apr 2021 16:08:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8.12</generator>
	<item>
		<title>Configuring PHP OPCache with Apache and Nginx</title>
		<link>https://www.osradar.com/configuring-php-opcache-apache-nginx/</link>
					<comments>https://www.osradar.com/configuring-php-opcache-apache-nginx/#comments</comments>
		
		<dc:creator><![CDATA[angeloma]]></dc:creator>
		<pubDate>Fri, 02 Apr 2021 03:21:00 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[OpCache]]></category>
		<category><![CDATA[server]]></category>
		<guid isPermaLink="false">https://www.osradar.com/?p=29257</guid>

					<description><![CDATA[<p>Hello, friends. We already know that the faster our website loads the more satisfied visitors will be. That is why we have to make some adjustments to the server to achieve this goal. That is why we prepared this post so you can configure PHP OPCache with Apache and Nginx. So your PHP applications or [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/configuring-php-opcache-apache-nginx/">Configuring PHP OPCache with Apache and Nginx</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Hello, friends. We already know that the faster our website loads the more satisfied visitors will be. That is why we have to make some adjustments to the server to achieve this goal. That is why we prepared this post so you can configure PHP OPCache with Apache and Nginx. So your PHP applications or websites will load faster.</p>



<h2 id="what-is-opcache?"><a href="#what-is-opcache?" name="what-is-opcache?"></a>What is OPCache?</h2>



<p><a href="https://www.php.net/manual/en/book.opcache.php" target="_blank" rel="noreferrer noopener">OPcache</a> is a PHP extension that improves the performance of a web page by storing the bytecode of a precompiled script in shared memory and eliminates the obligation to constantly load and parse scripts.</p>



<p>This extension is included in PHP 5.5.0 and later, and is “ available in PECL for PHP versions 5.2, 5.3 and 5.4.</p>



<p>In short, we can make use of it to speed up our websites without the need to install anything additional. Of course, for extreme situations, there are other solutions but for personal websites and small projects, OPCache is ideal.</p>



<p>So, in this post, I will show you how to configure PHP OPCache with <a href="https://www.osradar.com/install-lamp-ubuntu-20-04/" target="_blank" rel="noreferrer noopener">Apache</a> and <a href="https://www.osradar.com/install-lemp-on-ubuntu-20-04/" target="_blank" rel="noreferrer noopener">Nginx</a> so you can get the most out of it.</p>



<h2 id="configuring-php-opcache---apache"><a href="#configuring-php-opcache---apache" name="configuring-php-opcache---apache"></a>Configuring PHP OPCache &#8211; Apache</h2>



<p><strong>Note: For this post, we will use Ubuntu 20.04 as an example but you can also do it using Debian 10 or any derivative,</strong></p>



<p>Before you start, update the whole system</p>



<pre class="wp-block-preformatted">sudo apt update
sudo apt upgrade</pre>



<p>If you don’t have Apache and PHP installed you can do it with the following command:</p>



<pre class="wp-block-preformatted">sudo apt install apache2 libapache2-mod-php php php-cli php-opcache php-mysql php-zip php-gd php-mbstring php-curl php-xml
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'php7.4-opcache' instead of 'php-opcache'
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils fontconfig-config fonts-dejavu-core libapache2-mod-php7.4 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
  libfontconfig1 libgd3 libgdbm-compat4 libjansson4 libjbig0 libjpeg-turbo8 libjpeg8 liblua5.2-0 libmagic-mgc libmagic1 libonig5 libperl5.30 libtiff5 libwebp6 libx11-6
  libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 libxslt1.1 libzip5 perl perl-modules-5.30 php-common php7.4 php7.4-cli php7.4-common php7.4-curl php7.4-gd php7.4-json
  php7.4-mbstring php7.4-mysql php7.4-readline php7.4-xml php7.4-zip
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear libgd-tools file perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl
  make libb-debug-perl liblocale-codes-perl
Recommended packages:
  ssl-cert
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils fontconfig-config fonts-dejavu-core libapache2-mod-php libapache2-mod-php7.4 libapr1 libaprutil1
  libaprutil1-dbd-sqlite3 libaprutil1-ldap libfontconfig1 libgd3 libgdbm-compat4 libjansson4 libjbig0 libjpeg-turbo8 libjpeg8 liblua5.2-0 libmagic-mgc libmagic1
  libonig5 libperl5.30 libtiff5 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 libxslt1.1 libzip5 perl perl-modules-5.30 php php-cli php-common
  php-curl php-gd php-mbstring php-mysql php-xml php-zip php7.4 php7.4-cli php7.4-common php7.4-curl php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache
  php7.4-readline php7.4-xml php7.4-zip
0 upgraded, 57 newly installed, 0 to remove and 29 not upgraded.
Need to get 16.7 MB of archives.
After this operation, 91.0 MB of additional disk space will be used.
Do you want to continue? [Y/n]</pre>



<p>As you can notice in this command is included the <code>php-opcache</code> package which is where the extension is.</p>



<p>You can check the version of PHP installed and you can even create a test file.</p>



<pre class="wp-block-preformatted">php -version
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies</pre>



<p>Now it is necessary to enable the extension and this can be done by modifying some parameters from the PHP configuration file.</p>



<pre class="wp-block-preformatted">sudo nano /etc/php/7.4/apache2/php.ini</pre>



<p>And in the file uncomment the following lines:</p>



<pre class="wp-block-preformatted">opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=2000
opcache.revalidate_freq=30</pre>



<p>What we are doing is, enable it, tell it in Mb how much memory it can consume; the number of files to accelerate, and the time in seconds that it will look for files.</p>



<p>Save the changes and close the editor. To apply the changes, restart Apache.</p>



<pre class="wp-block-preformatted">sudo systemctl restart apache2</pre>



<p>Now check if OPCache is enabled</p>



<pre class="wp-block-preformatted">php -i | grep opcache</pre>



<p>The output will look something like this:</p>



<pre class="wp-block-preformatted">.
.
.
opcache.dups_fix =&gt; Off =&gt; Off
opcache.enable =&gt; On =&gt; On
opcache.enable_cli =&gt; Off =&gt; Off
opcache.enable_file_override =&gt; Off =&gt; Off
opcache.error_log =&gt; no value =&gt; no value
opcache.file_cache =&gt; no value =&gt; no value
opcache.file_cache_consistency_checks =&gt; 1 =&gt; 1
opcache.file_cache_only =&gt; 0 =&gt; 0
opcache.file_update_protection =&gt; 2 =&gt; 2
opcache.force_restart_timeout =&gt; 180 =&gt; 180
.
.
.</pre>



<p>So, PHP OPCache is now configured.</p>



<h2 id="configuring-php-opcache---apache"><a name="configuring-php-opcache---apache" href="#configuring-php-opcache---apache"></a>Configuring PHP OPCache &#8211; Nginx</h2>



<p>In the case of Nginx, the process is quite similar. Remember that it is not a good idea to have Apache and Nginx running together. So I will assume in this part of the post that you don’t have Apache.</p>



<p>So, install Nginx, PHP, and some modules from the official repositories of the distribution</p>



<pre class="wp-block-preformatted">sudo apt install nginx php php-fpm php-cli php-opcache php-mysql php-zip php-gd php-mbstring php-curl php-xml</pre>



<p>Again, the <code>php-opcache</code> package is present as it cannot be missing in the installation.</p>



<p>Then edit the <code>php-fpm</code> configuration file which is where we will have to enable the extension</p>



<pre class="wp-block-preformatted">sudo nano /etc/php/7.4/fpm/php.ini</pre>



<p>And uncomment the following lines</p>



<pre class="wp-block-preformatted">opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=200</pre>



<p>Save the changes and close the editor.</p>



<p>After that, restart <code>nginx</code> and <code>php-fpm</code>.</p>



<pre class="wp-block-preformatted">sudo systemctl restart nginx php7.4-fpm</pre>



<p>PHP OPCache will now be configured with Apache and Nginx. Enjoy it.</p>



<h2 id="conclusion"><a href="#conclusion" name="conclusion"></a>Conclusion</h2>



<p>In this post, we have shown you how with a PHP extension you can improve the performance of your web applications. This will improve the load times and make your users happy.</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/configuring-php-opcache-apache-nginx/">Configuring PHP OPCache with Apache and Nginx</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.osradar.com/configuring-php-opcache-apache-nginx/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
