centos一键部署Lamp,shell脚本和搭建教程
Posted jio本小子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos一键部署Lamp,shell脚本和搭建教程相关的知识,希望对你有一定的参考价值。
这个教程可以在无网络环境搭建部署,几条命令搞定。
linux系统上自动搭建lamp环境
1.下载这些东西,或者直接下载我的压缩包
ps:里面的内容如图,是一些安装包和一个脚本(脚本内容在最后)
用xshell里的xftp把压缩包上传到服务器
2.解压这个压缩包,并且进入目录
解压
unzip lamp-auto-config-master.zip
进入目录执行脚本
cd lamp-auto-config
chmod -R 777 lamp_auto_config.sh
./lamp_auto_config.sh #执行shell脚本
mysql安装后需要手动设置环境变量
然后就会开始安装了
lamp环境会自动安装配置完成,
自动运行php文件,输出success则安装配置完成
test_apache_success.php文件验证apache是否正确加载php模块
test_mysql_con_success.php文件验证php访问mysql是否成功
3.安装后配置环境mysql变量
find / -name mysql#查看位置
一般在:/usr/local/mysql 目录下,如果需要添加到环境变量中,可以在 ~/.bashrc 文件中添加以下行:
export PATH=$PATH:/usr/local/mysql/bin
然后运行以下命令更新环境变量:
source ~/.bashrc
4.重新设置mysql密码,网上有很多方法
脚本内容:
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
tar -zxvf httpd-2.4.41.tar.gz
tar -zxvf apr-1.7.0.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
tar -zxvf php-7.2.26.tar.gz
mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql
mv httpd-2.4.41 httpd
mv apr-1.7.0 httpd/srclib/apr
mv apr-util-1.6.1 httpd/srclib/apr-util
mv httpd /usr/local
mv php-7.2.26 /usr/local/php-tar
cd /usr/local
groupadd mysql
useradd mysql -g mysql
chown -R mysql:mysql mysql/
chgrp -R mysql mysql/
yum -y install libaio
cd mysql/bin
./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
sed -i 's/datadir=\\/var\\/lib\\/mysql/datadir=\\/usr\\/local\\/mysql\\/data/g' /etc/my.cnf
sed -i 's/socket=\\/var\\/lib\\/mysql\\/mysql.sock/socket=\\/usr\\/local\\/mysql\\/mysql.sock/g' /etc/my.cnf
sed -i 's/log-error=\\/var\\/log\\/mariadb\\/mariadb.log/log-error=\\/usr\\/local\\/mysql\\/data\\/mysql.log/g' /etc/my.cnf
sed -i 's/pid-file=\\/var\\/run\\/mariadb\\/mariadb.pid/pid-file=\\/usr\\/local\\/mysql\\/data\\/mysql.pid/g' /etc/my.cnf
sed -i '1i [client]' /etc/my.cnf
sed -i '2i socket=\\/usr\\/local\\/mysql\\/mysql.sock' /etc/my.cnf
../support-files/mysql.server start
ln -s /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
chkconfig --add mysql
chmod +x /etc/rc.d/init.d/mysql
service mysql restart
sed -i '/\\[mysqld\\]/a\\skip-grant-tables' /etc/my.cnf
service mysql restart
./mysql -uroot << EOF
flush privileges;
alter user 'root'@'localhost' identified by '123456';
exit
EOF
sed -i 's/skip-grant-tables/#&/g' /etc/my.cnf
service mysql restart
./mysql -uroot -p123456 << EOF
update mysql.user set host='%' where user='root';
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;
exit
EOF
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
cd /usr/local/httpd
yum -y install gcc make prce-devel openssl-devel expat-devel
./configure \\
--prefix=/usr/local/httpd \\
--enable-so \\
--enable-ssl \\
--enable-cgi \\
--enable-rewrite \\
--with-zlib \\
--with-pcre \\
--with-included-apr \\
--enable-modules=most \\
--enable-mpms-shared=all \\
--with-mpm=prefork
make && make install
echo $?
cd bin/
./apachectl start
sed -i '1i servername localhost:80' ../conf/httpd.conf
./apachectl restart
ln -s /usr/local/httpd/bin/apachectl /etc/rc.d/init.d/httpd
sed -i '1a # chkconfig: 35 85 21' /etc/init.d/httpd
sed -i '2a # description: apache 2.4.41' /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on
systemctl restart httpd
cd /usr/local/php-tar
yum -y install gcc autoconf gcc-c++
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
yum install -y systemd-devel
yum install -y openjpeg-devel
sed -i 's/\\/replace\\/with\\/path\\/to\\/perl\\/interpreter/\\/usr\\/bin\\/perl/g' /usr/local/httpd/bin/apxs
./configure \\
--prefix=/usr/local/php \\
--with-config-file-path=/usr/local/php/etc \\
--with-apxs2=/usr/local/httpd/bin/apxs \\
--with-pdo-mysql=/usr/local/mysql \\
--with-zlib \\
--with-freetype-dir \\
--enable-mbstring \\
--with-libxml-dir=/usr \\
--enable-xmlreader \\
--enable-xmlwriter \\
--enable-soap \\
--enable-calendar \\
--with-curl \\
--with-zlib \\
--with-gd \\
--with-pdo-sqlite \\
--with-pdo-mysql \\
--with-mysqli \\
--with-mysql-sock \\
--enable-mysqlnd \\
--disable-rpath \\
--enable-inline-optimization \\
--with-bz2 \\
--with-zlib \\
--enable-sockets \\
--enable-sysvsem \\
--enable-sysvshm \\
--enable-pcntl \\
--enable-mbregex \\
--enable-exif \\
--enable-bcmath \\
--with-mhash \\
--enable-zip \\
--with-pcre-regex \\
--with-jpeg-dir=/usr \\
--with-png-dir=/usr \\
--with-openssl \\
--enable-ftp \\
--with-kerberos \\
--with-gettext \\
--with-xmlrpc \\
--with-xsl \\
--enable-fpm \\
--with-fpm-user=php-fpm \\
--with-fpm-group=php-fpm \\
--with-fpm-systemd \\
--disable-fileinfo
make && make install
cp php.ini-development ../php/etc/php.ini
echo 'PATH=$PATH:/usr/local/php/bin' >>/etc/profile
echo 'export PATH' >>/etc/profile
sed -i '/AddType application\\/x-gzip .gz .tgz/a\\AddType application\\/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf
sed -i '/AddType application\\/x-httpd-php .php/a\\AddType application\\/x-httpd-source .phps' /usr/local/httpd/conf/httpd.conf
sed -i '/php7_module/a\\PhpIniDir \\/usr\\/local\\/php\\/etc' /usr/local/httpd/conf/httpd.conf
sed -i 's/DirectoryIndex index.html/& index.php/g' /usr/local/httpd/conf/httpd.conf
service httpd restart
cp /root/test_apache_success.php /usr/local/httpd/htdocs/
cp /root/test_mysql_con_success.php /usr/local/httpd/htdocs/
service mysql restart
service httpd restart
service mysql restart
curl 127.0.0.1/test_apache_success.php
curl 127.0.0.1/test_mysql_con_success.php
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
以上是关于centos一键部署Lamp,shell脚本和搭建教程的主要内容,如果未能解决你的问题,请参考以下文章