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安裝界面出現了,大功告成


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM