lnmp ubuntu 20.04

lnmp ubuntu 20.04 在Ubuntu安装nginx服务器,phpwordpressmysqlphpmyadmin

更新系统

1
2
sudo apt update
sudo apt upgrade

安装nginx

1
sudo apt install nginx

安装mysql,设置root及秘密。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
sudo apt install mysql-server-8.0 mysql-client-8.0 

sudo mysql -uroot

mysql> use mysql;

mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';

mysql> FLUSH PRIVILEGES;

mysql> exit;

csjtl@ubuntu:~$ sudo service mysql restart

csjtl@ubuntu:~$ mysql -uroot -p

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

mysql> exit

csjtl@ubuntu:~$ mysql -uroot -p

mysql> CREATE DATABASE wordpress;

mysql> FLUSH PRIVILEGES;

mysql> exit

安装php

1
2
3
csjtl@ubuntu:~$ sudo apt install php7.4-fpm php7.4-mysql php7.4 php7.4-gd php7.4-cgi php7.4-curl php7.4-mbstring php7.4-zip
csjtl@ubuntu:~$ ps -ef grep php

安装phpmyadmin

1
2
3
4
csjtl@ubuntu:~$ wget https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.tar.gz
tar -xvf phpMyAdmin-5.0.2-all-languages.tar.gz
mv phpMyAdmin-5.0.2-all-languages phpmyadmin
csjtl@ubuntu:~$ sudo cp -r phpmyadmin /var/www/html/

配置nginx站点默认端口和网站路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
csjtl@ubuntu:~$ sudo vi /etc/nginx/sites-available/default 

server {
listen 80 default_server;
listen [::]:80 default_server;

listen 443 default_server;
listen [::]:443 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

csjtl@ubuntu:~$ sudo service nginx restart

安装wordpress:默认安装目录为/usr/share/wordpress

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
csjtl@ubuntu:~$ wget https://cn.wordpress.org/latest-zh_CN.tar.gz
csjtl@ubuntu:~$ tar -xvf latest-zh_CN.tar.gz
csjtl@ubuntu:~$ cd wordpress
csjtl@ubuntu:~$ sudo mv * /var/www/html
csjtl@ubuntu:~$ cd /var/www/html

csjtl@ubuntu:~$ sudo cp wp-config-sample.php wp-config.php //重命名为wp-config.php文件

sudo vim wp-config.php //(11)编辑wp-config.php文件

默认内容如下:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');
/** MySQL database username */
define('DB_USER', 'username_here');
/** MySQL database password */
define('DB_PASSWORD', 'password_here');
/** MySQL hostname */
define('DB_HOST', 'localhost');
将其修改为:
// ** 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', 'root');
/** MySQL database password */
define('DB_PASSWORD', 'root');
/** MySQL hostname */
define('DB_HOST', 'localhost');

服务器IP/wp-admin/install.php //(12)安装

服务器ip/wp-login.php //(13)登陆

UBUNTUSERVER更多内容:

https://tl8517.com/category/personal-website-building/ubuntuserver/

ubuntu lamp 搭建(Apache+PHP+Mysql环境):

https://tl8517.com/ubuntu-lamp/