本文最后更新于194 天前,其中的信息可能已经过时,如有错误请发送邮件到big_fw@foxmail.com
apt update
apt install -y mariadb-server mariadb-client
systemctl enable --now mariadb
#1.检查端口
ss -lntup |grep mariadb
#2.检查进程
ps -ef |grep mariadb
#安装后进行即可,进行1次就行
mysql_secure_installation
root@oldboy-lnmp:~# 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
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none): #回车
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n #no
... skipping.
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] Y #Y
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 #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 #Y
... 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 #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 #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!
vim /etc/mysql/mariadb.conf.d/50-server.cnf
bind-address = 127.0.0.1 或者修改0.0.0.0
#-u用户名
#-p密码
root@oldboy-lnmp:~# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 39
Server version: 10.6.18-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04
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)]>
#1.创建库并检查
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| wordpress |
+--------------------+
5 rows in set (0.000 sec)
#2.添加用户并检查
MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'localhost' identified by 'Lidao996';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
| wordpress | localhost |
+-------------+-----------+
4 rows in set (0.001 sec)
ctrl +d退出
#3.通过wordpress用户登录并测试
root@oldboy-lnmp:~#mysql -uwordpress -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 10.6.18-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04
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 | #登录后这里有 wordpress才对.
+--------------------+
2 rows in set (0.000 sec)
MariaDB [(none)]> ^DBye
一些删除操作:
1删除数据库: drop database wordpress;
2删除用户: drop user ‘wordpress’@’localhost’ ; 刷新权限 flush privileges;
grant all on wordpress.* to ‘wordpress’@’localhost’ identified by ‘Lidao996’;说明
添加用户
设置权限
grant all on wordpress.* to ‘wordpress’@’localhost’ identified by’Lidao996′;
所有权限 对于 wordpress库所有表 to ‘用户’@白名单 密码是 xxxxxx
2.2. PHP环境部署
#1安装下面软件包
apt update
apt install -y php8.1-bcmath php8.1-bz2 php8.1-cgi php8.1-cli php8.1-common php8.1-curl php8.1-fpm php8.1-gd php8.1-intl \
php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-soap \
php8.1-xml php8.1-zip php8.1-apcu php8.1-redis php8.1-snmp
#2.检查数量
dpkg -l |grep php8.1
20
#1.查看软件包的配置文件
dpkg -L php8.1-fpm
先安装nginx 后续统一用户nginx 配置文件user要统一
/etc/php/8.1/fpm/php-fpm.conf #php-fpm主配置文件
/etc/php/8.1/fpm/pool.d
/etc/php/8.1/fpm/pool.d/www.conf #子配置文件.
#2.修改子配置文件
vim /etc/php/8.1/fpm/pool.d/www.conf
修改 listen = 127.0.0.1:9000 #主要修改这里
egrep '^(user|group|listen)' /etc/php/8.1/fpm/pool.d/www.conf
user = www-data
group = www-data
listen = 127.0.0.1:9000 #主要修改这里
listen.owner = www-data
listen.group = www-data
#user和group 看后续nginx安装后的用户.
#3,检查配置文件
root@oldboy-lnmp:~# php-fpm8.1 -t
[14-Sep-2024 10:21:34] NOTICE: PHP message: PHP Warning: Cannot load module "http" because required module "raphf" is not loaded in Unknown on line 0
[14-Sep-2024 10:21:34] NOTICE: configuration file /etc/php/8.1/fpm/php-fpm.conf test is successful
root@oldboy-lnmp:~# echo $?
0
#4.启动(重启)
root@oldboy-lnmp:~# dpkg -L php8.1-fpm |grep service
/lib/systemd/system/php8.1-fpm.service
root@oldboy-lnmp:~# systemctl enable --now php8.1-fpm
Synchronizing state of php8.1-fpm.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable php8.1-fpm
root@oldboy-lnmp:~# echo $?
0
systemctl restart php8.1-fpm
#5.检查 端口 进程
ss -lntup |grep php-fpm8.1
2.3. nginx
检查是否安装apache
dpkg -l |grep apache
关闭 apache2服务
apt autoremove apache2 apache2-bin
apt update
apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
上面命令执行后应该有如下输出:类似的
pub rsa2048 2011-08-19 [SC] [expires: 2027-05-24]
573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid nginx signing key <signing-key@nginx.com>
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
| sudo tee /etc/apt/preferences.d/99nginx
apt update
apt install -y nginx
root@oldboy-lnmp:~# dpkg -l|grep nginx
ii nginx 1.26.2-1~jammy amd64 high performance web server
root@oldboy-lnmp:~#
dpkg -L nginx
/etc/nginx/nginx.conf #主配置文件
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf #子配置文件
#1. 修改nginx用户为www-data
vim /etc/nginx/nginx.conf
user www-data;
grep ^user /etc/nginx/nginx.conf
user www-data;
#2.修改子配置文件
cp /etc/nginx/conf.d/default.conf{,.bak}
vim /etc/nginx/conf.d/default.conf(下边内容)
root@oldboy-lnmp:~# cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
root /app/code/blog/;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#3.检查语法,启动/重启服务
root@oldboy-lnmp:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@oldboy-lnmp:~# systemctl enable --now nginx
Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable nginx
2.4. 部署代码(业务)
#1. 创建代码目录
mkdir -p /app/code/blog/
#2.下载代码
https://cn.wordpress.org/download/
进入右键点击。复制链接
wget https://cn.wordpress.org/latest-zh_CN.zip
#3.解压代码移动到网站目录
apt update
apt install -y unzip
unzip -t latest-zh_CN.zip
unzip latest-zh_CN.zip
mv wordpress/* /app/code/blog/
#4.待补充
chown -R www-data.www-data /app/code/blog/
全部结束全部重启服务 确保服务全部开启+,
systemctl enable --now nginx php8.1-fpm
systemctl restart nginx php8.1-fpm
+++
3. 浏览器访问网站(最后的配置)
数据库密码 之前输入的Lidao996
密码自己设计
LNMP环境.
●
部署wordpress.