佛山正规网站建设报价,京东优惠劵网站怎么做,湘潭网站建设价格,照片制作网站作者 乐维社区#xff08;forum.lwops.cn#xff09; 许远 在这个信息爆炸的时代#xff0c;拥有一个能够迅速传达信息、展示个性、并能够与世界互动的在线平台#xff0c;已成为企业和个人的基本需求。WordPress#xff0c;以其无与伦比的易用性和强大的扩展性#xff0…作者 乐维社区forum.lwops.cn 许远 在这个信息爆炸的时代拥有一个能够迅速传达信息、展示个性、并能够与世界互动的在线平台已成为企业和个人的基本需求。WordPress以其无与伦比的易用性和强大的扩展性成为了构建此类平台的首选工具。而LNMP这个由Linux、Nginx、MySQL和PHP组成的强大组合为WordPress提供了一个稳定而高效的运行环境。本文将带您走进搭建WordPress站点的奇妙旅程从0开始利用LNMP的强大功能打造一个既充满个性又能满足业务需求的在线家园。
LNMP项目实战环境说明
LLinuxCentOS7https://mirrors.aliyun.com/centos/7/isos/x86_64/
NNginx1.18.0 https://nginx.org/en/download.html
MMySQL8.0.19 https://dev.mysql.com/downloads/mysql/
PPHP7.4.10 http://php.net/downloads.php
Wordpress5.4.2https://cn.wordpress.org/download/#部署规划 192.168.26.201Nginx php-fpm 运行web服务 192.168.26.202运行MySQL数据库 1.1 部署数据库 在192.168.26.202主机部署MySQL服务
1.1.1 部署Mariadb数据库
1 [rootmariadb ~]# yum -y install mariadb-server
2 [rootmariadb ~]# systemctl enable --now mariadb.service1.1.2 创建wordpress数据库和用户并授权
[rootmariadb ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type help; or \h for help. Type \c to clear the current input statement.
MariaDB [(none)] create database wordpress;
Query OK, 1 row affected (0.00 sec) MariaDB [(none)] create user wordpress192.168.26.% identified by 123456;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)] grant all on wordpress.* to wordpress192.168.26.%;
Query OK, 0 rows affected (0.00 sec) 18
MariaDB [(none)]1.1.3 验证MySQL账户权限 在WordPress服务器使用授权的MySQL账户远程登录测试权限
[rootweb ~]# mysql -uwordpress -p123456 -h192.168.26.202
Type help; or \h for help. Type \c to clear the current input statement.
--------------------
| Database |
--------------------
| information_schema |
| test |
| wordpress |
--------------------
3 rows in set (0.00 sec)1.2 部署PHP 在192.168.26.201主机部署php-fpm服务
1.2.1 编译安装 php https://www.php.net/downloads.php
[rootcentos7 ~]# yum -y install gcc openssl-devel libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel
[rootcentos7 ~]#cd /usr/local/src
[rootcentos7 src]#wget https://www.php.net/distributions/php-7.4.11.tar.xz
[rootweb src]# tar xf php-7.4.11.tar.xz
[rootweb src]# ls
nginx-1.22.0 nginx-1.22.0.tar.gz php-7.4.11 php-7.4.11.tar.xz
[rootweb src]# cd php-7.4.11/
[rootcentos7 php-7.4.11]# ./configure --prefix/usr/local/php74 --enable- mysqlnd --with-mysqlimysqlnd --with-pdo-mysqlmysqlnd --with-openssl --with-zlib --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
......config.status: creating main/php_config.h
config.status: executing default commands--------------------------------------------------------------------| License: |
| This software is subject to the PHP License, available in this || distribution in the file LICENSE. By continuing this installation || process, you are bound by the terms of this license agreement. || If you do not agree with the terms of this license, you must abort || the installation process at this point. |--------------------------------------------------------------------Thank you for using PHP.[rootcentos7 php-7.4.11]#make -j 8 make install1.2.2 准备PHP配置文件
#生成配置文件
[rootcentos7 php-7.4.11]#cp /usr/local/src/php-7.4.11/php.ini-production /etc/php.ini
[rootweb php-7.4.11]# cd /usr/local/php74/etc/
[rootweb etc]# cp php-fpm.conf.default php-fpm.conf[rootweb etc]# pwd
/usr/local/php74/etc
[rootweb etc]# cd php-fpm.d/
[rootweb php-fpm.d]# cp www.conf.default www.conf[rootweb php-fpm.d]# vim www.conf
[rootcentos7 php-fpm.d]#grep ^[^;] www.conf[www]
user nginxgroup nginx
listen 127.0.0.1:9000
pm dynamic
pm.max_children 5pm.start_servers 2
pm.min_spare_servers 1
pm.max_spare_servers 3
pm.status_path /pm_status
ping.path /ping1.2.3 启动并验证 php-fpm服务
[rootweb php-fpm.d]# /usr/local/php74/sbin/php-fpm -t
[01-Aug-2022 19:44:33] NOTICE: configuration file /usr/local/php74/etc/php- fpm.conf test is successful
[rootweb php-fpm.d]# /usr/local/php74/sbin/php-fpm
[rootweb php-fpm.d]# ss -ntl
State Recv-Q Send-Q Local Address:PortPeer Address:PortLISTEN 0 100 127.0.0.1:25*:*LISTEN 0 128 127.0.0.1:9000*:*LISTEN 0 128 *:22*:*LISTEN 0 100 [::1]:25[::]:*
LISTEN 0 128 [::]:22[::]:*[rootweb php-fpm.d]#[rootweb php-fpm.d]# pstree -p |grep php|-php-fpm(14119)--php-fpm(14120)| -php-fpm(14121)[rootweb php-fpm.d]# ps -ef |grep phproot 14119 1 0 19:45 ? 00:00:00 php-fpm: master process(/usr/local/php74/etc/php-fpm.conf)nobody 14120 14119 0 19:45 ? 00:00:00 php-fpm: pool wwwnobody 14121 14119 0 19:45 ? 00:00:00 php-fpm: pool wwwroot 14134 35079 0 19:46 pts/2 00:00:00 grep --colorauto php1.3 部署 Nginx 在192.168.26.201主机部署nginx服务
1.3.1 编译安装 nginx
1 [rootdb1 ~]# vim install_nginx.sh#!/bin/bash安装必要的编译依赖
yum install -y gcc-c pcre-devel zlib-devel make下载Nginx源码包
wget http://nginx.org/download/nginx-1.22.0.tar.gztar zxvf nginx-1.22.0.tar.gzcd nginx-1.22.0配置编译选项这里只列出了一部分常用选项
./configure --prefix/usr/local/nginx --with-http_ssl_module编译和安装
make make install启动Nginx
/usr/local/nginx/sbin/nginx2 [rootdb1 ~]# /bin/bash install_nginx.sh3 [rootdb1 ~]# ss -ntl | grep 80LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:8080 *:*
LISTEN 0 80 [::]:3306 [::]:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:8080 [::]:* 1.3.2 配置 Nginx 支持 fastcgi
[rootweb ~]#vim /usr/local/nginx/conf/nginx.conf[rootweb ~]#grep -Ev #|^$ vim /usr/local/nginx/conf/nginx.confworker_processes 1;events {worker_connections 1024;}http {
include mime.types;
default_type application/octet-stream;sendfile on;keepalive_timeout 65;
server {listen 80;server_name localhost;location / {root html;index index.php index.html index.htm;}error_page 500 502 503 504 /50x.html;location /50x.html { root html;}location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}} [rootweb ~]# /usr/local/nginx/sbin/nginx1.4 部署 WordPress 在192.168.26.201主机部署 wordpress
1.4.1 准备 WordPress 文件
[rootweb ~]# wget https://cn.wordpress.org/wordpress-6.0.1-zh_CN.tar.gz
[rootweb ~]# tar xf wordpress-6.0.1-zh_CN.tar.gz
[rootweb ~]#cp -r wordpress/* /usr/local/nginx/html
[rootweb html]# cp wp-config-sample.php wp-config.php
[rootweb html]# vim wp-config.php
define( DB_NAME, wordpress );
/** Database username */
define( DB_USER, wordpress );
/** Database password */
define( DB_PASSWORD, 123456 );
/** Database hostname */
define( DB_HOST, 192.168.26.202 );
[rootweb html]# chown -R nginx.nginx .1.4.2 初始化web页面 打开浏览器访问下面链接
192.168.26.201 1.4.3 登录后台管理界面并发表文章 1.4.4 验证发表的文章 #可以看到上传的图片
[[rootweb html]# tree wp-content/uploads/
wp-content/uploads/ └── 2022
└── 08
└── 1.png
2 directories, 1 file1.4.5 配置允许上传大文件
#注意:默认只支持1M以下文件上传 ,要利用php程序上传大图片 ,还需要修改下面三项配置 ,最大上传由 三项值的最小值决定
#直接上传大于1M文件 ,会出现下面413错误
[rootcentos7 ~]#tail -f /apps/nginx/logs/access.log
10.0.0.1 - - [27/Nov/2020:12:21:16 0800] POST /wp-admin/async-upload.php
HTTP/1.1 413 585 http://10.0.0.7/wp-admin/upload.php Mozilla/5.0
(Windows NT
10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67
Safari/537.36 Edg/87.0.664.47
#nginx上传文件大小限制
[rootcentos7 ~]#vim /apps/nginx/conf/nginx.conf
server {
client_max_body_size 10m; #默认值为1M
.....
#php上传文件大小限制
[rootcentos7 ~]#vim /etc/php.ini
post_max_size 30M #默认值为8M
upload_max_filesize 20M #默认值为2M
[rootcentos7 ~]#systemctl restart nginx php-fpm以上就是本期的全部内容更多运维技巧欢迎关注乐维社区更多运维问题也欢迎到乐维社区留言提问。