centos7搭建LNMP(wordpress)

一、思路:

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://<apache服务器ip>/blog ,网址不直接用wordpress,隐藏了产品信息。
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CentOS 7.6 LNMP搭建WordPress 1. 安装LNMP环境 LNMP环境包括LinuxNginxMySQL和PHP。在CentOS 7.6上安装LNMP环境,可以使用yum命令: sudo yum install nginx mysql-server php php-mysql 2. 配置Nginx Nginx是一个高性能的Web服务器,可以用来代替Apache。在CentOS 7.6上配置Nginx,需要编辑Nginx配置文件: sudo vi /etc/nginx/nginx.conf 在http块中添加以下内容: server { listen 80; server_name yourdomain.com; root /var/www/html; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 保存并退出文件。然后重新启动Nginx: sudo systemctl restart nginx 3. 配置MySQL MySQL是一个流行的关系型数据库管理系统。在CentOS 7.6上配置MySQL,可以使用以下命令: sudo systemctl start mysqld sudo systemctl enable mysqld 然后运行以下命令以设置MySQL root用户的密码: sudo mysql_secure_installation 按照提示输入密码并回答其他问题。 4. 安装WordPress WordPress是一个流行的开源博客平台。在CentOS 7.6上安装WordPress,可以使用以下命令: cd /var/www/html sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzvf latest.tar.gz sudo mv wordpress/* . sudo rm -rf wordpress latest.tar.gz 然后设置WordPress目录的权限: sudo chown -R nginx:nginx /var/www/html sudo chmod -R 755 /var/www/html 5. 配置WordPress 在浏览器中访问您的域名,您将看到WordPress的安装向导。按照向导的提示完成安装。 6. 完成 现在您已经成功地在CentOS 7.6上搭建LNMP环境,并安装了WordPress。您可以开始使用WordPress来创建博客和网站了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值