lamp环境一键安装搭建脚本

2022-09-16 21:35:14 浏览数 (2)

代码语言:javascript复制
#!/bin/bash
#解压压缩包
yum -y install gcc gcc-c   unzip
unzip lamp.zip
mv lamp /
cd /lamp

    for i in `ls *.tar.gz`
    do
      tar -xf $i
    done
	unzip $(ls *.zip)

YANZHENG () {
if [ $? -ne 0 ]
then 
	echo "$1 安装失败" >> /root/jieguo
	exit
else
	echo "$1 安装成功" >> /root/jieguo
fi
}
   
#安装libxml2
yum -y install  libxml2-devel python-devel 
cd /lamp/libxml2-2.9.1
./configure --prefix=/usr/local/libxml2/ && make -j 4 && make install 
YANZHENG libxml21

#安装libmcrypt
cd /lamp/libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt/ && make -j 4 && make install 
YANZHENG libmcrypt

#安装libltdl
cd /lamp/libmcrypt-2.5.8/libltdl
./configure --enable-ltdl-install && make -j 4 && make install 
YANZHENG libltdl

#安装mhash
cd /lamp/mhash-0.9.9.9 
./configure && make -j 4 && make install  
YANZHENG mhash

#安装mcrypt
cd /lamp/mcrypt-2.6.8
export LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/lib
#变量:LD_LIBRARY_PATH用于指定libmcrypt和mhash(公共位置了)的库的位置,只用这一次
./configure --with-libmcrypt-prefix=/usr/local/libmcrypt && make -j 4 && make install  
YANZHENG mcrypt

#安装zlib
cd /lamp/zlib-1.2.3
./configure  
sed -i '/DUSE_MMAP/ s/-DUSE_MMAP/-DUSE_MMAP -fPIC/ ' Makefile
make -j 4 && make install  
YANZHENG zlib

#安装libpng
cd /lamp/libpng-1.2.31
./configure --prefix=/usr/local/libpng && make -j 4 && make install  
YANZHENG libpng

#安装jpeg6
mkdir /usr/local/jpeg6
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/include
mkdir -p /usr/local/jpeg6/man/man1

yum -y install libtool  
cd /lamp/jpeg-6b
cp -a /usr/share/libtool/config/config.sub ./
cp -a /usr/share/libtool/config/config.guess ./
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static && make -j 4	&& make install  
YANZHENG jpeg6


#安装freetype
cd /lamp/freetype-2.3.5
./configure --prefix=/usr/local/freetype/ && make -j 4 && make install  
YANZHENG freetype

#安装apache
cp  -a  /lamp/apr-1.4.6  /lamp/httpd-2.4.7/srclib/apr
cp  -a  /lamp/apr-util-1.4.1  /lamp/httpd-2.4.7/srclib/apr-util
cd /lamp/pcre-8.34
./configure && make && make install  
yum -y install openssl-devel  
yum -y install expat-devel  

 cd /lamp/httpd-2.4.7
./configure --prefix=/usr/local/apache2 --sysconfdir=/usr/local/apache2/etc --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-ssl && make -j 4 && make install  
YANZHENG apache2

#安装ncurses 安装cmake和bison
yum -y install ncurses-devel cmake bison  
cd /lamp/ncurses-5.9
./configure --with-shared --without-debug --without-ada --enable-overwrite && make && make install  
YANZHENG ncurses

#安装mysql
useradd -r -s /sbin/nologin mysql
cd /lamp/mysql-5.5.48
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 && make -j 4  && make install  
YANZHENG mysql

cd /usr/local/mysql/
chown -R root ./
chown -R mysql data/

cp -a /lamp/mysql-5.5.48/support-files/my-medium.cnf /etc/my.cnf
cd /usr/local/mysql    #必须相对路径,因为脚本中调用是相对路径
./scripts/mysql_install_db --user=mysql

