Ubuntu20.04.1 LTS安装PHP8.0.1

这是目前全网最新的安装指南了。

首先,20.04.1版本的Ubuntu没有包括8.0.1PHP,所以需要安装第三方的PPA库来进行安装,下面的命令增加第三方PPT到Ubuntu

sudo apt update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/nginx

与Apache不同,Nginx没有对php文件的内建支持,因此使用php-fpm(fastCGI process manager)来处理PHP文件。

目前最新的php版本是8.0.1,但是aliyun没法自动安装这个源,手动安装太麻烦,因此我只有先用8.0来试试。

和Apache2不同,Nginx自己没有自建队php的处理支持,所以需要分别安装Nginx和PHP

#sudo apt update
#sudo apt install nginx php8.0-fpm

重新启动Nginx和PHP-FRM

sudo systemctl restart nginx
sudo systemctl restart php8.0-fpm

检查服务状态如下

systemctl status php8.0-fpm.service

现在你可以编辑服务器配置,方便Nginx处理PHP文件。

由于Nginx没有内建PHP支持,所以需求手工编辑server部分来支撑PHP,如下

sudo nano /etc/nginx/sites-available/default

编辑下文粗体部分

   # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;
        # 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/php8.0-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

然后reload两个服务

sudo systemctl reload nginx
sudo systemctl reload php8.0-fpm

参考文档如下
https://websiteforstudents.com/install-php-8-0-on-ubuntu-20-04-18-04/

安装MariaDB

通过mysql进入数据库

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.002 sec)
MariaDB [(none)]> create user 'user'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> grant all privileges on wordpress.* to 'user'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

参考文档如下
https://developer.aliyun.com/article/761741

ubuntu升级软件和安装Nginx

首先看下有没有需要升级的软件

# apt list --upgradable
Listing... Done
linux-generic/focal-updates 5.4.0.60.63 amd64 [upgradable from: 5.4.0.54.57]
linux-headers-generic/focal-updates 5.4.0.60.63 amd64 [upgradable from: 5.4.0.54.57]
linux-image-generic/focal-updates 5.4.0.60.63 amd64 [upgradable from: 5.4.0.54.57]

还好,刚才已经把软件包升级过了,现在只要升级系统就可以。

升级软件包命令

sudo apt-get update 更新源
sudo apt-get upgrade 更新已安装的包

升级系统命令如下

sudo apt-get dist-upgrade 升级系统

然后在看下,都是最新的了。

#apt list --upgradable
Listing... Done
root@MDaliyun ~ # sudo apt update
Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal InRelease
Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates InRelease
Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.

下来安装Nginx

安装Nginx

sudo apt install nginx

查看Nginx状态

 sudo systemctl status nginx

root@MDaliyun / # vi /etc/nginx/nginx.conf

编辑 nginx.conf 文件。
找到 server{…},并将 server 大括号中相应的配置信息替换为如下内容。用于取消对 IPv6 地址的监听,同时配置 Nginx,实现与 PHP 的联动。

server {
 listen       80;
 root   /usr/share/nginx/html;
 server_name  localhost;
 #charset koi8-r;
 #access_log  /var/log/nginx/log/host.access.log  main;
 #
 location / {
       index index.php index.html index.htm;
 }
 #error_page  404              /404.html;
 #redirect server error pages to the static page /50x.html
 #
 error_page   500 502 503 504  /50x.html;
 location = /50x.html {
   root   /usr/share/nginx/html;
 }
 #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 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;
 }
}

参考文档如下
https://www.myfreax.com/how-to-install-nginx-on-ubuntu-18-04/

Ubuntu安装oh-my-zsh

1 直接安装zsh

#sudo apt update
#sudo apt install zsh

显示版本

# zsh --version
zsh 5.8 (x86_64-ubuntu-linux-gnu)

设置ZSH为默认shell

# chsh -s /bin/zsh

修改vps上的hosts

#whereis hosts
hosts: /etc/hosts.allow /etc/hosts.deny /etc/hosts /usr/share/man/man5/hosts.5.gz
# vi /etc/hosts

添加如下内容

127.0.0.1       localhost
# GitHub Start
52.74.223.119 github.com
192.30.253.119 gist.github.com
54.169.195.247 api.github.com
185.199.111.153 assets-cdn.github.com
#151.101.76.133 raw.githubusercontent.com
151.101.108.133 raw.githubusercontent.com
151.101.108.133 user-images.githubusercontent.com
151.101.76.133 gist.githubusercontent.com
151.101.76.133 cloud.githubusercontent.com
151.101.76.133 camo.githubusercontent.com
151.101.76.133 avatars0.githubusercontent.com
151.101.76.133 avatars1.githubusercontent.com
151.101.76.133 avatars2.githubusercontent.com
151.101.76.133 avatars3.githubusercontent.com
151.101.76.133 avatars4.githubusercontent.com
151.101.76.133 avatars5.githubusercontent.com
151.101.76.133 avatars6.githubusercontent.com
151.101.76.133 avatars7.githubusercontent.com
151.101.76.133 avatars8.githubusercontent.com
# GitHub End

安装oh-my-zsh(下面是官网命令)

Method  Command
curl    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
wget    sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fetch   sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

最终因为“墙”的问题,总是出现下面的问题

Failed to connect to raw.githubusercontent.com port 443: Connection refused

安装了openssl,安装git,安装wget,修改了上面的hosts,都无济于事。我就不打算折腾了,直接玩zsh也罢。
不玩不知道,zsh更方便。

2 新建一个zshrc配置文件如下

vi ~/.zshrc

文件内容如下

autoload -U compinit promptinit
compinit
promptini

执行命令 source ~/.zshrc 来生效修改的配置,而不需要重新登录,然后使用命令

# prompt -p

哈哈,显示如下缤纷灿烂的提示符,我选择prompt adam1,每次登录会恢复到原始状态,根据心情,选择一个就好。

配置Zsh可参考下文
https://wiki.archlinux.org/index.php/Zsh_(简体中文)