LNMP (nginx + mysql + php) Environment/architecture one-click installation script

Source: Internet
Author: User

LNMP (nginx + mysql + php) Environment/architecture one-click installation script

LNMP (nginx + mysql + php) Environment/architecture one-click installation script, which has passed the test on CentOS 7.1, with a time of 27 minutes and hardware environment (1G, 1U ). This script has the PHP accelerator xcache installed:

#! /Bin/bash

# Role of this script: one-click online deployment of LNMP
# Write: King
# Date: 2015-03-19

# The mysql data storage directory is/data/mysql
# The main configuration file of php is in/usr/local/php/etc.
# Nginx web program directory/usr/local/nginx/html/index, Master configuration directory/usr/local/nginx/conf/nginx. conf

# Source code download directory
SoftDir = '/usr/local/src'

# Define the Installation Log Path
LOG_INS = '/var/log/install. Log'

# Define the Mysql source code directory:
MysqlS = '/usr/local/mysql'

# Define make
Function MAKE (){
If ['echo $? '-Eq 0]; then
Make >>$ LOG_INS 2> & 1
Else
Exit
Fi
}

# Define make install
Function MAKE_INS (){
If ['echo $? '-Eq 0]; then
Make install> $ LOG_INS 2> & 1
Else
Exit
Fi
}

# Install System Extension Source: http://dl.Fedoraproject.org/pub/epel
If ['awk' {print $3} '/etc/RedHat-release | awk-F'. ''{print $1}''-eq 6]; then
Rpm-ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm> $ LOG_INS 2> & 1
Elif ['awk' {print $4} '/etc/redhat-release | awk-F'. ''{print $1}''-eq 7]; then
Rpm-ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm> $ LOG_INS 2> & 1
Fi

# Install the system O & M package:
Yum install-y lrzsz gcc-c ++ bzip2 bzip2-devel make man vim tree unzip wget lua-devel lua-static patch libxml2-devel libxslt-devel gd-devel ntp ntpdate screen sysstat tree rsync lsof autoconf gettext-devel automake libtool git >>$ LOG_INS 2> & 1

# Upgrade the system:
Yum update-y> $ LOG_INS 2> & 1

# Replace selinux Configuration:
Sed-I's/SELINUX = enforcing/SELINUX = disabled/'/etc/selinux/config

# Download and install Mysql: http://cdn.mysql.com/Downloads
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

# Decompress:
Tar zxf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

# Rename Mysql due to moving and extracting directories:
Music mysql-5.6.26-linux-glibc2.5-x86_64/usr/local/mysql

# Add a mysql System User:
If [-z 'grep mysql/etc/passwd']; then
Useradd-s/sbin/nologin mysql
Fi

# Create a mysql initialization data directory:
If [! -D "/data/mysql"]; then
Mkdir-p/data/mysql
Fi

# Modify the master and Group of the mysql initialization directory to mysql:
Chown-R mysql. mysql/data/mysql/

# Initialization
Cd $ MysqlS &./scripts/mysql_install_db -- datadir =/data/mysql -- user = mysql >>$ LOG_INS 2> & 1

# Backup system default my. cnf file:
Mv/etc/my. cnf {,. bak}

# Copy the mysql master configuration file to the etc directory and rename it my. cnf
\ Cp support-files/my-default.cnf/etc/my. cnf

# Copy the mysql STARTUP script to the/etc/init. d directory:
\ Cp support-files/mysql. server/etc/init. d/mysqld

# Grant startup 755 permissions:
Chmod 755/etc/init. d/mysqld

# Modify the configuration of the my. cnf file as follows:
Cat <EOF>/etc/my. cnf
[Mysqld]
Pid-file =/data/mysql. pid
Log-error =/var/log/mysql. log
Datadir =/data/mysql
Basedir =/usr/local/mysql
Character-set-server = utf8
Port = 3306
Socket =/tmp/mysql. sock
Key_buffer_size = 256 M
Max_allowed_packet = 1 M
Table_open_cache = 256
Sort_buffer_size = 1 M
Read_buffer_size = 1 M
Read_rnd_buffer_size = 4 M
Myisam_sort_buffer_size = 64 M
Thread_cache_size = 8
Query_cache_size = 16 M
Thread_concurrency = 8
Binlog_format = mixed
Server-id = 1
Slow-query-log = 1
Slow-query-log-file =/data/mysql/mysql-slow.log.
Log-bin = mysql-bin
Log-bin-index = mysql-bin.index
Symbolic-links = 0
Skip-name-resolve

