CentOS implements Xcache for PHP Acceleration Based on FastCGI

Source: Internet
Author: User
Tags mysql commands what php zts

LAMP comprehension:

LAMP: A group of open-source software commonly used to build dynamic websites or servers in Linux + Apache + Mysql + Perl/PHP/Python. LAMP is independent of each other, however, because it is often used together, it becomes increasingly compatible and forms a powerful Web application platform.


Part 1: the order of the compilation and installation process: httpd 2.4.9 + mysql-5.5.33 + php-5.4.26:

One, install mysql-5.5.33:

Prerequisites:

Prepare and install the development kit and dependency packages.

1. File System for data storage preparation:

Create a new logical volume and mount it to a specific directory.

Assume that the Mount directory of the logical volume is/mydata, and then create the/mydata/data directory as the directory for storing mysql data.

1). Create the shard and/data directory:

2). Create LVM (to facilitate expansion in the future when the startup is insufficient .)

3) format the file system and configure it to be automatically mounted upon startup:

4) create a mydata directory and modify the owner Group of the directory:

2. Create a user to run the process securely:

3. Install and initialize mysql-5.5.33:

1). decompress the installation package and create a soft link (for future upgrades ):

2). initialize the System Library:

2. Provide the sysv service script for mysql:

3. Add to service list:

4. Provide the configuration file (my dual-core configuration file is changed to 4 ):


5. Start the mysqld service:

6. view the socket file:

Note that the path for installing the rpm package is/var/lib/mysql.

7. How to connect to mysql ??

1) modify the PATH environment variable so that the system can directly use mysql commands:

2) connect to mysql to view the version:

3). Delete Anonymous Users:

--> If you are not sure, check the following:

4). Change the password:

I. Change one password at a time:

Ii. change the password of all users:

Iii. Test Logon:

Iv. Create a hidden file in the home directory. my. cnf (you do not need to manually enter a password to automatically connect to mysql .):

8. Export the warehouse file and header file:

1

2. Compile and install apache;

1. Solve the dependency:

Httpd-2.4.9 needs a newer version of apr and apr-util, so it needs to be upgraded in advance.

There are two ways to upgrade: One is through source code compilation and installation, and the other is to directly upgrade the rpm package.

--> Here we select to compile the source code.

1). Install the pcre-devel package (Development Kit)-> the httpd-2.4.9 compilation process also depends on the pcre-devel package, needs to be installed in advance, this software package system CD comes:

2. Install apr and apr-util:

1). Compile and install the apr-1.5.0:

2). Compile and install the apr-util-1.5.3:

3. Compile and install httpd-2.4.9:

1). installation:

1234 [root@www ~] # tar xf httpd-2.4.9.tar.bz2 [root@www ~] # cd httpd-2.4.9 [root@www httpd-2.4.9] # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --with-zlib --with-pcre --enable-rewrite --with-apr=/usr/local/apr --with-apr -util=/usr/local/apr-util/ --enable-modules=most --enable-mpms- shared=all --with-mpm=event [root@www httpd-2.4.9] # make && make install

Supplement:
(1) construct MPM as a static module
MPM can be built as a static module on all platforms. Select an MPM during the build and link it to the server. To change the MPM, you must build it again. To use the specified MPM, use the -- with-mpm = NAME parameter when executing the configure script. NAME is the specified mpm name. After compilation, you can use./httpd-l to determine the selected MPM. This command lists all modules compiled into the server program, including MPM.
(2) construct an MPM as a dynamic module
On Unix or similar platforms, MPM can be built as a dynamic module and loaded at runtime like other dynamic modules. Building MPM as a dynamic module allows you to modify the content of the LoadModule command to change MPM without re-building the server program. You can use the -- enable-mpms-shared option to enable the configure script. When the given parameter is all, all MPM modules supported by this platform will be installed. You can also provide a list of modules in the parameters. The default MPM can be automatically selected or specified by the -- with-mpm option when the configure script is executed, and then appears in the generated server configuration file. You can select different MPM for editing the LoadModule command content.

2) provide the SysV service script/etc/rc. d/init. d/httpd24. The content is as follows:

---> If there is no script, it is provided as follows:

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 [root@www ~] # vim /etc/rc.d/init.d/httpd24 #!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd.pid # Source function library. . /etc/rc .d /init .d /functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG- "C" } # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS= "" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl= /usr/local/apache/bin/apachectl httpd=${HTTPD- /usr/local/apache/bin/httpd } prog=httpd pidfile=${PIDFILE- /var/run/httpd .pid} lockfile=${LOCKFILE- /var/lock/subsys/httpd } RETVAL=0 start() { echo -n $ "Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { echo -n $ "Stopping $prog: " killproc -p ${pidfile} -d 10 $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $ "Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >& /dev/null ; then RETVAL=$? echo $ "not reloading due to configuration syntax error" failure $ "not reloading $httpd due to configuration syntax error" else killproc -p ${pidfile} $httpd -HUP RETVAL=$? fi echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f ${pidfile} ] ; then stop start fi ;; reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $ "Usage: $ prog {start | stop | restart | condrestart | reload | status | next fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL

3) Add to the service list:

4. Provide PATH environment variables:

5. Modify the hosts file (an error will be reported during local startup ):

6. As long as it is a compilation module, you need it:

7. Edit the main configuration file of apache:

8. Start httpd24 and test the access to the default page:

1). Start the service:

2) Check whether port 80 is Enabled:

1234 [root@www init.d] # ss -tunlp | grep :80 tcp LISTEN 0 128 :::80 :::* users :(( "httpd" ,57827,4),( "httpd" ,57829,4),( "httpd" ,57857,4),( "httpd" ,57858,4)) users :(( "httpd" ,57827,4),( "httpd" ,57829,4),( "httpd" ,57857,4),( "httpd" ,57858,4)) [root@www init.d] #

