CentOS system initially installs MySQL, PHP, and Nginx scripts

Source: Internet
Author: User
Tags bz2 fpm hash install php openssl vars iptables openldap
The code is as follows Copy Code
#!/bin/sh
# by Jet Ma from www.javatang.com
# version v0.2 build20121011-1516
# Install Nginx, MySQL and PHP
# CentOS 5.5 64bit

#-----------Configuration Information-----------
# MySQL installation directory
Mysql_home= '/usr/local/mysql '
# The password for the MySQL root account
Mysql_root_passwd= ' ROOT '
# PHP installation directory
Php_home= '/usr/local/php '
# Nginx installation directory
Nginx_home= '/usr/local/nginx '

#-----------Detect if it is a root account-----------
If [$ (id-u)!= "0"]; Then
Echo-e "e[1;31m This scripts must under root user or group!! E[0m "
Echo
Exit 2
Fi

# Open Account permission file first
Chattr-i/etc/passwd
Chattr-i/etc/shadow
Chattr-i/etc/group
Chattr-i/etc/gshadow
# Close Firewall
/etc/init.d/iptables stop

#-----------The base Dependency library required for installation-----------
Echo-e "e[1;36m the base Dependency library required for installation ... e[0m"
Lang=c
Yum-y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-deve L zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel Curl curl-devel e2fsprogs E2 Fsprogs-devel krb5 krb5-devel libidn libidn-devel OpenSSL openssl-devel openldap openldap-devel Nss_ldap Openldap-clients openldap-servers

#-----------Install MySQL-----------
Echo-e "e[1;36m install mysql ... e[0m"
CD ~
mkdir Downloads
CD Downloads
Wget-c http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.65.tar.gz/from/http://cdn.mysql.com/
Tar xzvf mysql-5.1.65.tar.gz
CD mysql-5.1.65
./configure--prefix= $MYSQL _home--with-charset=utf8--with-extra-charsets=all--without-debug- Enable-thread-safe-client--enable-assembler--with-client-ldflags=-all-static--with-mysqld-ldflags=-all-static- -with-big-tables--with-readline--with-ssl--with-embedded-server--enable-local-infile--without-isam-- With-plugins=innobase
Make && make install
# Set up users to start
Groupadd MySQL
Useradd-s/sbin/nologin-m-G MySQL MySQL
CD $MYSQL _home
# Set installation directory permissions to MySQL users and user groups
Chown-r MySQL.
Chgrp-r MySQL.
# Install Database
bin/mysql_install_db--user=mysql
Chown-r Root.
Chown-r mysql var
CP SHARE/MYSQL/MY-MEDIUM.CNF/ETC/MY.CNF
Sed-i ' s/skip-locking/skip-external-locking/g '/etc/my.cnf
CP Share/mysql/mysql.server/etc/init.d/mysql
chmod +x/etc/init.d/mysql
/etc/init.d/mysql start
Bin/mysqladmin-uroot Password $MYSQL _root_passwd
History-c
/etc/init.d/mysql restart