cp -a ./support-files/mysql.server /etc/init.d/mysqld
chkconfig mysqld on
service mysqld start
/usr/local/mysql/bin/mysqladmin -uroot password 123456

ln -s /usr/local/mysql/bin/* /usr/local/bin/
ln -s /usr/local/mysql/sbin/* /usr/local/sbin/

#安装PHP
cd /lamp/php-7.0.7
./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets --with-pdo-mysql=/usr/local/mysql --with-gd --without-pear && make -j 4 && make install  
YANZHENG php
mkdir /usr/local/php/etc
cp /lamp/php-7.0.7/php.ini-production /usr/local/php/etc/php.ini

#修改Apache配置文件,使其识别*.php文件,并能通过php模块调用php进行页面解析
 echo -e "AddType application/x-httpd-php .php .phtmlnAddType application/x-httpd-php-source .phps" >> /usr/local/apache2/etc/httpd.conf

/usr/local/apache2/bin/apachectl stop && /usr/local/apache2/bin/apachectl start

echo -e "<?php	n   phpinfo();	 n ?>" >> /usr/local/apache2/htdocs/test.php	
#后加:
#安装memcached服务 
yum -y install libevent-devel
cd /lamp/memcached-1.4.17
./configure --prefix=/usr/local/memcache && make && make install
YANZHENG memcached1

useradd -r -s /sbin/nologin memcache
#添加memcache用户,此用户不用登录,不设置密码
nohup /usr/local/memcache/bin/memcached -umemcache &
#启动memcache服务,并设置为后台运行
YANZHENG memcached2

#PHP安装openssl模块
cd /lamp/php-7.0.7/ext/openssl
mv config0.m4 config.m4
/usr/local/php/bin/phpize
./configure --with-openssl --with-php-config=/usr/local/php/bin/php-config && make && make install 
YANZHENG opensslmokuai

#为PHP安装memcache模块
cd /lamp/pecl-memcache-php7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config && make && make install
YANZHENG memcachemokuai

#修改php配置文件,使其识别并调用openssl和memcache两个模块
echo "extension_dir="/usr/local/php/lib/php/extensions/no-debug-zts-20151012/"" >> /usr/local/php/etc/php.ini
echo "extension="openssl.so";" >> /usr/local/php/etc/php.ini
echo "extension="memcache.so";" >> /usr/local/php/etc/php.ini
#添加以上两个库文件的调用
YANZHENG opensslmemcache


#安装phpMyAdmin
cp -a /lamp/phpMyAdmin-4.1.4-all-languages /usr/local/apache2/htdocs/phpmyadmin
cd /usr/local/apache2/htdocs/phpmyadmin
cp -a config.sample.inc.php config.inc.php
#设置auth_type第一优先级为http ,即默认使用HTTP身份认证模式(复制新增即可)
echo "$cfg['Servers'][$i]['auth_type'] = 'http';" >> config.inc.php
sed -i '/DirectoryIndex/c DirectoryIndex index.html index.php' /usr/local/apache2/etc/httpd.conf
sed -i '/#ServerName/ c ServerName www.zjt.com:80' /usr/local/apache2/etc/httpd.conf
/usr/local/mysql/bin/mysqld_safe --user=mysql &
/usr/local/apache2/bin/apachectl stop && /usr/local/apache2/bin/apachectl start
YANZHENG phpMyAdmin

#设置Apache、MySQL、Memcache开机自启
#借助系统自带脚本/etc/rc.local,此脚本开机后会自动加载,我们可以将源码安装的服务启动命令写入该脚本,间接实现开机自启动
#需要提前加入执行权限chmod  x /etc/rc.d/rc.local
echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.local
echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >> /etc/rc.local
echo "/usr/local/memcache/bin/memcached -umemcache &" >> /etc/rc.local
YANZHENG ApacheMySQLMemcache


chmod  x /etc/rc.local
#给rc.local加上可执行权限

0 人点赞