{"id":3608,"date":"2012-07-24T23:00:18","date_gmt":"2012-07-24T15:00:18","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=3608"},"modified":"2023-06-23T17:06:12","modified_gmt":"2023-06-23T17:06:12","slug":"how-to-enable-apc-with-php-on-centos-6-3","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-enable-apc-with-php-on-centos-6-3\/","title":{"rendered":"How to Enable APC With PHP on CentOS 6.3"},"content":{"rendered":"<p>The Alternative PHP Cache (APC) is a robust, open-source framework that optimizes and caches PHP intermediate code. It&#8217;s a PECL extension, sharing the packaging and distribution system with its sister, PEAR.<\/p>\n<p>This tutorial will guide you through the process of enabling APC (Alternative PHP Cache) to enhance the speed of PHP on your server.<\/p>\n<p>Whether you&#8217;re using a <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-dedicated-server-hosting\/\">dedicated server<\/a>, a <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS server<\/a>, or even <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-cloud-hosting\/\">cloud hosting<\/a> or <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-shared-hosting\/\">shared hosting<\/a>, APC can be a valuable addition to your PHP environment.<\/p>\n<h2>Step 1: Install APC using the yum command<\/h2>\n<p>To install APC, you&#8217;ll need to use the yum command. Here&#8217;s the command you need to enter:<\/p>\n<pre>[root@centos63 ~]# yum install php-pecl-apc -y<\/pre>\n<p>After running this command, the system will resolve dependencies and install the necessary packages. Once the installation is complete, you&#8217;ll see a message indicating that php-pecl-apc and php-pear have been installed.<\/p>\n<p>Example:<\/p>\n<pre>[root@centos63 ~]# yum install php-pecl-apc -y\r\nLoaded plugins: fastestmirror, presto\r\nLoading mirror speeds from cached hostfile\r\n * base: mirrors.hostemo.com\r\n * extras: mirrors.hostemo.com\r\n * updates: mirrors.hostemo.com\r\nSetting up Install Process\r\nResolving Dependencies\r\n--&gt; Running transaction check\r\n---&gt; Package php-pecl-apc.i686 0:3.1.9-2.el6 will be installed\r\n--&gt; Processing Dependency: \/usr\/bin\/pecl for package: php-pecl-apc-3.1.9-2.el6.i686\r\n--&gt; Processing Dependency: \/usr\/bin\/pecl for package: php-pecl-apc-3.1.9-2.el6.i686\r\n--&gt; Running transaction check\r\n---&gt; Package php-pear.noarch 1:1.9.4-4.el6 will be installed\r\n--&gt; Finished Dependency Resolution\r\n\r\nDependencies Resolved\r\n\r\n====================================================================================================\r\n Package               Arch            Version                  Repository                     Size\r\n====================================================================================================\r\nInstalling:\r\n php-pecl-apc          i686            3.1.9-2.el6              CentOS6.3-Repository           96 k\r\nInstalling for dependencies:\r\n php-pear              noarch          1:1.9.4-4.el6            CentOS6.3-Repository          393 k\r\n\r\nTransaction Summary\r\n====================================================================================================\r\nInstall       2 Package(s)\r\n\r\nTotal download size: 489 k\r\nInstalled size: 2.5 M\r\nDownloading Packages:\r\nSetting up and reading Presto delta metadata\r\nProcessing delta metadata\r\nPackage(s) data still to download: 489 k\r\n----------------------------------------------------------------------------------------------------\r\nTotal                                                               3.3 MB\/s | 489 kB     00:00\r\nRunning rpm_check_debug\r\nRunning Transaction Test\r\nTransaction Test Succeeded\r\nRunning Transaction\r\n  Installing : 1:php-pear-1.9.4-4.el6.noarch                                                    1\/2\r\n  Installing : php-pecl-apc-3.1.9-2.el6.i686                                                    2\/2\r\n  Verifying  : 1:php-pear-1.9.4-4.el6.noarch                                                    1\/2\r\n  Verifying  : php-pecl-apc-3.1.9-2.el6.i686                                                    2\/2\r\n\r\nInstalled:\r\n  php-pecl-apc.i686 0:3.1.9-2.el6\r\n\r\nDependency Installed:\r\n  php-pear.noarch 1:1.9.4-4.el6\r\n\r\nComplete!<\/pre>\n<h2>Step 2: Specify Shared Memory<\/h2>\n<p>Next, you&#8217;ll need to specify the size of the shared memory. To do this, open the apc.ini file:<\/p>\n<pre>[root@centos63 ~]# vi \/etc\/php.d\/apc.ini<\/pre>\n<p>On line 12, specify the shared memory size:<\/p>\n<pre>\r\n; The size of each shared memory segment, with M\/G suffix\r\napc.shm_size=512M\r\n; A \"hint\" about the number of distinct source files that will be included or\r\n; requested on your web server. Set to zero or omit if you are not sure;\r\n<\/pre>\n<h2>Step 3: Restart Apache<\/h2>\n<p>After specifying the shared memory size, you&#8217;ll need to restart Apache for the changes to take effect. Use the following command to restart Apache:<\/p>\n<pre>\r\n[root@centos63 ~]# \/etc\/rc.d\/init.d\/httpd restart\r\nStopping httpd:                                            [  OK  ]\r\nStarting httpd:                                            [  OK  ]\r\n<\/pre>\n<h2>Step 4: Verify APC Installation<\/h2>\n<p>Finally, to ensure that APC has been enabled, create a &#8220;phpinfo&#8221; file:<\/p>\n<pre>[root@centos63 ~]# vi \/var\/www\/html\/phpinfo.php<\/pre>\n<p>In this file, add the following lines:<\/p>\n<pre>&lt;?php\r\nphpinfo();\r\n?&gt;<\/pre>\n<p>After saving and closing the file, open it in a web browser. You should see APC listed among the enabled modules.<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/07\/apc-1.png\" alt=\"apc\" width=\"606\" height=\"247\" class=\"alignnone size-full wp-image-16652 img-fluid lazyload\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/07\/apc-1.png 606w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/07\/apc-1-300x122.png 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/07\/apc-1-128x52.png 128w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/07\/apc-1-420x171.png 420w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/07\/apc-1-540x220.png 540w\" data-sizes=\"(max-width: 606px) 100vw, 606px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 606px; --smush-placeholder-aspect-ratio: 606\/247;\" \/><\/p>\n<h2>Commands Mentioned<\/h2>\n<ul>\n<li><span class=\"fw-bold\">yum install php-pecl-apc -y<\/span> \u2013 This command installs the APC extension on your server.<\/li>\n<li><span class=\"fw-bold\">vi \/etc\/php.d\/apc.ini<\/span> \u2013 This command opens the APC configuration file where you can specify the shared memory size.<\/li>\n<li><span class=\"fw-bold\">\/etc\/rc.d\/init.d\/httpd restart<\/span> \u2013 This command restarts the Apache server, allowing the changes to take effect.<\/li>\n<li><span class=\"fw-bold\">vi \/var\/www\/html\/phpinfo.php<\/span> \u2013 This command creates a new PHP file where you can check if APC has been enabled.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Enabling APC with PHP on CentOS 6.3 can significantly enhance the performance of your PHP applications. This tutorial has guided you through the process of installing APC, specifying shared memory, restarting Apache, and verifying the APC installation.<\/p>\n<p>By following these steps, you can optimize your PHP environment and make your server more efficient.<\/p>\n<p>By implementing APC, you&#8217;re taking a significant step towards optimizing your server and enhancing the performance of your PHP applications. If you have any further questions, refer to the FAQ section or feel free to ask.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Alternative PHP Cache (APC) is a robust, open-source framework that optimizes and caches PHP intermediate code. It&#8217;s a PECL extension, sharing the packaging and distribution system with its sister,&#8230;<\/p>\n","protected":false},"author":6,"featured_media":1262,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1025],"tags":[1199,1202,1536,1646],"class_list":["post-3608","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-apache","tag-apc","tag-linux","tag-php"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/3608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=3608"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/3608\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/1262"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=3608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=3608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=3608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}