Compile and install LNMP in CentOS 6.8
Build Environment: CentOS 6.8, nginx 1.9.14, mysql 5.6.23, php 5.6.17
I. Purpose: LNMP has become a mainstream web Server construction solution. The company's ECstore and Discuz plan is used to replace Zabbix of nagios + check_mk monitoring platform. All are based on LNMP. The establishment of the standalone LNMP will prepare for the follow-up comprehensive understanding of e-commerce clusters, and record the construction process as a reference for building the environment in the future.
2. Prepare the LNMP installation environment:
Disable firewall and selinux
Service iptables stop
Chkconfig iptables off
Setenforce 0
Vi/etc/sysconfig/selinux
SELINUX = disabled # enforcing changed to disabled
Install dependency packages
Yum-y install gcc-c ++ autoconf libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses- devel curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn-devel openssl-devel openldap-clients openldap-servers make libtool * git tree bison pcre-devel perl gd-gd- devel
Install libiconv (supports Code Conversion to functions)
Tar xf libiconv-1.14.tar.gz
Cd libiconv-1.14/
./Configure -- prefix =/usr/local
Make & make install
Install libmcrypt (encryption algorithm extension library, supporting DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER +, and other algorithms)
Tar xf libmcrypt-2.5.8.tar.gz
Cd libmcrypt-2.5.8
./Configure
Make & make install
Cd libltdl/
./Configure -- enable-ltdl-install # Load dynamic library
Make & make install
Install mhash (Mhash is an extension library based on discrete mathematics that cannot be reversed in php encryption mode. It is disabled by default. Mhash can be used to create verification values, message digests, message authentication codes, and save key information without the need for the original text)
1234 tar xf mhash-0.9.9.9.tar.bz2
Cd mhash-0.9.9.9
./Configure
Make & make install
Install mcrypt (Mcrypt is an important extension library supporting encryption in php. mcrypt extension library can implement encryption and decryption, that is, it can both encrypt plaintext and restore ciphertext .)
123456 cd/usr/local/src
Tar zxvf mcrypt-2.6.8.tar.gz
Cd mcrypt-2.6.8/
Export LD_LIBRARY_PATH =/usr/local/lib: $ LD_LIBRARY_PATH # takes effect temporarily
./Configure
Make & make install
You can also add library files in either of the following ways:
12345678910 ln-s/usr/local/lib/libmcrypt. la/usr/lib/libmcrypt. la
Ln-s/usr/local/lib/libmcrypt. so/usr/lib/libmcrypt. so
Ln-s/usr/local/lib/libmcrypt. so.4/usr/lib/libmcrypt. so.4
Ln-s/usr/local/lib/libmcrypt. so.4.4.8/usr/lib/libmcrypt. so.4.4.8
Ln-s/usr/local/lib/libmhash. a/usr/lib/libmhash.
Ln-s/usr/local/lib/libmhash. la/usr/lib/libmhash. la
Ln-s/usr/local/lib/libmhash. so/usr/lib/libmhash. so
Ln-s/usr/local/lib/libmhash. so.2/usr/lib/libmhash. so.2
Ln-s/usr/local/lib/libmhash. so.2.0.1/usr/lib/libmhash. so.2.0.1
Ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-config
Vim/etc/ld. so. conf
/Usr/local/lib/
Ldconfig
Install cmake (MySQL 5.5 and later versions have been canceled by using./configure for compilation and configuration, and replaced by the cmake tool)
Tar xf cmake-3.4.1.tar.gz
Cd cmake-3.4.1
./Bootstrap
Make & make install
Note: to decompress all files together, use find/usr/local/src/* .tar.gz-exec tar xf {}\;
Iii. MySQL compilation and Installation
New mysql user
Groupadd-r mysql
Useradd-r-g mysql
Create a directory for MySQL
Mkdir-p/usr/local/mysql
Mkdir-p/data/mysqldb
Compile and install
Tar xf mysql-5.6.23.tar.gz
Cd mysql-5.6.23
Cmake-DCMAKE_INSTALL_PREFIX =/usr/local/mysql-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci-rows = 1-rows = 1-rows =/data/mysqldb-rows = 3306- DENABLE_DOWNLOADS = 1-DSYSCONFDIR =/etc-DWITH_SSL = system-DWITH_ZLIB = system-DWITH_LIBWRAP = 0
Make & make install
Modify mysql Directory Permissions
Cd/usr/local/mysql
Chown-R mysql: mysql.
Cd/data/mysqldb
Chown-R mysql: mysql.
Initialize the mysql database
Cd/usr/local/mysql
./Scripts/mysql_install_db -- user = mysql -- datadir =/data/mysqldb
Compile and modify/etc/my. cnf
[Mysql]
# CLIENT #
Port = 3306
Socket =/data/mysqldb/mysql. sock
[Mysqld]
# GENERAL #
User = mysql
Default-storage-engine = InnoDB
Socket =/data/mysqldb/mysql. sock
Pid-file =/data/mysqldb/mysql. pid
# MyISAM #
Key-buffer-size = 32 M
Myisam-recover = FORCE, BACKUP
# SAFETY #
Max-allowed-packet = 16 M
Max-connect-errorrs = 1000000
# Data storage #
Datadir =/data/mysqldb/
# Binary logging #
Log-bin =/data/mysqldb/mysql-bin
Expire-logs-days = 14
Sync-binlog = 1
# REPLICATION #
Skip-slave-start = 1
Relay-log =/data/mysqldb/relay-bin
Slave-net-timeout = 60
# Caches and limits #
Tmp-table-size = 32 M
Max-heap-table-size = 32 M
Query-cache-type = 0
Query-cache-size = 0
Max-connections = 500
Thread-cache-size = 50
Open-files-limit = 65535
Table-definition-cache = 4096
Table-open-cache = 4096
# INNODB #
Innodb-flush-method = O_DIRECT
Innodb-log-files-in-group = 2
Innodb-log-file-size = 64 M
Innodb-flush-log-at-trx-commit = 1
Innodb-file-per-table = 1
Innodb-buffer-pool-size = 592 M
# LOGGING #
Log-error =/data/mysqldb/mysql-error.log
Log-queries-not-using-indexes = 1
Slow-query-log = 1
Slow-query-log-file =/data/mysqldb/mysql-slow.log
Copy the MySQL Startup File and its command and add it to PATH
Cp support-files/mysql. server/etc/init. d/mysqld
Vim/etc/profile. d/mysql. sh
PATH =/usr/local/mysql/bin:/usr/local/mysql/lib: $ PATH
Export PATH
Source/etc/profile. d/mysql. sh
Start MySQL and add a startup Item
Service mysqld start
Chkconfig mysqld on
Set MySQL logon Permissions
Drop user ''@ localhost;
Drop user ''@ hostname;
Update mysql. user set password = password ('*******');
Flush privileges;
Iv. Nginx compilation and Installation
New nginx user
Groupadd-r nginx
Useradd-g nginx-r nginx
Create the required directory
Mkdir-pv/var/tmp/nginx/client
Compile and install nginx
Tar xf nginx-1.9.14.tar.gz
Cd nginx-1.9.14
. /Configure -- prefix =/usr/local/nginx -- sbin-path =/usr/local/nginx/sbin/nginx -- conf-path =/etc/nginx. conf -- error-log-path =/var/log/nginx/error. log -- http-log-path =/var/log/nginx/access. log -- pid-path =/var/run/nginx. pid -- lock-path =/var/lock/nginx. lock -- user = nginx -- group = nginx -- with-http_ssl_module -- with-http_flv_module -- with-http_stub_status_module -- with-http_gzip_static_module -- http-client-body-temp-path =/var/tmp/nginx/client/-- http- proxy-temp-path =/var/tmp/nginx/proxy/-- http-fastcgi-temp-path =/var/tmp/nginx/fcgi/-- http-uwsgi-temp- path =/var/tmp/nginx/uwsgi -- http-scgi-temp-path =/var/tmp/nginx/scgi -- with-pcre
Make & make install
Edit Startup Script
Vim/etc/rc. d/init. d/nginx
#! /Bin/sh
#
# Nginx-this script starts and stops the nginx daemon
#
# Chkconfig:-85 15
# Description: Nginx is an HTTP (S) server, HTTP (S) reverse \
# Proxy and IMAP/POP3 proxy server
# Processname: nginx
# Config:/etc/nginx. conf
# Config:/etc/sysconfig/nginx
# Pidfile:/var/run/nginx. pid
# Source function library.
./Etc/rc. d/init. d/functions
# Source networking configuration.
./Etc/sysconfig/network
# Check that networking is up.
["$ NETWORKING" = "no"] & exit 0
Nginx = "/usr/local/nginx/sbin/nginx"
Prog = $ (basename $ nginx)
NGINX_CONF_FILE = "/etc/nginx. conf"
[-F/etc/sysconfig/nginx] &./etc/sysconfig/nginx
Lockfile =/var/lock/subsys/nginx
Make_dirs (){
# Make required directories
User = 'nginx-V 2> & 1 | grep "configure arguments:" | sed's/[^ *] * -- user = \ ([^] * \). */\ 1/G '-'
Options = '$ nginx-V 2> & 1 | grep' configure arguments :''
For opt in $ options; do
If ['echo $ opt | grep'. *-temp-path'']; then
Value = 'echo $ opt | cut-d "="-f 2'
If [! -D "$ value"]; then
# Echo "creating" $ value
Mkdir-p $ value & chown-R $ user $ value
Fi
Fi
Done
}
Start (){
[-X $ nginx] | exit 5
[-F $ NGINX_CONF_FILE] | exit 6
Make_dirs
Echo-n $ "Starting $ prog :"
Daemon $ nginx-c $ NGINX_CONF_FILE
Retval =$?
Echo
[$ Retval-eq 0] & touch $ lockfile
Return $ retval
}
Stop (){
Echo-n $ "Stopping $ prog :"
Killproc $ prog-QUIT
Retval =$?
Echo
[$ Retval-eq 0] & rm-f $ lockfile
Return $ retval
}
Restart (){
Configtest | return $?
Stop
Sleep 1
Start
}
Reload (){
Configtest | return $?
Echo-n $ "Reloading $ prog :"
Killproc $ nginx-HUP
RETVAL =$?
Echo
}
Force_reload (){
Restart
}
Configtest (){
$ Nginx-t-c $ NGINX_CONF_FILE
}
Rh_status (){
Status $ prog
}
Rh_status_q (){
Rh_status>/dev/null 2> & 1
}
Case "$1" in
Start)
Rh_status_q & exit 0
$1
;;
Stop)
Rh_status_q | exit 0
$1
;;
Restart | configtest)
$1
;;
Reload)
Rh_status_q | exit 7
$1
;;
Force-reload)
Force_reload
;;
Status)
Rh_status
;;
Condrestart | try-restart)
Rh_status_q | exit 0
;;
*)
Echo $ "Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest }"
Exit 2
Esac
Set start and start services
Chmod + x/etc/rc. d/init. d/nginx
Chkconfig -- add nginx
Chkconfig nginx on
Service nginx start
V. PHP compilation and Installation
Solve the library dependency of php installation
Cp-frp/usr/lib64/libldap */usr/lib/
Echo/usr/local/mysql/lib>/etc/ld. so. conf. d/mysql-x86_64.conf
Ldconfig-v
Compile and install php
Tar xf php-5.6.17.tar.gz
Cd php-5.6.17
. /Configure -- prefix =/usr/local/php -- with-mysql =/usr/local/mysql -- with-mysqli =/usr/local/mysql/bin/mysql_config --- iconv-dir =/usr/local -- with-openssl -- enable-mbstring -- with-freetype-dir -- with-jpeg-dir -- with-png-dir -- with-zlib -- -libxml-dir =/usr -- enable-xml -- disable-rpath -- enable-bcmath -- enable-shmop -- enable-sysvsem -- enable-inline-optimization -- enable-mbregex -- enable-rpath- mbstring -- with-gd -- enable-gd-native-ttf -- with-mhash -- enable-pcntl -- enable-sockets -- with-mcrypt -- with-ldap-sasl -- with-xmlrpc -- enable-zip -- enable-soap -- with-bz2 -- with-config-file-path =/etc -- enable-fpm -- with-config-file-scan-dir =/ etc/php. d -- enable-maintainer-zts
Make ZEND_EXTRA_LIBS = '-liconv'
Make install
Copy the PHP configuration file
Cp php. ini-production/etc/php. ini
Copy the php-fpm configuration file
Cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
Set the php-fpm STARTUP script and start it upon startup
Cp sapi/fpm/init. d. php-fpm/etc/rc. d/init. d/php-fpm
Chmod + x/etc/rc. d/init. d/php-fpm
Chkconfig -- add php-fpm
Chkconfig php-fpm on
Service php-fpm start
Vi. Basic web Functions
Nginx and php functions integration
Vim/etc/nginx. conf
# Location ~ \. Php $ {
# Root html;
# Fastcgi_pass 127.0.0.1: 9000;
# Fastcgi_index index. php;
# Fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name;
# Include fastcgi_params;
#}
# Change
Location ~ \. Php $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Include fastcgi_params;
}
LNMP test page added
Vim/usr/local/nginx/html/test. php
<? Php
$ Link = mysql_connect ('2017. 0.0.1 ', 'root', 'you _ passwd ');
If ($ link)
Echo "It's OK, Frank ";
Else
Echo "Failed, Frank ";
Mysql_close;
Phpinfo ();
?>
Nginx overload
Service nginx reload
Access http: // ip/test. php, LNMP test successful.
VII. Postscript
Since the end of last year, LAMP and LNMP have been built on and off multiple times. When it was built, it was forgotten. It is estimated that it was the cause of poor foundation. Although it was a little difficult to build this project, I decided to write a blog post, but it was still a little stressful. I verified it twice before and after, and it was still feasible. This nginx and php configuration optimization and plug-ins are not involved, and will be completed later.
Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL
Install the LAMP \ Vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04
Build and install the LNMP production environment in CentOS 6.4
Practical Production Environment-LNMP architecture compilation and installation + SSL encryption implementation
LNMP full-featured compilation and installation for CentOS 6.3 notes
Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)
Nginx startup failure occurs during LNMP deployment.
Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)