3). Test Access:

Three, compile and install php-5.4.26:

1. Solve the dependency-> Configure yum;

2. Compile and install php-5.4.26:

1). installation:

1234 [root@www ~] # tar xf php-5.4.26.tar.bz2 [root@www ~] # cd php-5.4.26 [root@www php-5.4.26] # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts [root@www php-5.4.26] # make && make install

2). Parameter introduction:

Note:

Note:
1. The -- enable-maintainer-zts option is used during compilation to support the MPM of apache worker or event.
2. If PHP5.3 or later is used, you can specify mysqlnd to connect to the MySQL database, so that you do not need to install MySQL or MySQL development kit on the local machine. Mysqlnd is available from php 5.3 and can be bound to it during compilation (instead of binding to a specific MySQL client library), but it is set by default since PHP 5.4.
#./Configure -- with-mysql = mysqlnd -- with-pdo-mysql = mysqlnd -- with-mysqli = mysqlnd

3. Provide the configuration file for php:

1). About php. ini:

2). Provide the configuration file (not edited here ):

4. Edit the apache configuration file httpd. conf to support php in apache:

1). Edit vim/etc/httpd24/httpd. conf:

2) Restart httpd24:

3). view the Port:

5. Edit index. php on the test page, as shown in the following --> (the connection session with MySQL is as follows ):

1). The first time (edit the test page ):

2). First time (Test Access: http: // 172.16.17.201 /):

3). Second (edit the Page Test script ):

4). Second (Test Access: http: // 172.16.17.201 /):

5). The third test (Closing the mysql Service ):

6). Third (access test: http: // 172.16.17.201 /)

4. Install xcache to accelerate php:

Easy to understand:

XCache is an open-source opcode Cache/optimizer, which means it can improve the PHP performance on your server. by caching the compiled PHP Data to the shared memory, he can avoid repeated compilation processes and directly use the compiled code in the buffer to improve the speed. generally, it can increase the page generation rate by 2 to 5 times, reducing the server load.

1. Install phpMyAdmin-4.0.5:

1). decompress the file:

2) Cut the file to/usr/local/apache/htdocs/pma

3). Access: http: // 172.16.17.201/pma/

4). Use AB for stress testing (before installing the xcache php accelerator, the AB test results are as follows ):

(1) usage of the top test:

(2) stress test results:

(3) Compare the stress test with the above picture:

(4). phpMyAdmin during stress testing (can be opened, but you have to wait for the pipeline ):

2. Install xcache to accelerate php:

1). Install the xcache-3.0.3 (use the local interpreter to probe the version number of the module, extended API, etc., generate the serial number mark, and then compile ):

Note:

2) Access: http: // 172.16.17.201/--> and find the xcache:

3). Access: http: // 172.16.17.201/pma (no stress test is performed here)

4). Execute AB again for stress testing (this won't happen ):

5). After Xcache is implemented, the performance will be improved by about 3 times. Here there is no diagram after the CPU and pressure tests.


Part 2: Configure php-5.4.26 for apache-2.4.9 and fpm

1. The installation of Apache and MySQL is the same as that of the previous part. install Apache and MySQL as needed;
This is omitted...

Please click: http://xiaomazi.blog.51cto.com/5891742/1383122

Ii. Compile and install the php-5.4.26:

1. Solve the dependency:

1). You need to delete the following items first, as I have done in the following environment:

1 [root@station76 ~] # rm -rf php-5.4.26

2). decompress, compile, and install:

12345 [root@www ~] # tar xf php-5.4.26.tar.bz2 [root@www php-5.4.26] # cd php-5.4.26 [root@www php-5.4.26] # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 [root@www php-5.4.26] # make && make install Note: The Path is changed to php5, because it has been installed before. You can directly delete/uninstall it in the production environment.

2. Provide the configuration file:

12 [root@www php-5.4.26] # mkdir /etc/php5 [root@www php-5.4.26] # cp php.ini-production /etc/php5/php.ini

3. Configure php-fpm:

1). Provide the SysV init script for php-fpm and add it to the service list:

2). Provide the configuration file for php-fpm:

3. Configure httpd-2.4.9 and Xcache for php acceleration;

1. configuration file: httpd. conf

2. Edit the configuration file httpd. conf:

3. Configure the httpd-vhosts.conf file to make the VM take effect:

1). Configure the VM:

2). create the required directory, test syntax, start service, and Port:

3). Add the local hosts file (note that you do not need to add it in the production environment ):

4) Local Test Access (access will not succeed because you do not have the permission ):

5). Modify the file and add the corresponding permissions:

6). Start and access:

4. Test the modified index. php:

1). Modify the webpage file:

2). Access: http: // www.xiaoma1.com (www.xiaoma2.com)

5. Configure the forwarding function:

1) restart the service:

2) view ports and modules:

3) Test Access: http: // www.xiaoma1.com (www.xiaoma2.com). This is what php parses.

6. Install phpMyAdmin:


1). Delete the index. php file:

2). Decompress phpMyAdmin and copy the file to htdocs (xiaoma2 is the same operation ):

3) Test Access: http://www.xiaoma1.com/pma/

4). Stress Test --> AB (the stress test can still be quickly opened on the pilot webpage ):

7. Install xcache php acceleration:

1 ). delete the previous files, decompress the files, and install phpize (use the local interpreter to test the version number of the module, extend the API, and generate the serial number mark before compilation), compile, and install:

2) create the required directory, cpoy configuration file, modify the configuration file, and start the service:

3) Create the index. php file and:

4). Test Access: http://www.xiaoma1.com/--> http://www.xiaoma1.com/pma/

5) before the AB test:

6). stress testing:

7). The opening speed is very fast after stress testing:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.