关闭防护墙
运行命令,检查防火墙当前的状态
sudo ufw status
- Status:inactive,表示防火墙关闭状态。
- Status:active,表示防火墙开启状态。
关闭防火墙命令
sudo ufw disable
开启防火墙命令
sudo ufw enable
安装Nginx
更新Ubuntu的软件包
sudo apt update
安装nginx
sudo apt -y install nginx
查看nginx版本
nginx -v
安装配置Mysql
安装MySQL
sudo apt -y install mysql-server
进入MySQL
sudo mysql
设置root用户密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';
在mynewpassword的地方就是你的密码。
创建一个数据库
CREATE DATABASE wordpress;
安装PHP
安装PHP
sudo apt -y install php-fpm
php -v 查看php版本
修改nginx配置文件来支持php
sudo vim /etc/nginx/sites-enabled/default
按i进入编辑模式,找到index开头的,在这行加入index.php,这样就在目录索引中加index.php了。
找到location ~ \.php${}, 将其中的注释去掉
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; #注意:请确认PHP版本与您安装的PHP-FPM版本相匹配,此处为php7.4-fpm.sock
}
注意:php版本根据前面查看的进行修改
按esc退出编辑模式,输入:wq回车,退出并保存文件。
重启nginx服务
sudo systemctl restart nginx.service
接下来,来检查一下php是否配置成功,Ubuntu系统下来到/var/www/html目录下,创建一个info.php文件
sudo vim phpinfo.php
里面写入这段检测代码
<? php echo phpinfo(); ?>
注意:该文件一定要写在/var/www/html目录下
启动php
sudo systemctl start php8.1-fpm
最后,在浏览器中打开你的网站http://<你的网址>/info.php
来查看有没有php配置页面。存在就是配置成功了。
注意:成功后一定要删除这个info.php。
安装word press
wget https://cn.wordpress.org/wordpress-6.5.2-zh_CN.zip
tar zxvf wordpress-6.5.2-zh_CN.zip
注意:还是在/var/www/html目录下,并且先删除原来的index.php
修改wordpress配置文件
cd /usr/share/nginx/html/wordpress
进入这个文件夹
cp wp-config-sample.php wp-config.php
将wp-config.php给copy出来
vim wp-config.php
进行编辑
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress'); 这个是咱们创建的数据库
/** MySQL database username */
define('DB_USER', 'user'); 是个是用户,懒省事直接用root
/** MySQL database password */
define('DB_PASSWORD', '123456'); 这个填写密码
/** MySQL hostname */
define('DB_HOST', 'localhost');
下边的key填上去就行了
链接:https://api.wordpress.org/secret-key/1.1/salt/
* 您可以随时更改这些内容以使所有现有 cookies 失效。
* 这将强制所有用户必须重新登录。
*
* @since 2.6.0
*/
define('AUTH_KEY', '');
define('SECURE_AUTH_KEY', '');
define('LOGGED_IN_KEY', '');
define('NONCE_KEY', '');
define('AUTH_SALT', '');
define('SECURE_AUTH_SALT', '');
define('NONCE_SALT', '');
/**#@-*/
保存退出后,访问http://<你的网址>/wordpress就可以查看wordpress是否搭建好了。
写这个就是为了以后网站挂掉了,快速的搭建起来,拜拜。

Comments | NOTHING