Compile and install on CentOS6 to implement lamp (Php-modules) +phpmyadmin installation process full record

Source: Internet
Author: User
Tags fpm mcrypt stop script zts

PHP has three modes of collaboration with Apache: CGI, Modules, FastCGI.
In CGI mode, when a user requests a PHP file, Apache initiates the response process, invokes the PHP processor to process the request, and then returns the result to the client. User response and processing is done by the front-end Apache server;
In modules mode, the PHP parser acts as a module of Apache, and the PHP processor runs with the Web server to process user requests. The user response is handled by Apache and the request processing is performed by Apache and the PHP processor;
In fastcgi mode, Apache calls the Proxcy module, acting as an agent, directly to the backend PHP processor (PHP-FPM) processing, and then return from the back end of the php-fpm of processing results to the user. User response is handled by Apache, request processing PHP-FPM completed;

This document shows the lamp that PHP works in modules mode.
Installation process: httpd--->mariadb--->php--->phpmyadmin--->xcache

Date: September 24, 2017

First, the SOFTWARE environment:

ip:192.168.1.67;
Hostname:centos69-2.surmount.net;
Linux:centos Release 6.9 (Final);
apache:httpd-2.4.27
mariadb:mariadb-5.5.57
php:php-5.6.31
Others: apr-1.6.2;apr-util-1.6.0;phpmyadmin-4.7.4-all-languages;xcache-3.2.0


Second, lamp construction:

2-1: Environment Preparation:

2-1-1: Configure the network yum Source:
# Wget-o/etc/yum.repos.d/centos-base-ali.repo Http://mirrors.aliyun.com/repo/Centos-6.repo
# sed-i ' s/$releasever/6/g '/etc/yum.repos.d/centos-base-ali.repo

2-1-2: Configure the Epel Source:
# Vim/etc/yum.repos.d/epel.repo
[Epel]
Name=epel
baseurl=https://mirrors.ustc.edu.cn/epel/6server/x86_64/
Gpgcheck=0
Enable=1

2-1-3: Configure the Server Software environment:
# yum Groupinstall "Development Tools" "Server Platform Development"-Y

2-2: Install and configure Apache:

2-2-1: Resolve httpd dependencies, compile and install Apr and apr-util:
# Tar XF apr-1.6.2.tar.bz2
# CD apr-1.6.2
#./configure--PREFIX=/USR/LOCAL/APR
# make-j 2 && make install

# Tar XF apr-util-1.6.0.tar.bz2
# CD apr-util-1.6.0
#./configure--prefix=/usr/local/apr-util--WITH-APR=/USR/LOCAL/APR
......
XML/APR_XML.C && Touch Xml/apr_xml.lo
Xml/apr_xml.c:35:19:error:expat.h:no such file or directory
MAKE[1]: * * * [Xml/apr_xml.lo] Error 1 make[1]: * * * waiting for unfinished Jo
......
---> Error, the analysis may be missing expat's development library, after installing the Expat-devel package, the recompile succeeds.
# yum Install Expat-devel-y
# RM-RF apr-util-1.6.0
# Tar XF apr-util-1.6.0.tar.bz2
# CD apr-util-1.6.0
#./configure--prefix=/usr/local/apr-util--WITH-APR=/USR/LOCAL/APR
# make-j 2 && make install

--->: Apache's official introduction to Apr:
The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a Predi CTable and consistent interface to underlying PLATFORM-SPECIFIC implementations. The primary goal is to provide a API to which software developers may code and being assured of predictable if not identical Behaviour regardless of the platform on which their software are built, relieving them of the need to code Special-case CO Nditions to work around or take advantage of platform-specific deficiencies or features.


2-2-2: Install httpd Other dependent packages and required packages:
# yum Install Pcre-devel httpd-y
--->pcre-devel provides a regular pattern matching library, httpd only to provide a httpd startup script template and delete it after use.

2-2-3: Compile and install Apache:
# Tar XF httpd-2.4.27.tar.bz2
# CD httpd-2.4.27
#./configure--prefix=/usr/local/apache--sysconfdir=/etc/httpd24--enable-so--enable-ssl--enable-cgi-- Enable-rewrite--with-zlib--with-pcre--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util-- Enable-modules=most--enable-mpms-shared=all--with-mpm=event
# make-j 2 && make install

--->mpm module knowledge Supplement:
(1) Build MPM as static module:
In all platforms, MPM can be built as a static module. Select a mpm at build time, linked to the server. If you want to change MPM, you must rebuild it. In order to use the specified MPM, use the parameter--with-mpm=name when executing the Configure script. Name is the specified MPM name. After the compilation is complete, you can use./httpd-l to determine the selected MPM. This command lists all modules that are compiled into the server program, including MPM.
(2) Build MPM as dynamic module:
In UNIX or similar platforms, MPM can be built as a dynamic module and loaded at run time as with other dynamic modules. Building MPM as a dynamic module allows you to change the MPM by modifying the contents of the LoadModule directive without rebuilding the server program. Use the--enable-mpms-shared option to enable this feature when you execute a configure script. All MPM modules supported by this platform will be installed when the given parameter is all. You can also give a list of modules in the parameters. The default MPM, which can be automatically selected or specified by the--WITH-MPM option when the Configure script is executed, then appears in the generated server configuration file. Edit the loadmodule instruction content to select a different mpm.

