一、思路:
1、使用脚本自动化安装。
2、分别安装mysql和nginx/php,可以根据需要安装在同一台机器或不同机器上。
二、实践:
1、安装mysql,并配置wordpress账号。为了方便测试,使用默认的配置。
#cat lamp-mysql.sh
#!/bin/bash
yum install -y mariadb-server
systemctl enable --now mariadb
#mysql_secure_installation
cat > create_sql_user.sql <<-EOF
create database wordpress;
grant all on wordpress.* to username@'%' identified by 'password';
flush privileges;
EOF
mysql < create_sql_user.sql
2、安装配置nginx\php。下载wordpress,解压、拷贝到nginx指定的网页部署目录(/data/nginx)。这里使用清华镜像源加速下载php。
#cat lnmp-web.sh
#!/bin/bash
# nginx+php
nginx_data="/data/nginx"
wget https://cn.wordpress.org/wordpress-5.9.3-zh_CN.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm --no-check-certificate
yum install -y remi-release-7.rpm
sed -i '/^mirrorlist=/c\mirrorlist=https:\/\/mirrors.tuna.tsinghua.edu.cn\/remi\/enterprise\/7\/safe\/mirror' /etc/yum.repos.d/remi-safe.repo
yum install -y nginx php74-php php74-php-fpm php74-php-mbstring php74-php-mysqlnd \
php74-php-xml.x86_64 php74-php-opcache.x86_64 unzip tree
mkdir ${nginx_data}/{html,blog,forum} -p
echo ${nginx_data}/html/index.html > ${nginx_data}/html/index.html
tar vxf wordpress-5.9.3-zh_CN.tar.gz
#rm -f wordpress-5.9.3-zh_CN.tar.gz
mv wordpress/* ${nginx_data}/blog
chown -R nginx.nginx ${nginx_data}
sed -i '/^http {/a\ server_tokens off;' /etc/nginx/nginx.conf
cat > /etc/nginx/conf.d/blog.conf <<-EOF
server{
listen 80;
server_name blog.17.com;
location / {
root /data/nginx/blog;
index index.php index.html index.htm;
}
error_page 500 502 503 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$|pm_status|ping {
root /data/nginx/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
sed -i -e '/^user =/c user = nginx' -e '/^group =/c group = nginx' \
-e '/^listen = /c listen = 127.0.0.1:9000' \
-e '/^\;pm.status_path = /c pm.status_path = \/pm_status' \
-e '/^\;ping.path =/c ping.path = \/ping' /etc/opt/remi/php74/php-fpm.d/www.conf
sed -i -e '/^upload_max_filesize = /c upload_max_filesize = 20M' \
-e '/^post_max_size = /c post_max_size = 10M' \
-e '/^expose_php =/c expose_php = Off' /etc/opt/remi/php74/php.ini
systemctl enable --now nginx php74-php-fpm
3、用浏览器访问http://