[Client]
Port = 3306
Socket =/tmp/mysql. sock
Default-character-set = utf8

[Mysqldump]
Quick
Max_allowed_packet = 16 M

# [Mysqld_safe]

[Mysql]
No-auto-rehash

[Myisamchk]
Key_buffer_size = 128 M
Sort_buffer_size = 128 M
Read_buffer = 2 M
Write_buffer = 2 M

[Mysqlhotcopy]
Interactive-timeout
EOF

# Start mysql:
Service mysqld start

If ['echo $? '-Eq 0]; then
Echo "Mysql started"
Else
Exit
Fi

# Set Mysqld to random start:
Chkconfig -- add mysqld & chkconfig mysqld on

#============================================ Install LTP ========================================================
# Download LTP:
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/ltp-full-20150420.tar.bz2

# Decompress
Tar jxf ltp-full-20150420.tar.bz2

# Configure compilation parameters:
Cd./ltp-full-20150420 &./configure> $ LOG_INS 2> & 1

# Compilation and Installation
MAKE & MAKE_INS

#======================================================== Install openssl1.0.2 ========================================================
# Download openssl:
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/openssl-1.0.2.tar.gz

# Decompress:
Tar zxf openssl-1.0.2.tar.gz

# Enter the extract directory and configure the compilation parameters:
Cd./openssl-1.0.2 &./config> $ LOG_INS 2> & 1

# Compilation and Installation
MAKE & MAKE_INS

#========================================== Install curl -7.45.0 ============================================== =
# Download:
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/curl-7.45.0.tar.gz

# Decompress:
Tar zxf curl-7.45.0.tar.gz

# Enter the extract directory and configure the compilation parameters:
Cd./curl-7.45.0 &./configure> $ LOG_INS 2> & 1

# Compilation and Installation
MAKE & MAKE_INS

#============================================================ Install the libmcrypt-2.5.8 ========================================
# Download:
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/libmcrypt-2.5.8.tar.gz

# Decompress:
Tar zxf libmcrypt-2.5.8.tar.gz

# Enter the extract directory and configure the compilation parameters:
Cd./libmcrypt-2.5.8 &./configure> $ LOG_INS 2> & 1

# Compilation and Installation
MAKE & MAKE_INS

#===================================================== Install PHP 5.5.22
# Download PHP 5.5.22
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/php-5.5.30.tar.gz

# Decompress PHP:
Tar zxf php-5.5.30.tar.gz

# Adding a php-fpm user is not allowed to log on to the system
Useradd-s/sbin/nologin php-fpm

# Enter the PHP decompression directory and configure the compilation parameters:
Cd. /php-5.5.30 &&. /configure -- prefix =/usr/local/php -- with-config-file-path =/usr/local/php/etc -- enable-fpm -- with-fpm-user = php -fpm -- with-fpm-group = php-fpm -- with-mysql =/usr/local/mysql -- with-mysql-sock =/tmp/mysql. sock -- with-libxml-dir -- with-gd -- with-jpeg-dir -- with-png-dir -- with-freetype-dir -- with-iconv-dir -- with-zlib- dir -- with-mcrypt -- enable-soap -- enable-gd-native-ttf -- enable-ftp -- enable-mbstring -- enable-exif -- enable-zend-multibyte -- disable-ipv6 --- pear -- with-curl -- with-openssl -- with-mysqli -- enable-mysqlnd -- with-gettext >>$ LOG_INS 2> & 1

# Compilation and Installation
MAKE & MAKE_INS

# Copy the Php master Configuration:
\ Cp php. ini-production/usr/local/php/etc/php. ini

# Create a php-fpm main configuration file:
Cat <EOF>/usr/local/php/etc/php-fpm.conf
[Global]
Pid =/usr/local/php/var/run/php-fpm.pid
Error_log =/usr/local/php/var/log/php-fpm.log
[Www]
Listen = 127.0.0.1: 9000
User = php-fpm
Group = php-fpm
Pm = dynamic
Pm. max_children = 50
Pm. start_servers = 20
Pm. min_spare_servers = 5
Pm. max_spare_servers = 35
Pm. max_requests = 500
Rlimit_files = 1024
EOF