2-2-4: Provides a start-stop script for httpd2.4:
# CD/ETC/RC.D/INIT.D
# CP httpd HTTPD24
# Vim HTTPD24
......
Apachectl=/usr/local/apache/bin/apachectl
HTTPD=${HTTPD-/USR/LOCAL/APACHE/BIN/HTTPD}
......
Pidfile=${pidfile-/usr/local/apache/logs/httpd.pid}
LOCKFILE=${LOCKFILE-/VAR/LOCK/SUBSYS/HTTPD24}
......
# chkconfig--add httpd24
# chkconfig--list | grep httpd24

2-2-5: Configure Apache:
# httpd-t
---> Note: This syntax detects httpd installed for RPM packages, httpd for non-compiled installations.
# vim/etc/profile.d/httpd.sh
Export Path=/usr/local/apache/bin: $PATH
# . /etc/profile.d/httpd.sh
# httpd-t
# hash
Hitscommand
1/usr/local/apache/bin/httpd
---> Note: This syntax detects the httpd of a compiled installation.
# vim/etc/httpd24/httpd.conf
......
ServerName centos69.surmount.net:80
......
LoadModule Deflate_module modules/mod_deflate.so
.....
---> Modify hostname to enable the Deflate module (role: Allows the server to compress the output before it is sent to the client to conserve bandwidth. ), the other temporarily remains the default.
# httpd-t

2-2-6: Launch Apache, Access test:
#/ETC/INIT.D/HTTPD24 Start
# SS-TANL
# Ps-ef | grep httpd
Root 31142 1 0 22:46? 00:00:00/usr/local/apache/bin/httpd
Daemon 31144 31142 0 22:46? 00:00:00/usr/local/apache/bin/httpd
# Httpd-m | grep Event
Mpm_event_module (Shared)
--->event module is started
http://192.168.1.69
It works!
# yum Remove httpd-y
---> Configuration complete, delete the completed httpd package.


2-3: Installation and configuration mariadb:

2-3-1: Prepare the file system for data storage:
# FDISK/DEV/SDB
N--->p--->1--->enter--->+2g--->t--->8e--->w
# partx-a/dev/sdb
# yum Install Lvm2-y
# PVCREATE/DEV/SDB1
# vgcreate DBVG/DEV/SDB1
# lvcreate-l 2g-n DBLV DBVG
# yum Install Xfsprogs-y
# modprobe XFS
# Modinfo XFS
# MKFS.XFS/DEV/DBVG/DBLV
# Mkdir-pv/dbdata
# Vim/etc/fstab
......
/dev/dbvg/dblv/dbdata XFS Defaults 0 0
# mount-a
---> Divides a 2GB partition, creates a LV, is easy to extend, formats the XFS file system, sets the boot auto mount, and stores the data.

2-3-2: Create DATABASE User:
# Mkdir-pv/dbdata/data
# groupadd-r MySQL
# useradd-g mysql-r-s/sbin/nologin-m-d/dbdata/data MySQL
# Chown-r mysql:mysql/dbdata/data/

2-3-3: Initialize the installation mariadb:
# Tar XF mariadb-5.5.57-linux-x86_64.tar.gz-c/usr/local
# cd/usr/local/
# LN-SV mariadb-5.5.57-linux-x86_64 MySQL
# CD MySQL
# Chown-r root:mysql/usr/loca/mysql/*
#/usr/local/mysql/scripts/mysql_install_db--user=mysql--datadir=/dbdata/data

2-3-4: Provides a start-stop script for mariadb:
# ls/dbdata/data/
# Cp/usr/local/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld
# chkconfig--add mysqld

2-3-5: Configure MARIADB:
# Mkdir-pv/etc/mysql
# CP/USR/LOCAL/MYSQL/SUPPORT-FILES/MY-LARGE.CNF/ETC/MYSQL/MY.CNF
# VIM/ETC/MYSQL/MY.CNF
......
Thread_concurrency = 8
DataDir =/dbdata/data
Innodb_file_per_table = On
Skip_name_resolve = On
......
The value of the--->thread_concurrency is twice times the number of CPUs,/dbdata/data is the location where the data files are stored, the InnoDB engine Independent table space is enabled, and the reverse domain name is skipped.

2-3-6: Start mariadb, set the root user password for db:
#/etc/init.d/mysqld Start
#/usr/local/mysql/bin/mysql
MariaDB [(none)]> use MySQL
MariaDB [mysql]> UPDATE user SET Password=password (' Jingpei ') WHERE user= ' root ';
MariaDB [mysql]> SELECT User,host,password from User;
MariaDB [mysql]> DROP USER ' @ ' localhost ';
MariaDB [mysql]> DROP USER ' @ ' centos69-2.surmount.net ';
MariaDB [mysql]> FLUSH privileges;

2-3-7: Export man manual file, header file, output library file, path:
# Vim/etc/man.config
......
Manpath/usr/local/mysql/man
---> Output man manual to the search path of the man command;

