一、编译安装LNMP,并安装wordpress
1、编译安装nginx
# 安装相关依赖环境
yum install -y gcc pcre-devel openssl-devel zlib-devel
# 创建nginx用户并解压源码包
tar -zxvf nginx-1.16.1.tar.gz
useradd -r -s /sbin/nologin nginx
cd nginx-1.16.1
# 开始配置相关参数,设置相关模块
./configure --prefix=/apps/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_ssl_module \
> --with-http_v2_module \
> --with-http_realip_module \
> --with-http_stub_status_module \
> --with-http_gzip_static_module \
> --with-pcre \
> --with-stream \
> --with-stream_ssl_module \
> --with-stream_realip_module
# 开始编译安装
make && make install
2、编译安装Mariadb
# 解压源码包,创建mysql用户,创建mysql数据存储目录并设置用户权限
tar -zxvf mariadb-10.2.25.tar.gz
useradd -r -s /sbin/nologin -d /data/mysql mysql
mkdir /data/mysql
chown root:mysql /data/mysql
# 安装依赖环境
yum install -y bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel
# 进入源码包目录配置相关配置选项
cmake . \
> -DCMAKE_INSTALL_PREFIX=/apps/mysql \
> -DMYSQL_DATADIR=/data/mysql/ \
> -DSYSCONFDIR=/etc/ \
> -DMYSQL_USER=mysql \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
> -DWITH_DEBUG=0 \
> -DWITH_READLINE=1 \
> -DWITH_SSL=system \
> -DWITH_ZLIB=system \
> -DWITH_LIBWRAP=0 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci
#开始编译安装
make && make install
# 配置环境变量,生成数据库文件
echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
bash /etc/profile.d/mysql.sh
/apps/mysql/scripts/mysql_install_db --datadir=/data/mysql --user=mysql
# 准备配置文件和启动脚本
cp /apps/mysql/support-files/my-huge.cnf /etc/my.cnf
cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld
# 设置开机启动
chkconfig --add mysqld
3、编译安装php-fpm
# 配置epel源,这里不做相关配置,请自行百度配置阿里epel源
# 安装依赖环境
yum install -y libxml2-devel bzip2-devel libmcrypt-devel
# 解压源码包,进入目录
tar -jxvf php-7.3.12.tar.bz2
# 配置相关参数
./configure --prefix=/apps/php \
> --enable-mysqlnd \
> --with-mysqli=mysqlnd \
> --with-pdo-mysql=mysqlnd \
> --with-openssl \
> --with-freetype-dir \
> --with-jpeg-dir \
> --with-png-dir \
> --with-zlib \
> --with-libxml-dir=/usr \
> --with-config-file-path=/etc \
> --with-config-file-scan-dir=/etc/php.d \
> --enable-mbstring \
> --enable-xml \
> --enable-sockets \
> --enable-fpm \
> --enable-maintainer-zts \
> --disable-fileinfo
# 编译并安装
make && make install
# 准备配置文件,并修改www.conf配置文件中启动用户和组为nginx
cp php.ini-production /etc/php.ini
cd /apps/php/etc/
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf
vim www.conf
#找到以下两项,将nobody改为nginx
user = nginx
group = nginx
# 准备php启动脚本
cp /data/php-7.3.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
# 设置开启自启动
chkconfig --add php-fpm
#启动nginx、mysql、php
/apps/nginx/sbin/nginx
service mysqld start
service php-fpm start
4、安装wordpress
# 数据库创建库和用户
mysql -u root -p
Enter password:
MariaDB [(none)]> create database wordpress charset 'utf8';
MariaDB [(none)]> grant all on wordpress.* to 'wpuser'@'10.50.6.%' identified by 'centos';
# 解压wordpress到/apps/nginx/html/ 并给源码目录设置nginx访问权限
tar -xf wordpress-5.2.2.tar.gz -C /apps/nginx/html
setfacl -Rm u:nginx:rwx /apps/nginx/html/wordpress
# 修改nginx虚拟主机配置文件
vim /apps/nginx/conf/nginx.conf
# 在http{}段中添加以下内容
server {
listen 80;
server_name blog.wordpress.com;
location / {
root html/wordpress;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html/wordpress;
fastcgi_pass 127.0.0.1:8000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# 测试nginx配置文件是否有问题
/apps/nginx/sbin/nginx -t
# 重新加载nginx配置文件
/apps/nginx/sbin/nginx -s reload
配置wordpress网站,根据向导安装,这里不做展示
# 配置hosts文件使其可以解析域名
vim /etc/hosts
10.50.6.80 www.x.com admin.x.com
# 登录wordpress后台,
# Settings --》General Settings 中,
# 将 WordPress Address (URL) 改为后台地址 admin.x.com
# Site Address (URL) 改为前台地址 www.x.com
修改nginx配置文件,在http段中添加以下内容
server {
listen 80;
server_name www.x.com;
location / {
root html/wordpress;
index index.php index.html index.htm;
}
#添加重写规则,用前台域名访问后台时,跳转到后台域名访问
location ~ /(wp-admin|wp-login.php) {
rewrite / http://admin.x.com/wp-login.php;
}
location ~ \.php$ {
root html/wordpress;
fastcgi_pass 127.0.0.1:8000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name admin.x.com;
location / {
root html/wordpress;
index wp-login.php index.php;
}
location ~ \.php$ {
root html/wordpress;
fastcgi_pass 127.0.0.1:8000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}