步骤1:安装 依赖包
yum -y install gcc-c++ && yum install -y pcre pcre-devel && yum install -y zlib zlib-devel && yum install -y openssl openssl-devel
步骤2:编译安装nginx
1. 下载nginx
wget http://nginx.org/download/nginx-1.26.2.tar.gz
2. 解压nginx压缩包
tar zxvf nginx-1.26.2.tar.gz -C /usr/local/
3. 进入解压后的nginx目录
cd /usr/local/nginx-1.26.2/
4. 执行编译脚本
./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/sbin/nginx --error-log-path=/var/log/nginx/nginx_error.log --http-log-path=/var/log/nginx/nginx_access.log --pid-path=/usr/local/nginx/run/nginx.pid
5. 编译安装
make && make install
6. 验证安装
nginx -v
7. 创建systemd 服务文件
vi /etc/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
8. 让服务生效
systemctl daemon-reload
9. 启动nginx
systemctl start nginx
10. 访问测试
步骤3:编译安装Mysql5.7
先检查并删除其他数据库相关驱动文件,否则会有冲突。
yum erase mariadb mariadb-server mariadb-libs mariadb-devel -y
userdel -r mysql && rm -rf /var/lib/mysql &>/dev/null
1. 创建MySQL启动用户,此用户不具备终端交互环境
cd && useradd -r mysql -M -s /bin/nologin -M
2. 安装编译工具
yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make glibc automake autoconf cmake
3. 下载mysql源码包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.44.tar.gz
4. 创建mysql工作目录
mkdir -p /usr/local/mysql/{data,log}
5. 解压mysql源码包
tar xzvf mysql-boost-5.7.44.tar.gz -C /usr/local/
6. 进入解压后的目录
cd /usr/local/mysql-5.7.44/
7. 编译
cmake . -DWITH_BOOST=boost/boost_1_59_0/ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_DATADIR=/usr/local/mysql/data -DINSTALL_MANDIR=/usr/share/man -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DEXTRA_CHARSETS=all -DDEFAULT_COLLATION=utf8_general_ci -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
8. 编译安装,此过程耗时比较长
make && make install
9. 修改目录权限
chown -R mysql.mysql /usr/local/mysql
10. 进入MySQL目录,初始化MySQL获取随机密码
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2>&1 | grep 'temporary password' | awk '{print $NF}'
我这里的密码是:beS8dfqMIU-E
11. 设置环境变量 ,方便系统识别MySQL命令
echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
source /etc/profile
12. 修改配置文件
vi /etc/my.cnf
将内容全部删除,并写入一下内容
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
character-set-server = utf8
collation-server = utf8_general_ci
default-storage-engine = INNODB
max_connections = 100
sql_mode = STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
[mysqld_safe]
log-error = /var/log/mysqld.log
pid-file = /usr/local/mysql/data/mysqld.pid
13. 将MySQL添加到服务单元
vi /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=forking
User=mysql
Group=mysql
PIDFile=/usr/local/mysql/data/mysqld.pid
# ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize --pid-file=/usr/local/mysql/data/mysqld.pid
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/usr/local/mysql/bin/mysqladmin shutdown
LimitNOFILE=5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
14. 生效配置
systemctl daemon-reload
14. 启动MySQL
15. 登录MySQL
mysql -uroot -p
16. 创建用户和数据库并设置权限
#创建库
CREATE DATABASE wordpress;
#创建用户
GRANT ALL PRIVILEGES ON wordpress.* TO 'www'@'%' IDENTIFIED BY 'Aa123123!' WITH GRANT OPTION;
#刷新权限
FLUSH PRIVILEGES;
步骤4:编译安装php7.4
1. 安装依赖
yum -y install gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel gd sqlite sqlite-devel net-snmp net-snmp-devel oniguruma oniguruma-devel
2. 下载php7.4
wget https://www.php.net/distributions/php-7.4.33.tar.gz
3. 解压,并进入解压后的目录
tar -xf php-7.4.33.tar.gz && cd php-7.4.33
4. 编译
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mbstring --with-curl --with-openssl --with-zlib --enable-fpm --with-mysqli --enable-pdo --with-pdo-mysql
5. 安装
make && make install
6. 复制php配置文件
cp php.ini-development /usr/local/php/etc/php.ini
7. 配置服务管理单元
cp sapi/fpm/php-fpm.service /etc/systemd/system/
步骤5:配置nginx和php
1. 修改nginx配置,修改server块内容为下所示
server {
listen 80;
server_name _;
root /usr/local/nginx/html/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
2. 修改 /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
#粘贴以下内容
[global]
pid = /run/php-fpm.pid
error_log = /var/log/php/php-fpm.log
log_level = notice
daemonize = yes
include = /usr/local/php/etc/php-fpm.d/*.conf
3. 修改 /usr/local/php/etc/php-fpm.d/www.conf
vi /usr/local/php/etc/php-fpm.d/www.conf
#粘贴以下内容
[web]
listen = 127.0.0.1:9000
listen.owner = www
listen.group = www
listen.mode = 0660
user = www
group = www
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
4. 创建www用户
useradd -r www -M -s /bin/nologin -M
5. 修改php目录权限
chown www:www/usr/local/php -R
6. 创建目录,也可以使用其他目录,nginx配置文件对应目录要一致
mkdir -p /usr/local/nginx/html
步骤6:安装wordpress
1. 进入网站目录
cd /usr/local/nginx/html
2. 下载wordpress源码包
wget https://cn.wordpress.org/latest-zh_CN.zip
3. 解压,如果没有unzip需要使用yum安装!
unzip latest-zh_CN.zip
4. 浏览器访问主机ip地址
5. 填写上面安装MySQL创建的信息
6. 手动修改配置文件
vi /usr/local/nginx/html/wordpress/wp-config.php
下面要换成你自己安装提示的内容
<?php
/**
***************************************
***************************************
7. 再次点击
8 填写你的站点配置
安装完成
登录
重新访问一下ip地址看看