# Ln-sv/usr/local/mysql/include/mysql/usr/include/mysql
---> Output header file to System header file path/usr/include;

# echo '/usr/local/mysql/include ' >/etc/ld.so.conf.d/mysql.conf
# Ldconfig
---> Output mysql library file to the system library to find the path;

# vim/etc/profile.d/mysql.sh
Export path=/usr/local/mysql/bin/: $PATH
# source/etc/profile.d/mysql.sh
---> Modify the PATH environment variable so that the system can directly use the relevant commands of MySQL;

2-4: Install and configure PHP (PHP for Apache module):

2-4-1: Install PHP-dependent packages:
# yum Install Bzip2-devel-y

2-4-2: Compile and install PHP:
# Tar XF php-5.6.31.tar.bz2
# CD php-5.6.31
#./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
......
Configure:error:xml2-config not found. Please check your LIBXML2 installation.
---> An error occurred, the analysis could be a missing Libxml2-devel package:
# yum Install Libxml2-devel-y
#./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
......
Libtool:warning:remember to run ' Libtool--finish/root/sources/php-5.6.31/libs '
---> A warning appears:
# Make && make install

2-4-3: Provide a configuration file for PHP:
# CP Php.ini-production/etc/php.ini
---> Description:
1. In order to support the two mpm of the Apache worker or event, the--ENABLE-MAINTAINER-ZTS option is used at compile time.
2, if you use PHP5.3 or above, in order to link the MySQL database, you can specify MYSQLND, so you do not need to install the MySQL or MySQL development package. MYSQLND is available from PHP 5.3 and can be bound to it at compile time (instead of relying on the specific MySQL client library bindings), but it is the default setting starting with PHP 5.4.
#./configure--with-mysql=mysqlnd--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd

2-4-4: Configure Apache to support PHP:
# cd/etc/httpd24/
# CP Httpd.conf{,.bak}
# Vim Httpd.conf
......
LoadModule Php5_module modules/libphp5.so
.....
AddType application/x-httpd-php. php
AddType Application/x-httpd-php-source. Phps
......
<ifmodule dir_module>
DirectoryIndex index.php index.html
</IfModule>
......
#/etc/init.d/httpd24 Restart
# Httpd-m | grep php
Php5_module (Shared)

2-4-5: Build a PHP page and test the PHP connection to DB:
# vim/usr/local/apache/htdocs/index.php
<?php
$link = mysql_connect (' localhost ', ' root ', ' Jingpei ');
if (! $link)
{
Die (' Could not connect: '. Mysql_error ());
}
Echo ' Connected successfully ';
Mysql_close ($link);
Phpinfo ()
?>

2-4-6: Access test:
http://192.168.1.67/index.php
Connected successfully
PHP Version 5.6.31

Third, installation phpMyAdmin:

3-1:phpmyadmin Introduction:
PhpMyAdmin is a GUI management tool for MySQL or MARIADB database, based on PHP and web as the working form.

3-2:phpmyadmin Installation:
# Unzip Phpmyadmin-4.7.4-all-languages.zip
# MV PHPMYADMIN-4.7.4-ALL-LANGUAGES/USR/LOCAL/APACHE/HTDOCS/PMA
# CD/USR/LOCAL/APACHE/HTDOCS/PMA
# CP config.sample.inc.php config.inc.php
# Vim config.inc.php
......
$cfg [' blowfish_secret '] = ' 1qazxsw23edcvfr45tgbnhy67ujm ';
......

3-3: Access test:
Http://192.168.1.67/pma


Iv. Install the XCache for PHP acceleration:

4-1: Pre-installation stress test:
# ab-c 20-n http://192.168.1.67/pma/index.php
---> Record the number of responses per second for easy comparison.

4-2: Installation and configuration XCache:
# Tar XF xcache-3.2.0.tar.bz2
# CD xcache-3.2.0
#/usr/local/php/bin/phpize
#./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config
# Make && make install
......
Installing Shared extensions:/usr/local/php/lib/php/extensions/no-debug-zts-20131226/
# MKDIR-PV/ETC/PHP.D
# cp/root/sources/xcache-3.2.0/xcache.ini/etc/php.d/
# Vim/etc/php.d/xcache.ini
Extension =/usr/local/php/lib/php/extensions/no-debug-zts-20131226/xcache.so
......
Xcache.admin.enable_auth = Off
#/etc/init.d/httpd24 Restart
http://192.168.1.67/index.php
---> Find the XCache feature in the Open page.

4-3: Post-Installation pressure test and comparison
---> Test environment:
Cpu:intel (R) Core (TM) i3-4160 CPU @ 3.60GHz
Memory: 512MB
# ab-c 20-n http://192.168.1.67/pma/index.php
......
Requests per second:49.72 [#/sec] (mean)
......
# ab-c 20-n http://192.168.1.67/pma/index.php
......
Requests per second:195.00 [#/sec] (mean)

---> 3-4 times faster response times compared to multiple stress tests.

Compile and install on CentOS6 to implement lamp (Php-modules) +phpmyadmin installation process full record

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.