1 环境准备
所需环境 | 说明 |
---|---|
CentOS7.9 | ip地址:10.0.0.7,可以上网 |
PHP72系列软件 | 下面会介绍 |
MySQL数据库 | 暴露端口3306,用户wordpress,库wordpress |
nginx | 版本任意 |
wordpres v6.5.2代码 | 下载地址:https://cn.wordpress.org/wordpress-6.5.2-zh_CN.zip |
1.1 设置系统yum源和优化系统
1.确保linux主机可以上网
[root@web~]# ping wzywzy.fun -c 3
PING wzywzy.fun (47.120.55.69) 56(84) bytes of data.
64 bytes from 47.120.55.69 (47.120.55.69): icmp_seq=1 ttl=128 time=31.2 ms
64 bytes from 47.120.55.69 (47.120.55.69): icmp_seq=2 ttl=128 time=30.1 ms
64 bytes from 47.120.55.69 (47.120.55.69): icmp_seq=3 ttl=128 time=30.9 ms--- wzywzy.fun ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2012ms
rtt min/avg/max/mdev = 30.124/30.795/31.299/0.514 ms
2.设置软件源,并安装一些常用的软件
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum repolist
yum -y install tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop \
iftop htop unzip nc sl cowsay nmap telnet bc psmisc httpd-tools bind-utils nethogs expect tldr sshpass
3.关闭防火墙和selinux,清除iptables
systemctl disable firewalld --now; systemctl stop firewalldsetenforce 0
sed -i '/^SELINUX=/ s#SELINUX=.*#SELINUX=disabled#g' /etc/selinux/configiptables -X
iptables -F
iptables -Z
2 设置软件
1.2 配置PHP
1.2.1 下载PHP
1.设置PHP yum源,之前设置的阿里是没有详细的PHP源的,手动设置1个。
cat > /etc/yum.repos.d/php.repo <<EOF
[webtatic-php]
name = php Repository
baseurl = https://us-east.repo.webtatic.com/yum/el7/x86_64
enabled = 1
gpgcheck = 0
EOF
2.安装PHP
yum clean all && yum repolist
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd \
php72w-mcrypt php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache \
php72w-pecl-memcached php72w-pecl-redis php72w-pecl-mongodb php72w-bcmath php72w-ldap.x86_64
1.2.2 设置PHP
1.统一设置PHP的运行用户为www用户。如果没有www用户的话,得创建这个用户
创建方式:
useradd www -M -s /sbin/nologin
修改运行用户为www:
sed -i -e '/^user/ s#^user.*#user = www#g' -e 's#^group.*#group = www#g' /etc/php-fpm.d/www.conf
1.2 配置nginx
1.2.1 下载nginx
1.下载nginx
yum -y install nginx
2.修改nginx运行用户为www:
sed -i '/^user/ s#^user.*#user www;#g' /etc/nginx/nginx.conf
1.2.2 设置nginx
定义1个wordpress的虚拟主机用80端口,前提你的本机80端口没有被占用
rm -rf /etc/nginx/conf.d/* > /dev/null 2>&1
cat > /etc/nginx/conf.d/wordpress.conf <<EOF
server {listen 80;server_name localhost;location / {root /code/wordpress;index index.php index.html;}location ~* \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /code/wordpress/$fastcgi_script_name;include fastcgi_params;fastcgi_buffering on;fastcgi_buffers 64 64k;}
}
EOF
1.3 设置数据库
安装数据库参考我的博客,二进制部署mysql8.0.26
1.创建库和用户,并授权用户管理对应库的权限。
create database wordpress charset utf8mb4;
create user wordpress@'%' identified with mysql_native_password by '123456';
grant all on wordpress.* to wordpress@'%';
执行过程参考
mysql> create database wordpress charset utf8mb4;
Query OK, 1 row affected (0.00 sec)mysql> create user wordpress@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)mysql> grant all on wordpress.* to wordpress@'%';
Query OK, 0 rows affected (0.01 sec)
3 启动所有服务测试
3.1 下载wordpress代码
wget https://cn.wordpress.org/wordpress-6.5.2-zh_CN.zip
unzip wordpress-6.5.2-zh_CN.zip -d /code/
chown www.www -R /code/wordpress
3.2 启动服务
systemctl restart php-fpm.service
systemctl restart nginx
3.3 安装过程
浏览器输入:10.0.0.7,(换成你的ip地址),如果你无法访问你的服务器,请留言wenzy18@qq.com
填写连接数据库的信息
提示:下面的信息需要手动填写。虽然它有个灰色的提示,实际上还是要手动填入的。
可能浏览器重新输入10.0.0.7。最后就进入了