一鍵原始碼安裝lamp環境
阿新 • • 發佈:2020-09-07
[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
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
#!/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 \n#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/c\ServerName '$(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