zoukankan      html  css  js  c++  java
  • 一键源码安装lamp环境

    [root@x112 software]# unzip -l LAMP_centos7.4.zip
    Archive: LAMP_centos7.4.zip
    Length Date Time Name
    --------- ---------- ----- ----
    1031613 04-10-2017 19:35 LAMP for centos7.4/apr-1.5.2.tar.gz
    874044 04-10-2017 19:36 LAMP for centos7.4/apr-util-1.5.4.tar.gz
    8628454 10-14-2017 14:58 LAMP for centos7.4/httpd-2.4.28.tar.gz
    48799895 10-14-2017 15:09 LAMP for centos7.4/mysql-boost-5.7.19.tar.gz
    2068775 10-14-2017 15:00 LAMP for centos7.4/pcre-8.41.tar.gz
    19300905 05-18-2018 20:26 LAMP for centos7.4/php-5.6.36.tar.gz
    0 05-18-2018 20:27 LAMP for centos7.4/
    --------- -------
    80703686 7 files
    [root@x112 software]#

    #!/bin/bash
    #describtion for install lamp
    
    #进入安装目录,解压并重命名文件夹
    cd /root/linshi/software
    unzip LAMP_centos7.4.zip
    mv LAMP for centos7.4/ lamp
    cd lamp
    
    #安装apache基础准备环境
    #yum安装c编译器
    yum -y install gcc gcc-c++ openssl-devel
    
    #开始编译安装依赖包
    #源码编译安装apr
    tar -xf apr-1.5.2.tar.gz
    cd apr-1.5.2/
    ./configure --prefix=/usr/local/apr
    make -j2 && make install
    
    #源码编译安装apr-util
    cd ..
    tar -xf apr-util-1.5.4.tar.gz
    cd apr-util-1.5.4/
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
    make -j2 && make install
    
    #源码编译安装pcre
    cd ..
    tar -xf pcre-8.41.tar.gz
    cd pcre-8.41
    ./configure --prefix=/usr/local/pcre
    make -j2 && make install
    
    #开始源码编译安装apache
    cd ..
    tar -xf httpd-2.4.28.tar.gz
    cd httpd-2.4.28/
    ./configure --prefix=/usr/local/apache  --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-rewrite --enable-ssl
    make -j2 && make install
    
    配置apache
    cd /usr/local/apache/
    cp bin/apachectl /etc/init.d/httpd
    sed -ri '2a#chkconfig: 2345 99 20 
    #describtion: service for httpd' /etc/init.d/httpd
    chkconfig --add httpd
    service httpd start
    
    #安装mysql数据库
    #安装mysql依赖包
    yum install -y cmake ncurses-devel
    
    #源码编译安装mysql数据库
    cd /root/linshi/software/lamp
    tar -xf mysql-boost-5.7.19.tar.gz
    cd mysql-5.7.19/
    cmake 
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 
    -DMYSQL_UNIX_ADDR=/usr/local/mysql57/mysql.sock 
    -DDEFAULT_CHARSET=utf8 
    -DDEFAULT_COLLATION=utf8_general_ci 
    -DWITH_MYISAM_STORAGE_ENGINE=1 
    -DWITH_INNODB_STORAGE_ENGINE=1 
    -DWITH_MEMORY_STORAGE_ENGINE=1 
    -DWITH_DATADIR=/mysql/data 
    -DMYSQL_USER=mysql 
    -DWITH_BOOST=/root/linshi/software/lamp/mysql-5.7.19/boost/boost_1_59_0
    
    make -j2 && make install
    #配置httpd服务
    sed -ri '/^#ServerName/cServerName '$(ifconfig eth0 |awk 'NR==2{print $2}')':80' /usr/local/apache/conf/httpd.conf
    
    #配置mysql数据库
    #生成启动脚本.并设置开机自启动
    cd /usr/local/mysql57
    cp support-files/mysql.server /etc/init.d/mysqld
    chkconfig --add mysqld
    
    #创建数据库账号及目录,并授权
    useradd mysql -s /sbin/nologin -M
    mkdir /mysql/data -p
    chown -R mysql.mysql /mysql/data/
    
    #更改环境变量
    echo "export PATH=$PATH:/usr/local/mysql57/bin/" >/etc/profile.d/mysql.sh
    . /etc/profile.d/mysql.sh
    
    #备份原有my.cnf文件,重新生成新的my.cnf文件
    mv /etc/my.cnf /etc/my.cnf_bak
    mv /etc/my.cnf.d/mysql-clients.cnf{,_bak}
    cat <<-eof > /etc/my.cnf
            [mysqld]
            basedir=/usr/local/mysql57
            datadir=/mysql/data
            port=3306
            socket=/usr/local/mysql57/mysql.sock
            log-error=/usr/local/mysql57/log/mysqld.log
            pid-file=/usr/local/mysql57/mysqld.pid
            [mysql]
            socket=/usr/local/mysql57/mysql.sock
    eof
    
    #根据my.cnf文件,创建相应文件
    mkdir /usr/local/mysql57/log
    touch /usr/local/mysql57/log/mysqld.log
    chown -R mysql.mysql /usr/local/mysql57/
    
    #初始化数据库,启动并更改密码
    mysql_install_db  --insecure --user=mysql --basedir=/usr/local/mysql57 --datadir=/mysql/data
    service mysqld start
    mysqladmin -uroot password "123456"
    
    #安装php
    #安装php依赖包
    yum -y install libxml2-devel curl-devel libpng libjpeg libpng-devel
    cd /root/linshi/software/lamp
    tar -xf php-5.6.36.tar.gz
    cd php-5.6.36
    ./configure --prefix=/usr/local/php 
    --with-apxs2=/usr/local/apache/bin/apxs 
    --enable-mbstring 
    --with-curl 
    --with-gd 
    --enable-fpm 
    --enable-mysqlnd 
    --with-pdo-mysql=mysqlnd 
    --with-config-file-path=/usr/local/php/etc 
    --with-mysqli=mysqlnd 
    --with-mysql-sock=/usr/local/mysql57/mysql.sock
    
    make -j2 && make install
    
    #生成配置文件
    cp php.ini-production /usr/local/php/etc/php.ini
    
    #添加apache支持
    sed -ri '/^<IfModule mime_module>/a\tAddtype application/x-httpd-php .php .phtml'  /usr/local/apache/conf/httpd.conf
    sed -ri '/^<IfModule dir_module>/{n;s/$/ index.php/}' /usr/local/apache/conf/httpd.conf
    cat <<-eof >/usr/local/apache/htdocs/index.php
    <?php
     phpinfo();
    ?>
    eof
    service httpd restart
                                                                                                                             
    

      

  • 相关阅读:
    第04组 Beta冲刺 (3/5)
    第04组 Beta冲刺 (2/5)
    第04组 Beta冲刺 (1/5)
    软工实践个人总结
    第09组 每周小结(3/3)
    第09组 每周小结(2/3)
    第09组 每周小结(1/3)
    第09组 Beta冲刺 总结
    第09组 Beta冲刺 (5/5)
    第09组 Beta冲刺 (4/5)
  • 原文地址:https://www.cnblogs.com/xiaofeng666/p/13629496.html
Copyright © 2011-2022 走看看