#-----------Install PHP and PHP-FPM-----------
Echo-e "e[1;36m install PHP with php-fpm ... e[0m"
# Create Account
Groupadd www
Useradd-s/sbin/nologin-m-G www www
# download Libmcrypt, two files
CD ~/downloads
Wget-c "http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz?ts=1347243907 &use_mirror=ncu "
Wget-c "http://downloads.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz?r=&ts=1347244005 &USE_MIRROR=NCHC "
# download Libmhash
Wget-c "http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2?ts=1347245105& Use_mirror=ncu "
# First Install Libmcrypt
Tar zxvf libmcrypt-2.5.8.tar.gz
CD libmcrypt-2.5.8
./configure
Make && make install
Ldconfig
CD libltdl/
./configure--enable-ltdl-install
Make && make install
# Next install Mhash, because MCrypt needs mhash dependencies
Cd.. /.. /
Tar jxvf mhash-0.9.9.9.tar.bz2
CD mhash-0.9.9.9
./configure
Make && make install
# finally install MCrypt
Cd..
Tar xzxvf mcrypt-2.6.8.tar.gz
CD mcrypt-2.6.8
# Add Mhash to the LD library path
Export Ld_library_path=/usr/local/lib
Ldconfig
./configure
Make && make install
Cd..
# download PHP and the corresponding version of PHP-FPM
Wget-c Http://www.php.net/get/php-5.2.17.tar.gz/from/this/mirror
# in the Http://php-fpm.org/downloads directory to select and install the PHP version consistent with the PHP-FPM, otherwise it will cause compatibility problems
Wget-c http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
# if it is a 5.2.x version, also need to download the PHP hash conflict patch, 5.3+ do not need to download the
Wget-c ps://github.com/laruence/laruence.github.com/raw/master/php-5.2-max-input-vars/ Php-5.2.17-max-input-vars.patch ">https://github.com/laruence/laruence.github.com/raw/master/ Php-5.2-max-input-vars/php-5.2.17-max-input-vars.patch
Tar xzvf php-5.2.17.tar.gz
# write PHP-FPM to the PHP source in the form of patches
GZIP-CD php-5.2.17-fpm-0.5.14.diff.gz | Patch-d PHP-5.2.17-P1
# Write hash conflict patch, PHP 5.3+ does not need
Patch-d Php-5.2.17-p1 < Php-5.2.17-max-input-vars.patch
CD php-5.2.17
# here will install PHP to the/usr/local/php directory, citing the MySQL installation directory for/usr/local/mysql, here needs to be modified according to the actual situation
/configure--prefix= $PHP _home--with-config-file-path= $PHP _home/etc--with-mysql= $MYSQL _home--with-mysqli= $MYSQL _home/bin/mysql_config--with-iconv-dir=/usr/local--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib-- WITH-LIBXML-DIR=/USR--enable-xml--disable-rpath--enable-discard-path--enable-safe-mode--enable-bcmath-- Enable-shmop--enable-sysvsem--enable-inline-optimization--with-curl--with-curlwrappers--enable-mbregex-- enable-fastcgi--enable-fpm--enable-force-cgi-redirect--enable-mbstring--with-mcrypt--WITH-GD-- Enable-gd-native-ttf--with-openssl--with-mhash--enable-pcntl--enable-sockets--with-ldap-- With-xmlrpc--enable-zip--enable-soap
Make zend_extra_libs= '-liconv '
Make install
CP Php.ini-dist/usr/local/php/etc/php.ini
Cd..
# Compile the extension module to install PHP
CD ~/downloads
# Install <a href= "Http://pecl.php.net/package/PDO_MYSQL" target= "_blank" >pdo_mysql</a>
Wget-c http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
Tar zxvf pdo_mysql-1.0.2.tgz
CD pdo_mysql-1.0.2
$PHP _home/bin/phpize
./configure--with-php-config= $PHP _home/bin/php-config--with-pdo-mysql= $MYSQL _home
Make && make install
Cd..
# Install Eaccelerator
Wget-c https://github.com/downloads/eaccelerator/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
Tar jxvf eaccelerator-0.9.6.1.tar.bz2
CD eaccelerator-0.9.6.1
$PHP _home/bin/phpize
./configure--enable-shared--with-php-config= $PHP _home/bin/php-config
Make && make install
Cd..
# Modify the php.ini file to enable the installation of Third-party modules
Sed-i-E "s:^extension_dir.*:extension_dir=" $PHP _home/lib/php/extensions/no-debug-non-zts-20060613/": G" $PHP _home /etc/php.ini
# Increase Extension
Cat >> $PHP _home/etc/php.ini <<eof
Extension=eaccelerator.so
Extension=pdo_mysql.so
[Eaccelerator]
Eaccelerator.shm_size= "32"
Eaccelerator.cache_dir= "/tmp/eaccelerator"
eaccelerator.enable= "1"
Eaccelerator.optimizer= "1"
Eaccelerator.check_mtime= "1"
eaccelerator.debug= "0"
Eaccelerator.filter= ""
Eaccelerator.shm_ttl= "0"
eaccelerator.shm_prune_period= "0"
eaccelerator.shm_only= "0"
Eof