# Test the configuration of php-fpm:
/Usr/local/php/sbin/php-fpm-t
If ['echo $? '-Eq 0]; then
Echo "php-fpm installed successfully"
Else
Exit
Fi

# Copy the php-fpm STARTUP script:
\ Cp sapi/fpm/init. d. php-fpm/etc/init. d/php-fpm

# Grant the script executable permission:
Chmod 755/etc/init. d/php-fpm

# Disable php version information:
Sed-I's/expose_php = On/expose_php = Off/G'/usr/local/php/etc/php. ini

# Write a php-fpm file to start at random:
Chkconfig -- add php-fpm & chkconfig php-fpm on

# Start php-fpm
Service php-fpm start

#===================================================== Install pcre2-10.00
# Download
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/pcre-8.37.tar.gz

# Decompress:
Tar zxf pcre-8.37.tar.gz

# Access pcre and configure compilation parameters:
Cd./pcre-8.37 &./configure> $ LOG_INS 2> & 1

# Compilation and Installation
MAKE & MAKE_INS

#===================================================== Add libmaxminddb ========================================
# Download:
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/libmaxminddb-1.1.1.tar.gz

# Decompress:
Tar zxf libmaxminddb-1.1.1.tar.gz

Cd./libmaxminddb-1.1.1 &./configure> $ LOG_INS 2> & 1

# Compilation and Installation
MAKE & MAKE_INS

#===================================================== Add a geoip2 module =============================================
# Download
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/ngx_http_geoip2_module-master.zip

# Decompress:
Unzip ngx_http_geoip2_module-master.zip> $ LOG_INS 2> & 1

#===================================================== Add libuwind ==========================================
# Download:
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/libunwind-1.1.tar.gz

# Decompress:
Tar zxf libunwind-1.1.tar.gz

# Enter the extract directory and configure the compilation parameters ::
Cd./libunwind-1.1 &./configure> $ LOG_INS 2> & 1

# Compilation and Installation
MAKE & MAKE_INS

#===================================================== Add gperftools ========================================
# Download:
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/gperftools-master.zip

# Decompress:
Unzip gperftools-master.zip

# Enter the extract directory and execute autogen. sh to generate the configuration file:
Cd./gperftools-master &./autogen. sh >>$ LOG_INS 2> & 1

# Configure compilation parameters:
If ['echo $? '-Eq 0]; then
./Configure> $ LOG_INS 2> & 1
Else
Exit
Fi

# Compilation and Installation
MAKE & MAKE_INS

#===================================================== Install Tengine 2.1.0 ========================================
# Download
Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/nginx-1.8.0.tar.gz
# Decompress:
Tar zxf nginx-1.8.0.tar.gz

# Enter the extract directory and configure the compilation parameters:
Cd. /nginx-1.8.0 &&. /configure -- prefix =/usr/local/nginx -- with-http_realip_module -- with-http_sub_module -- with-http_dav_module -- with-http_gzip_static_module -- with-http_stub_status_module -- with-http_flv_module -- with-http_mp4_module -- with-http_gunzip_module -- with-http_gzip_static_module -- with-http_auth_request_module -- with-http_secure_link_module -- with-http_stub_status_module -- with-http_ssl_module -- http- log-path =/var/log/nginx_access.log -- with-google_perftools_module -- with-pcre =/usr/local/src/pcre-8.37 -- with-openssl =/usr/local/src/openssl-1.0.2 -- add -module =/usr/local/src/ngx_http_geoip2_module-master> $ LOG_INS 2> & 1

# Compilation and Installation
MAKE & MAKE_INS

# Set soft links
Ln-s/usr/local/lib/libmaxminddb. so.0/usr/lib64
Ln-s/usr/local/lib/libprofiler. so.0/usr/lib64
Ln-s/usr/local/lib/libunwind. so.8/usr/lib64

# Check whether the nginx configuration after Initialization is correct
/Usr/local/nginx/sbin/nginx-t
If ['echo $? '-Eq 0]; then
Echo "Nginx installed successfully! "
Else
Exit
Fi

# Create an nginx Startup Script
Cat <EOF>/etc/init. d/nginx
#! /Bin/bash
# Chkconfig:-30 21
# Description: http service.
# Source Function Library
./Etc/init. d/functions
# Nginx Settings

