如果MySQL root用户密码忘记,可以通过修改配置文件来登录MySQL,修改密码。
修改配置文件,在 /etc/my.cnf 中,
保存并退出,重启MySQL,
systemctl restart mysqld
此时进入MySQL,就已经不需要密码了,直接输入MySQL就会进入。
mysql
更改密码
update mysql.user set authentication_string=password('123456') where user'root' and host'localhost';
刷新权限
flush privileges;
修改完之后要及时删除配置项
vim /etc/my.cnf
更改完文件之后,要重启MySQL。
此时用新密码登录MySQL root用户。
mysql -uroot -p123456
yum 安装nginx
yum install nginx
启动nginx
nginx
用命令查看80端口
ss -nplt | grep 80
发现nginx已经启动。
部署php
进入rpm软件包仓库网站。
https://rpms.remirepo.net/ 是一个 RPM 软件包仓库,它提供大量的 PHP 和相关扩展包
Remi's RPM repository (remirepo.net)https://rpms.remirepo.net/
右键-复制链接。
在终端中用yum进行下载。
yum -y install php74-php-fpm
yum -y install php74-php-xsl php74-php php74-php-cli php74-php-devel php74-php-gd php74-php-pdo php74-php-mysql php74-php-fpm
启动php
systemctl restart php74-php-fpm
检查是否启动成功
ss -nplt | grep 9000
nginx 关联php
将nginx文件备份,文件在 /etc/nginx/nginx.conf。
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
对nginx配置文件进行编辑
vim /etc/nginx/nginx.conf
可以用 加个+42来指定文件开启时光标在第42行。
vim +42 /etc/nginx/nginx.conf
在第42行下进行编辑,添加以下代码
index index.php index.html index.htm;
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
}
可以用nginx -t 来检测是否有语法问题
nginx -t
配置文件语法没有问题后,重启nginx
nginx -s reload
编写一个探测文件来查看nginx和php是否连接成功
vim index.php
<?php
phpinfo();
?>
用浏览器访问ip地址,显示下面界面,就表示连接成功。
接下来就是让项目上线
将压缩包从本地上传到虚拟机中。解压
tar -zxvf wordpress-6.2.2-zh_CN.tar.gz
将解压后的目录下的文件和目录拷贝到 /usr/share/nginx/html/ 目录下
cp -r /root/wordpress/* /usr/share/nginx/html/
删除之前的测试文件index.php。
rm -rf index.php
进入mysql中创建数据库
create database wordpress;
打开浏览器访问ip地址。
这里输入刚刚创建的数据库名wordpress,用户名root 。
点击提交后,看到无法写入wp-config.php文件,需要我们手动创建并配置。
需要创建在 /usr/share/nginx/html 目录下,
vim 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/documentation/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', 'root' );
/** Database password */
define( 'DB_PASSWORD', '123' );
/** 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', '^ES>dqfaA%hn5{P[VB!I d3 gezm;J`agkJ~m<E58/*a<(q:D, O)7rIjQGkd|1@' );
define( 'SECURE_AUTH_KEY', 'kqD}9<+<?Mc3d+4N+v71Zq+OS=|m-@l(J|lSMKi_x5+Wi-!b|uvDs%qT!`MDJ[*=' );
define( 'LOGGED_IN_KEY', 'I.$A3BAHf<grZ.;q3]c+D{3%cS#&L!SDo%NIi_PXjvq3Bivt*Ue+h&TX-{Wj9%}?' );
define( 'NONCE_KEY', 'rJW2hf(L|8T(!.ek^GFLCDr0.#K3_mYnP3HO@:s6Q(%:tAUwYCE_[~M%f$)?[Ck%' );
define( 'AUTH_SALT', 'wH/OAd`MEb9[gzu3PT_tVv3m/I%p*@eo*CVe`^KyH5_:{`WdN2%Z-xns0.E_+W#g' );
define( 'SECURE_AUTH_SALT', 'q~ej>{5{%3(59J&hOP;Z{Gn-NLbsIaLvZRniA=jkhCNj/&|3ssR*(r%R,xq==1NW' );
define( 'LOGGED_IN_SALT', '<t*,_SprcP>6EG=wSXIFm]93SK$A8Vc-B0E>*d2lg[<CE#X}{m:nvtE4%5c#kip]' );
define( 'NONCE_SALT', 'QP9To>rx:oA,X5D%2cV^Ni,Zr7S_BwUdAvEj)@scV-To9Hv%?U$O=v*]1Z[+|Sr!' );
/**#@-*/
/**
* 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/documentation/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';