# Create temporary directory for Eaccelerator
Mkdir/tmp/eaccelerator
chmod 777/tmp/eaccelerator

#-----------Install Nginx-----------
Echo-e "e[1;36m installation nginx ... e[0m"
# Download and install the latest Pcre library
CD ~/downloads
Wget-c ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz
Tar xzvf pcre-8.31.tar.gz
CD pcre-8.31
./configure
Make && make install
Cd..
# Install Tcmalloc upgrade Nginx performance
# if it's a 64-bit system, first you need to install the Libunwind library, 32-bit system does not need to install.
Wget-c http://download.savannah.gnu.org/releases/libunwind/libunwind-1.0.1.tar.gz
Tar xzvf libunwind-1.0.1.tar.gz
CD libunwind-1.0.1
Cflags=-fpic./configure
Make Cflags=-fpic
Make Cflags=-fpic Install
Cd..
# Install Google-perftools
Wget-c https://gperftools.googlecode.com/files/gperftools-2.0.tar.gz
Tar xzvf gperftools-2.0.tar.gz
CD gperftools-2.0
./configure
Make && make install
echo "/usr/local/lib" >/etc/ld.so.conf.d/usr_local_lib.conf
Ldconfig
Cd..
# Install Nginx
Wget-c http://nginx.org/download/nginx-1.2.3.tar.gz
Tar xzvf nginx-1.2.3.tar.gz
CD nginx-1.2.3
./configure--prefix= $NGINX _home--user=www--group=www--with-http_stub_status_module- With-google_perftools_module
Make && make install
# 64-bit to increase library links
Ln-s/lib64/libpcre.so.0.0.1/lib64/libpcre.so.1
Ln-s/usr/local/lib/libprofiler.so/lib64/libprofiler.so.0
Ln-s/usr/local/lib/libunwind.so/lib64/libunwind.so.8
# Enable Tcmalloc
Mkdir/tmp/tcmalloc
chmod 777/tmp/tcmalloc
# Modify the nginx.conf configuration file, add the following information to the PID line below
Sed-i-E ' s:^ #pid. *:&ngoogle_perftools_profiles/tmp/tcmalloc;:g ' $NGINX _home/conf/nginx.conf
# increase log Automatic cutting script
echo ' #!/bin/bash ' > ${nginx_home}/sbin/cutlogs.sh
echo "Mkdir-p ${nginx_home}/logs/$ (date +%y)/$ (date +%m)
MV ${nginx_home}/logs/access.log ${nginx_home}/logs/$ (date +%y)/$ (date +%m)/access.$ (date +%y%m%d). log
MV ${nginx_home}/logs/error.log ${nginx_home}/logs/$ (date +%y)/$ (date +%m)/error.$ (date +%y%m%d). log

KILL-USR1 ' Cat ${nginx_home}/logs/nginx.pid ' ">> ${nginx_home}/sbin/cutlogs.sh
# Increase execution permissions and add to Tasks
chmod +x ${nginx_home}/sbin/cutlogs.sh
Crontab-l > Tmpcrontab
echo "* * * */bin/bash ${nginx_home}/sbin/cutlogs.sh" >> tmpcrontab
Crontab Tmpcrontab
Rm-f Tmpcrontab

# finally close the account permission file
Chattr +i/etc/passwd
Chattr +i/etc/shadow
Chattr +i/etc/group
Chattr +i/etc/gshadow
# Open the Firewall
/etc/init.d/iptables start

#-----------set to boot-----------
Echo-e "e[1;36m MySQL, php-fpm and nginx set to boot ... e[0m"
Cat >>/etc/rc.local <<eof
/etc/init.d/mysql start
Ulimit-shn 65535
$PHP _home/sbin/php-fpm Start
$NGINX _home/sbin/nginx
Eof


Cat << EOF
+--------------------------------------------------------------+
MySQL, PHP, and Nginx have been installed
Please use $PHP _home/bin/php-version to see if PHP runs successfully and includes extensions
Please use $NGINX _home/sbin/nginx-t to see if NGINX configuration information is successful
Finally, we need to optimize the MySQL, php-fpm and nginx configuration files!
+--------------------------------------------------------------+
Eof
Related Article

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.