环境信息
[root@linux ~]# cat /etc/os-release
NAME="Rocky Linux"
VERSION="8.6 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.6 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8"
部署环境-LNMP
LNMP就是Linux
、Nginx
、MySQL/Mariadb
、PHP
的首字母缩写
下面的内容建立在系统源已配置的前提下进行
下载源码
如果是局域网环境请将源码包上传到服务器
wget https://cn.wordpress.org/latest-zh_CN.zip
安装服务
Nginx
Nginx (engine x)
是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务
执行下面的命令进行安装
yum install -y nginx
效果如下
验证
systemctl restart nginx.service # 重启Nginx服务
systemctl status nginx.service # 查看Nginx服务状态
效果如下
[root@linux ~]# systemctl restart nginx.service
[root@linux ~]# systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2022-08-03 22:30:39 CST; 5s ago
Process: 26524 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 26522 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 26520 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 26525 (nginx)
Tasks: 5 (limit: 49261)
Memory: 10.5M
CGroup: /system.slice/nginx.service
├─26525 nginx: master process /usr/sbin/nginx
├─26526 nginx: worker process
├─26527 nginx: worker process
├─26528 nginx: worker process
└─26529 nginx: worker process
8月 03 22:30:39 linux systemd[1]: Starting The nginx HTTP and reverse proxy server...
8月 03 22:30:39 linux nginx[26522]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
8月 03 22:30:39 linux nginx[26522]: nginx: configuration file /etc/nginx/nginx.conf test is successful
8月 03 22:30:39 linux systemd[1]: Started The nginx HTTP and reverse proxy server.
[root@linux ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 26525/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1057/sshd
tcp6 0 0 :::80 :::* LISTEN 26525/nginx: master
tcp6 0 0 :::22 :::* LISTEN 1057/sshd
MariaDB
yum install -y mariadb-server
效果如下
验证
[root@linux ~]# systemctl restart mariadb.service
[root@linux ~]# systemctl status mariadb.service
● mariadb.service - MariaDB 10.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2022-08-03 22:34:11 CST; 5s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 27680 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 27546 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
Process: 27521 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 27649 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 30 (limit: 49261)
Memory: 81.9M
CGroup: /system.slice/mariadb.service
└─27649 /usr/libexec/mysqld --basedir=/usr
8月 03 22:34:06 linux systemd[1]: Starting MariaDB 10.3 database server...
8月 03 22:34:06 linux mysql-prepare-db-dir[27546]: Initializing MariaDB database
8月 03 22:34:10 linux mysqld[27649]: 2022-08-03 22:34:10 0 [Note] /usr/libexec/mysqld (mysqld 10.3.32-MariaDB) starting as process 27649 ...
8月 03 22:34:11 linux systemd[1]: Started MariaDB 10.3 database server.
Php
yum install -y php-* php
效果如下
[root@linux html]# yum install -y php-* php
上次元数据过期检查:0:35:24 前,执行于 2022年08月03日 星期三 23时13分19秒。
软件包 php-bcmath-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-cli-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-common-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-dba-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-dbg-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-devel-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-embedded-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-enchant-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-fpm-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-gd-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-gmp-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-intl-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-json-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-ldap-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-mbstring-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-mysqlnd-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-odbc-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-opcache-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-pdo-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-pear-1:1.10.5-9.module+el8.4.0+413+c9202dda.noarch 已安装。
软件包 php-pecl-apcu-5.1.12-2.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-pecl-apcu-devel-5.1.12-2.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-pecl-zip-1.15.3-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-pgsql-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-process-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-recode-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-snmp-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-soap-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-xml-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-xmlrpc-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
软件包 php-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
验证
[root@linux ~]# systemctl restart php-fpm.service
[root@linux ~]# systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2022-08-03 22:38:30 CST; 6s ago
Main PID: 28302 (php-fpm)
Status: "Ready to handle connections"
Tasks: 6 (limit: 49261)
Memory: 9.5M
CGroup: /system.slice/php-fpm.service
├─28302 php-fpm: master process (/etc/php-fpm.conf)
├─28303 php-fpm: pool www
├─28304 php-fpm: pool www
├─28305 php-fpm: pool www
├─28306 php-fpm: pool www
└─28307 php-fpm: pool www
8月 03 22:38:30 linux systemd[1]: Starting The PHP FastCGI Process Manager...
8月 03 22:38:30 linux systemd[1]: Started The PHP FastCGI Process Manager.
[root@linux ~]# php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
至此,服务的安装工作就完成了,下面开始进行服务的配置
配置服务
Nginx
首页索引
使用下面的命令进入编辑
vim /etc/nginx/nginx.conf
首先新增首页索引文件的名称(48行
),如下:
index index.php index.html index.htm;
增加匹配规则
继续在刚配置的位置下面加上配置参数
location ~ \.php$ {
fastcgi_read_timeout 300;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
如下
然后执行下面的命令设置其他用户写权限
chmod o+w /run/php-fpm/www.sock
增加PHP验证文件
vim /usr/share/nginx/html/test.php
输入下面的内容
<?php
phpinfo();
?>
验证解析
首先重启服务
[root@linux ~]# systemctl restart nginx.service php-fpm.service
[root@linux ~]# systemctl status nginx.service php-fpm.service
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/nginx.service.d
└─php-fpm.conf
Active: active (running) since Wed 2022-08-03 23:07:01 CST; 5s ago
Process: 28452 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 28449 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 28442 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 28453 (nginx)
Tasks: 5 (limit: 49261)
Memory: 7.8M
CGroup: /system.slice/nginx.service
├─28453 nginx: master process /usr/sbin/nginx
├─28454 nginx: worker process
├─28455 nginx: worker process
├─28456 nginx: worker process
└─28457 nginx: worker process
8月 03 23:07:01 linux systemd[1]: Starting The nginx HTTP and reverse proxy server...
8月 03 23:07:01 linux nginx[28449]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
8月 03 23:07:01 linux nginx[28449]: nginx: configuration file /etc/nginx/nginx.conf test is successful
8月 03 23:07:01 linux systemd[1]: Started The nginx HTTP and reverse proxy server.
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2022-08-03 23:07:01 CST; 5s ago
Main PID: 28437 (php-fpm)
Status: "Ready to handle connections"
Tasks: 6 (limit: 49261)
Memory: 9.4M
CGroup: /system.slice/php-fpm.service
├─28437 php-fpm: master process (/etc/php-fpm.conf)
├─28441 php-fpm: pool www
├─28443 php-fpm: pool www
├─28444 php-fpm: pool www
├─28445 php-fpm: pool www
└─28446 php-fpm: pool www
8月 03 23:07:01 linux systemd[1]: Starting The PHP FastCGI Process Manager...
8月 03 23:07:01 linux systemd[1]: Started The PHP FastCGI Process Manager.
然后关闭防火墙或者开放端口
systemctl stop firewalld.service
然后访问测试页面
http://192.168.65.128/test.php
192.168.65.128
是安装Nginx的服务器IP
效果如下
此时说明Nginx已经实现PHP的解析了
数据库MariaDB
输入命令进行初始化
mysql_secure_installation
开始设置密码
首次执行直接回车即可
全过程如下
[root@linux ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): # 这里回车开始进入密码设置
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y # 这是询问是否设置root密码
New password: # 输入新密码(输入的时候看不见的,输入完回车即可)
Re-enter new password: # 再次输入新密码验证(输入的时候看不见的,输入完回车即可)
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y # 是否移除匿名用户
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y # 是否关闭root远程登录
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y # 是否移除测试数据库
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y # 是否重置权限
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
#
及后面的中文都是后期注释
到这里,数据库的基本配置就完成了,然后登录数据库创建数据库和用户
安装phpMyAdmin
完成php
和mariadb
的配置之后,就可以进行phpMyAdmin
的部署了
下载源码
点击访问官网下载源码
https://www.phpmyadmin.net/downloads/
wget https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-all-languages.zip
配置源码
unzip phpMyAdmin-5.2.0-all-languages.zip
mv phpMyAdmin-5.2.0-all-languages /usr/share/nginx/html/phpMyAdmin
chmod -R 0755 /usr/share/nginx/html/phpMyAdmin/*
访问验证
http://192.168.65.128/phpMyAdmin/
登录界面
创建数据库-命令行操作
首先登录数据库
mysql -uroot -p
登录成功之后,依次执行下面的命令
创建数据库(wordpress)
create database wordpress default charset utf8 collate utf8_unicode_ci;
创建用户(liuyi)
请根据实际需求设置用户名
create user liuyi;
设置权限及密码
grant all privileges on wordpress.* to 'liuyi'@'localhost' identified by 'liuyi123';
wordpress
表示刚创建的数据库名称liuyi
表示刚创建的用户名localhost
表示允许登录的主机名称liuyi123
表示用户名(liuyi)的登录密码
刷新权限
flush privileges;
效果如下
[root@linux ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.32-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 default charset utf8 collate utf8_unicode_ci;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> create user liuyi;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on wordpress.* to 'liuyi'@'localhost' identified by 'liuyi123';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> Bye
[root@linux ~]# mysql -uliuyi -pliuyi123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.3.32-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| wordpress |
+--------------------+
2 rows in set (0.001 sec)
MariaDB [(none)]>
创建数据库-图形化操作
登录数据库
首先登录phpMyAdmin
创建数据库
然后输入数据库名称并选择编码,点击创建
创建用户并设置权限
设置用户权限
执行操作
最后点击执行
部署网站
源码配置
将源码解压并移动到网站根目录
mv latest-zh_CN.zip /usr/share/nginx/html/
cd /usr/share/nginx/html/
unzip latest-zh_CN.zip
cp -rf wordpress/* .
rm -rf wordpress/
rm -f index.html
效果如下
[root@linux html]# pwd
/usr/share/nginx/html
[root@linux html]# ls
404.html index.php license.txt poweredby.png test.php wp-admin wp-comments-post.php wp-content wp-includes wp-load.php wp-mail.php wp-signup.php xmlrpc.php
50x.html latest-zh_CN.zip nginx-logo.png readme.html wp-activate.php wp-blog-header.php wp-config-sample.php wp-cron.php wp-links-opml.php wp-login.php wp-settings.php wp-trackback.php
[root@linux html]#
访问网站
直接访问IP地址即可,安装程序会自动跳转到配置页面的
配置信息预览页面
配置数据库信息
点击提交
然后根据提示进行操作
[root@linux html]# cat wp-config.php
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the installation.
* You don't have to use the web site, you can copy this file to "wp-config.php"
* and fill in the values.
*
* This file contains the following configurations:
*
* * Database settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://wordpress.org/support/article/editing-wp-config-php/
*
* @package WordPress
*/
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );
/** Database username */
define( 'DB_USER', 'liuyi' );
/** Database password */
define( 'DB_PASSWORD', 'liuyi123' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
/**#@+
* Authentication unique keys and salts.
*
* Change these to different unique phrases! You can generate these using
* the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
*
* You can change these at any point in time to invalidate all existing cookies.
* This will force all users to have to log in again.
*
* @since 2.6.0
*/
define( 'AUTH_KEY', 'I1%Mn!DQ^P#olgGN>6;b3u&a)yLDvQh{>[ xZFbPGc(|UKB=R^KqEFj>[!/#~..;' );
define( 'SECURE_AUTH_KEY', 'Ijd6-M326Fb!{xR-_Y^#pRv{AAYXxXIv5ixREwP98I#=KRmbJW=|rx^&8hQ8<efv' );
define( 'LOGGED_IN_KEY', '60VsHphzlA_[Y48!T#fv#G9Q<adzLap]2poy3~b<m>x,.%<P;*aj{N=c/#/xFzDA' );
define( 'NONCE_KEY', 'N0>m4RpQjnzb7Mcit~P-!AM(Ob7?aVt3labkFp/TK2W7ZxY<-jBDt^HU$jLkgR8X' );
define( 'AUTH_SALT', 'bU3}PF0^JuZ-_+_D&[O|w2M~W;ZJxk? bh =0kPde h~S8p?jTHy7$Z9KKRfO%zs' );
define( 'SECURE_AUTH_SALT', '}?2fE(2UP{gK,+<|Qy? e|8*=,D6#FfJm}Ga7K{~f8C-dP]o1Me%wH>A*Von SSm' );
define( 'LOGGED_IN_SALT', 'y8]Qst.o,!s:!VgQ@7/Ni-VDFv]_:;kD(_rBG8b[Y{ntmsCC]iw*B.-^hD[~z*,Q' );
define( 'NONCE_SALT', '(F5UqI &|td|c#*Z%jA~WEtlrZ(0bQA,Iy}{K?K]7uqI<Jw130PU,q`q-JJ%`AG?' );
/**#@-*/
/**
* WordPress database table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'wp_';
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the documentation.
*
* @link https://wordpress.org/support/article/debugging-in-wordpress/
*/
define( 'WP_DEBUG', false );
/* Add any custom values between this line and the "stop editing" line. */
/* That's all, stop editing! Happy publishing. */
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';