ubuntu20.04安装php8和wordpress

安装mysql8.0

sudo apt install mysql-server
......
Processing triggers for systemd (245.4-4ubuntu3.7) ...###############################################################################################################################################################################...] 
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

安装完成,然后设置mysql用户

mysql> use mysql;
mysql> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| localhost | debian-sys-maint | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | auth_socket           |
+-----------+------------------+-----------------------+
6 rows in set (0.00 sec)

添加用户

如果不需要远程访问,那么将%替换为localhost或127.0.0.1

mysql> CREATE USER ‘admin‘@‘%‘ IDENTIFIED WITH mysql_native_password BY ‘12345678‘;
如果用户需要远程访问

需要设置mysql监听的地址,把默认的127.0.0.1 改为0.0.0.0(或者需要提供访问的网络里,主机的ip地址)

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
sudo service mysql restart

查询用户是否设置成功

mysql> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| %         | admin            | mysql_native_password |
| localhost | debian-sys-maint | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | auth_socket           |
+-----------+------------------+-----------------------+

如此,mysql链接可以远程访问了

添加wordpress数据库,并授权给用户admin

mysql> create database wordpress DEFAULT CHARSET=utf8mb4;
Query OK, 1 row affected (0.01 sec)

mysql> grant all on wordpress.* to admin@‘%‘;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

安装php8.0

这里就直接用系统官方的源了,不费事;(用8.0的原因是,8.0引入了jit编译,计算性能相比7.x提升巨大,不同场景下有1.5-4倍的性能提升)

sudo apt install php8.0 php8.0-cli php8.0-xml php8.0-mysql php8.0-gd php8.0-imagick php8.0-fpm php8.0-xmlrpc

安装完成以后,我们需要记住php-fpm的监听地址

cat /etc/php/8.0/fpm/pool.d/www.conf

找到listen这一行

listen = /run/php/php8.0-fpm.sock

这里要着重注意一下

listen.owner = www-data
listen.group = www-data

这个是php-fpm的执行用户角色,php文件最终是丢给这个用户角色去运行的

下载wordpress

官方下载最新版5.7.2,然后解压到服务器上 /var/www/html/wordpress;
设置wp-content的权限; 这个是所有php程序报错无权限的根源所在

sudo chown -R www-data:www-data wp-content

如此就可以愉快的修改配置,装插件、主题了

安装nginx

此处可以根据自己需要自己编译,也可以使用官方的源
我使用的openresty的套件

基础用法一致
添加php服务配置 www_youkong.conf

server{
   listen 80;
   server_name www.youkong.chat;

   root /var/www/html/wordpress;
   index index.php;

    access_log /var/log/nginx/youkong.chat.access.log;
    error_log /var/log/nginx/youkong.chat.error.log;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        expires 30d;
        log_not_found off;
    }

}

检测配置,加载php服务

ubuntu@VM-0-15-ubuntu:/usr/local/openresty/nginx$  nginx -t
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful

ubuntu@VM-0-15-ubuntu:/usr/local/openresty/nginx$ nginx -s reload

查看结果

解析完成
浏览器打开 http://www.youkong.chat/ ,熟悉已久的wp安装界面出现了,大功告成

ubuntu20.04安装php8和wordpress

上一篇:http/https请求----cookies和session 接口应用


下一篇:web自动化元素定位大全