NGINX_SBIN = "/usr/local/nginx/sbin/nginx"
NGINX_CONF = "/usr/local/nginx/conf/nginx. conf"
NGINX_PID = "/usr/local/nginx/logs/nginx. pid"
RETVAL = 0
Prog = "Nginx"

Start (){
Echo-n \ $ "Starting \ $ prog :"
Mkdir-p/dev/shm/nginx_temp
Daemon \ $ NGINX_SBIN-c \ $ NGINX_CONF
RETVAL =\$?
Echo
Return \ $ RETVAL
}

Stop (){
Echo-n \ $ "Stopping \ $ prog :"
Killproc-p \ $ NGINX_PID \ $ NGINX_SBIN-TERM
Rm-rf/dev/shm/nginx_temp
RETVAL =\$?
Echo
Return \ $ RETVAL
}

Reload (){
Echo-n \ $ "Reloading \ $ prog :"
Killproc-p \ $ NGINX_PID \ $ NGINX_SBIN-HUP
RETVAL =\$?
Echo
Return \ $ RETVAL
}

Restart (){
Stop
Start
}

Configtest (){
\ $ NGINX_SBIN-c \ $ NGINX_CONF-t
Return 0
}

Case "\ $1" in
Start)
Start
;;
Stop)
Stop
;;
Reload)
Reload
;;
Restart)
Restart
;;
Configtest)
Configtest
;;
*)
Echo $ "Usage: \ $0 {start | stop | reload | restart | configtest }"
RETVAL = 1
Esac

Exit \ $ RETVAL
EOF

# Grant the script executable permission
Chmod 755/etc/init. d/nginx

# Back up the nginx main configuration file
\ Cp/usr/local/nginx/conf/nginx. conf {,. bak}

# Re-configure nginx:
Cat <EOF>/usr/local/nginx/conf/nginx. conf
Error_log/var/log/nginx_error.log crit;
Pid/usr/local/nginx/logs/nginx. pid;
Worker_processes 1;
Events {
Worker_connections 1024;
}
Http {
Include mime. types;
Default_type application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
Server_tokens off;
Server {
Listen 80;
Server_name localhost;
Location /{
Root html;
Index index.html index.htm index. php;
}
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
}
Location ~ \. Php \ $ {
Root html;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME \ $ document_root \ $ fastcgi_script_name;
Include fastcgi_params;
}
}
}
EOF

# Create a PHP test file:
Echo "<? Php echo phpinfo ();?> ">/Usr/local/nginx/html/index. php

Registry.index.html:
Mv/usr/local/nginx/html/index.html {,. bak}

# Start nginx:
Service nginx start

# Write nginx to start at random:
Chkconfig -- add nginx & chkconfig nginx on

# Enable port 80 of the firewall
Iptables-I INPUT-p tcp -- dport 80-j ACCEPT

# Save firewall configurations
Service iptables save

# Restart the Firewall:
Service iptables restart

# Set environment variables for nginx, mysql, and php:
Echo "PATH = $ PATH:/usr/local/php/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin: /usr/local/php/sbin ">/etc/profile

# Refresh the environment variable configuration to make it take effect immediately:
Source/etc/profile

##=================================================== = Install the php accelerator xcache 3.2.0 ======================================== =
# Official address: http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz

Cd $ SoftDir & wget-q http://www.linuser.com/share/soft/xcache-3.2.0.tar.gz

# Decompress
Tar zxf xcache-3.2.0.tar.gz

# Execute phpize to generate the xcache configure file
Cd./xcache-3.2.0 &/usr/local/php/bin/phpize -- clean &/usr/local/php/bin/phpize

# Configure compilation parameters:
./Configure -- enable-xcache -- with-php-config =/usr/local/php/bin/php-config> $ LOG_INS 2> & 1

# Compilation and Installation
MAKE & MAKE_INS

# Combining xcache with php
Echo "extemsiobn_dir = '/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/'">/usr/local/php/etc/php. ini
Echo "extension = xcache. so">/usr/local/php/etc/php. ini

# Check for php errors:
/Usr/local/php/sbin/php-fpm-t

# Restart php-fpm:
Service php-fpm restart

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)

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.