Install Xcache and Memcached on the LAMP platform to accelerate website operation
After the LAMP environment is set up in CentOS 7, you can install website programs. The most popular Wordpess is used as an example. To speed up Website access, in addition to spending money to buy better hardware. We can optimize website programs and themes. Enable the cache function for the server to speed up the website. We know that the cache on the internet is king.
Build a LAMP platform environment in CentOS 7
1. install php accelerator Xcache
XCache is a fast and stable PHP opcode cache developed by Chinese people. It reduces server load by sharing the compiled memory.
Because the yum source Warehouse does not exist, download the source file first. The latest version is 3.2.0.
Download: wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz in the tmp directory: cd/tmp
Decompression: tar xvfz xcache-3.2.0.tar.gz
Prepare installation: cd xcache-3.2.0
Before installation, prepare the compiling environment: yum-y install php-devel gcc
Run phpize, which is very important: phpize
Configuration:./configure -- enable-xcache
Install: make & make install
Copy the configuration file cp xcache. ini/etc/php. d (xcache. ini is in the installation directory of the source program)
Restart the http service: systemctl restart httpd
2. Install memcached
Memcached is a high-performance distributed memory object Cache System for dynamic Web applications to reduce database load. It caches data and objects in the memory to reduce the number of times the database is read, so as to provide dynamic, database-driven website speed.
A. Install
Yum-y install memcached
Install memcache and associate php
Yum-y install php-pecl-memcache
Compile and install PHP memcache extensions
Download wget http://pecl.php.net/get/memcache-3.0.8.tgz
Tar xf memcache-3.0.8.tgz
Cd memcache-3.0.8
Run
Phpize
./Configure
Make & make install
B. Configuration
Add memcache extension to the php. ini file
Extension =/usr/lib64/php/modules/memcache. so (versions may vary with Directories)
C. Run
Memcached-d-m 128-c 1024-P/tmp/memcached. pid
D. Test
Test whether memcached works normally. edit a file such as memtest. php In the website directory and put the following code:
<? Php
$ Memcache = new Memcache;
$ Memcache-> connect ('localhost', 11211) or die ("cocould not connect ");
$ Version = $ memcache-> getVersion ();
Echo "Server's version:". $ version. "<br/> \ n ";
$ Tmp_object = new stdClass;
$ Tmp_object-> str_attr = 'test ';
$ Tmp_object-> int_attr = 123;
$ Memcache-> set ('key', $ tmp_object, false, 10) or die ("Failed to save data at the server ");
Echo "Store data in the cache (data will expire in 10 seconds) <br/> \ n ";
$ Get_result = $ memcache-> get ('key ');
Echo "Data from the cache: <br/> \ n ";
Var_dump ($ get_result );
?>
If the actual server version: 1.4 ...... Store date in the cache and other information indicates that memcached runs normally.
5. Integration
Wordpress supports memcached
Download: wget https://downloads.wordpress.org/plugin/memcached.2.0.2.zip
Unzip memcached.2.0.2.zip
Cd memcached.2.0.2
Copy the object-cache.php to the wp-content folder in the root directory of the website, and wordpress automatically calls the cache.
Restart the server:
Sytemctl restart memcached
Sytemctl restart httpd
3. Enable Gzip compression.
By default, the gzip module is added to apache2.4. We need to enable the deflate module at the same time to compress web files and increase the server browsing speed.
Vim/etc/httpd/conf/httpd. conf Add the following lines at the end:
<IfModule mod_deflate.c>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE css js
</IfModule>
Restart the http service: systemctl restart httpd
Memcached installation and startup script
Performance problems of using Memcached in PHP
Install Memcached in Ubuntu and its command explanation
Install and apply Memcached
Use Nginx + Memcached's small image storage solution
Getting started with Memcached
For details about Memcached, click here
Memcached: click here
This article permanently updates the link address: