LAMP (apache/httpd+mysql+php) environment/Architecture One-click installation script

Source: Internet
Author: User
Tags curl gettext i18n lua openssl iptables egrep

the script was tested on CentOS only, test OK, and other distributions self-test


#!/bin/bash


#Purpose: Install lamp with one click (apache + mysql + php)

#Writer: www.linuser.com

#Date: 2015-10-08


#定义软件下载目录:

Softdir= '/USR/LOCAL/SRC '


#定义编译函数:

function make () {

If [' echo $? '-eq 0];then

Make

Else

Exit

Fi

}


#定义安装函数:

function Make_ins () {

If [' echo $? '-eq 0];then

Make install

Else

Exit

Fi

}


#第一部分: Configuration of the system's underlying environment:


#判断当前用户是否为root:

If [' WhoAmI ' = ' root '];then

echo "Root"

Else

echo "Please use root"

Exit

Fi


#判断当前网络是否畅通:

Net= ' Ping-c 4 www.baidu.com |grep received |awk ' {print $6} ' |sed-e ' s/%//'

If [$NET-ge 2];then

echo "Please check your network"

Exit

Fi


#配置PS Environment:

If [-Z ' egrep-i ps1/etc/profile |awk ' {print '} '];then

Echo ' ps1= ' \[\e[33;1m\][\[email protected]\[\e[31;1m\]\h \ t \# \w]\\$\[\e[m\] "' >>/etc/profile

Source/etc/profile

Fi


#查看系统编码是否为en_US. UTF-8

Lang= ' grep-i lang/etc/sysconfig/i18n |awk-f ' "" ' {print $} '

if [$lang! = ' en_US. UTF-8 '];then

Sed-i "s/$lang/en_us. utf-8/"i18n

Fi


#做本机的hosts parsing:

Eth= ' egrep-i device/etc/sysconfig/network-scripts/ifcfg-eth0 |awk-f ' = ' {print $} '

If [-Z ' egrep-i $ (echo $HOSTNAME)/etc/hosts |awk ' {print $} '];then

echo $ (IP ad |grep "Global $ETH" |awk-f "/" ' {print $} ' |awk ' {print $} ' && echo $HOSTNAME) >>/etc/host S

Fi

#关闭selinux:

Sed-i ' s/selinux=enforcing/selinux=disabled/'/etc/selinux/config


#关闭反向解析:

Sed-i ' s/^ #UseDNS yes/usedns no/'/etc/selinux/config


#重启启动sshd Services:

Service sshd Restart


#系统调优, increase the number of system files and the number of processes to 65535

Cat <<eof >>/etc/security/limits.conf

* Soft Nproc 65535

* Soft Nproc 65535

* Soft Nofile 65535

* Hard Nofile 65535

Eof

#或者使用sed inserted into the specified row

#sed-i "49i* soft nproc 65535\n* soft Nproc 65535\n* Soft Nofile 65535\n* hard nofile 65535 "/etc/security/limits.conf


Sed-i ' s/^root/#root/'/etc/security/limits.d/90-nproc.conf

Sed-i ' s/1024/65535/'/etc/security/limits.d/90-nproc.conf

Sed-i "6i* hard Nporc 65535"/etc/security/limits.d/90-nproc.conf


#安装系统扩展源: Http://dl.fedoraproject.org/pub/epel

If [' awk ' {print $} '/etc/redhat-release |awk-f '. ' ' {print $} '-eq 6];then

RPM-IVH http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

elif [' awk ' {print $4} '/etc/redhat-release |awk-f '. ' ' {print $} '-eq 7];then

RPM-IVH http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

Fi


#安装系统运维包:

Yum install-y lrzsz gcc gcc-c++ perl perl-devel bzip2 bzip2-devel make mans vim tree unzip wget lua-devel lua-static PATC H libxml2 libxml2-devel libxslt libxslt-devel gd gd-devel NTP screen sysstat rsync lsof gettext gettext-devel autoconf A Utomake libtool git OpenSSL openssl-devel curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel per L-data-dumper


#升级系统:

Yum Update-y


#第二部分: Installing Lamp


Installation configuration of #================================mysql #================================

CD $SoftDir && wget-q http://www.linuser.com/share/soft/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz


#解压:

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


#移动解压目录病重命名Mysql:

MV Mysql-5.6.26-linux-glibc2.5-x86_64/usr/local/mysql


#添加mysql System Users:

If [-Z ' grep mysql/etc/passwd ']; then

Useradd-s/sbin/nologin MySQL

Fi


#创建mysql Initialize the Data directory:

if [!-D "/data/mysql"]; then

Mkdir-p/data/mysql

Fi


#将mysql Initialize directory owner and group modified to MySQL:

Chown-r mysql.mysql/data/mysql/


#初始化

CD $MysqlS &&./scripts/mysql_install_db--datadir=/data/mysql--user=mysql


#备份系统默认的my. cnf file:

Mv/etc/my.cnf{,.bak}


#复制mysql main configuration file to the ETC directory seriously ill named MY.CNF

\CP support-files/my-default.cnf/etc/my.cnf


#复制mysql startup script to the/ETC/INIT.D directory:

\CP Support-files/mysql.server/etc/init.d/mysqld


#赋予启动755 Permissions:

chmod 755/etc/init.d/mysqld


#修改my. cnf files are configured as follows:

Cat << EOF >/ETC/MY.CNF

[Mysqld]

Pid-file=/data/mysql/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 = 256M

Max_allowed_packet = 1M

Table_open_cache = 256

Sort_buffer_size = 1M

Read_buffer_size = 1M

Read_rnd_buffer_size = 4M

Myisam_sort_buffer_size = 64M

Thread_cache_size = 8

Query_cache_size = 16M

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 = 16M


#[mysqld_safe]


[MySQL]

No-auto-rehash


[Myisamchk]

Key_buffer_size = 128M

Sort_buffer_size = 128M

Read_buffer = 2M

Write_buffer = 2M


[Mysqlhotcopy]

Interactive-timeout

Eof


#启动mysql:

Service mysqld Start


If [' echo $? '-eq 0]; then

echo "Mysql started"

Else

Exit

Fi


#将Mysqld set to random start:

Chkconfig--add mysqld && chkconfig mysqld on


#================================apr, Apr-util, Libmcrypt and Pcre ================================


CD $SoftDir


Wget-q http://www.linuser.com/share/soft/apr-1.5.2.tar.gz


#解压:

Tar zxf apr-1.5.2.tar.gz


#进入解压目录:

CD apr-1.5.2 &&/configure--prefix=/usr/local/apr


#编译及安装

Make && Make_ins


CD $SoftDir


Wget-q http://www.linuser.com/share/soft/apr-util-1.5.4.tar.gz


Tar zxf apr-util-1.5.4.tar.gz


CD./apr-util-1.5.4 &&/configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr


#编译及安装

Make && Make_ins


CD $SoftDir


Wget-q http://www.linuser.com/share/soft/libmcrypt-2.5.7.tar.gz


Tar zxf libmcrypt-2.5.7.tar.gz


CD libmcrypt-2.5.7 &&/configure--prefix=/usr/local/libmcrypt


#编译及安装

Make && Make_ins


CD $SoftDir


Wget-q http://www.linuser.com/share/soft/pcre-8.37.tar.gz


Tar zxf pcre-8.37.tar.gz


CD pcre-8.37 &&/configure--prefix=/usr/local/pcre


#编译及安装

Make && Make_ins


CD $SoftDir


Wget-q http://www.linuser.com/share/soft/zlib-1.2.8.tar.gz


Tar zxf zlib-1.2.8.tar.gz


CD zlib-1.2.8 &&/configure--prefix=/usr/local/zlib


#编译及安装:

Make && Make_ins


Installation configuration of #================================apache ================================

CD $SoftDir && wget-q http://www.linuser.com/share/soft/httpd-2.4.16.tar.gz


#解压apache:

Tar zxf httpd-2.4.16.tar.gz


#进入解压目录:

CD httpd-2.4.16


#配置编译参数:

./configure--prefix=/usr/local/apache2-enable-so--enable-mods-shared=all--enable-deflate=shared-- enable-expires=shared--enable-rewrite=shared--with-pcre=/usr/local/pcre/--WITH-APR=/USR/LOCAL/APR-- With-apr-util=/usr/local/apr-util--with-z=/usr/local/zlib


#编译简装:

Make && Make_ins


#================================php Installation Configuration ================================

CD $SoftDir && wget-q http://www.linuser.com/share/soft/php-5.5.30.tar.gz


#解压:

TAR-ZXF php-5.5.30.tar.gz


CD php-5.5.30 &&/configure--prefix=/usr/local/php--with-apxs2=/usr/local/apache2/bin/apxs--  With-config-file-path=/usr/local/php/etc--with-mysql=/usr/local/mysql--with-libxml-dir--with-gd--with-jpeg-dir --with-png-dir--with-freetype-dir--with-iconv-dir--with-zlib-dir--with-bz2--with-openssl--with-mcrypt=/usr/ Local/libmcrypt--enable-soap--enable-gd-native-ttf--enable-mbstring--enable-sockets--enable-exif--disable-ipv6 --with-pear--with-curl--with-openssl--with-mysqli--enable-mysqlnd--with-gettext--enable-bcmath--enable-sockets


#编译及安装

Make && Make_ins


Sed-i ' S/directoryindex index.html/directoryindex index.html index.php/'/usr/local/apache2/conf/httpd.conf

Sed-i ' s/^ #ServerName www.example.com:80/ServerName localhost:80/'/usr/local/apache2/conf/httpd.conf

Sed-i "392i addtype application/x-httpd-php. php"/usr/local/apache2/conf/httpd.conf


#开启防火墙的80端口

Iptables-i input-p TCP--dport 80-j ACCEPT && service iptables Save


#测试apache configuration is incorrect

/usr/local/apache2/bin/apachectl-t

If [' echo $? '-ne 0];then

Exit

Fi

#================================xcache Installation Configuration ================================

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


#解压:

Tar zxf xcache-3.2.0.tar.gz


#进入解压目录, Clear Phpize

CD xcache-3.2.0 &&/usr/local/php/bin/phpize--clean


#执行phpize, Production xcache configuration file:

/usr/local/php/bin/phpize


#配置编译参数:

./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config


#编译及安装

Make && Make_ins


#复制PHP源码包中的php. Ini-production to/usr/local/php/etc directory and rename to PHP.ini

\cp/usr/local/src/php-5.5.30/php.ini-production/usr/local/php/etc/php.ini


#将xcache library file into the php.ini file

echo "extemsiobn_dir= '/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/'" >>/usr/local/php/etc/ Ini

echo "extension=xcache.so" >>/usr/local/php/etc/php.ini


#启动Apache:

/usr/local/apache2/bin/apachectl-k restart


#重命名apache The default home index.html:

Mv/usr/local/apache2/htdocs/index.html{,.bak}


#新建php Information page, test Apache parsing PHP:

echo "<?php echo phpinfo (); ?> ">/usr/local/apache2/htdocs/index.php


#将apache add to the system environment variable:

echo "path= $PAHT:/usr/local/apache2/bin" >>/etc/profile

Source/etc/profile


Script execution:

Time sh/usr/local/sbin/lamp.sh >/var/log/install.log 2>&1

This article is from the Linux system Learning extension blog, so be sure to keep this source http://zhangxiaoxiong.blog.51cto.com/11657691/1786187

LAMP (apache/httpd+mysql+php) environment/Architecture One-click installation script

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.