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_(简体中文)

Python@Socket

2019-9-1

服务器与客户端通信,实际是两个进程在通信。

在terminal(mac或windows)里输入ps,一般会显示本地的所有进程,包括其pid、创建时间等等。

由于两个进程不相关,所以单独通过pid等进行区分是没法避免冲突的,这就需要将三元组(地址、端口和协议)考虑进来。

同时直接对TCP/UDP/IP进行复杂操作太麻烦,因此在应用层和传输层之间,使用Socket进行抽象,通过几个简单接口来实现通信。Socket起源于Unix,在其一切皆文件对思路下,服务器和客户度各自维护一个文件,Socket也是一种“文件打开-读/写-文件关闭”对模式,建立连接后,各自对自己的文件进行写或读的操作,同时供对方读或写,通讯结束关闭这个文件。

流程如下:

1-服务器创建socket
2-服务器为socket绑定IP+端口
3-服务器监听socket
4-客户端创建socket
5-客户端打开socket,根据服务器地址和端口访问服务器socket
6-服务器socket接收到客户端socket请求,被动打开!!!开始接受客户端请求,当客户端返回连接信息,socket进入阻塞状态即accept()方法一直到客户端返回连接信息后才返回
7-客户端连接成功,向服务器发送连接状态信息
8-服务器accept方法返回,连接成功
9-服务器读取信息
10-客户端关闭
11-服务器关闭

商汤是否成为一家伟大公司的判断

2018-9-23

使用“从零到一”这本书提供的原则:

  1. the engineering question
    1. 除了有10倍于市场平均水平的融资能力外,目前看不到商汤有什么能够带来颠覆的产品或者技术;
    2. 从ToB市场分析,没有那些企业、政府客户可以从人工智能行业受益,至少2018年的行业反馈是如此。
  2. the timing question
    1. 人工智能行业前有BAT三大巨头,身旁有科大讯飞势均力敌,身后是云从、依图等小弟拼命追赶,时不我待,如果2018年无法顺利上市,真的危险。
  3. the monopoly question
    1. 是否能做安防行业这个小池塘里的大鱼呢?和海大宇比较起来,遥不可及;
    2. 客户不关心什么新奇的技术,除非 其能够以一种超级牛的方式解决某种特定问题;
  4. the people question
    1. 从网罗中国人工智能算法人才看,这事商汤做对了的事情
  5. the distribution question
    1. 呵呵
  6. the durability question
    1. AI是下一个物联网吗?是下一个ATM吗,谁也不知道;
  7. the secret question 
    1. 商汤有秘密吗?谁也不知道

以上规则用来检验商汤是否是个好公司。

创业公司能否继续生存的7条checklist

2018-9-16

创业公司能否继续生存的7条checklist

  1. the engineering question
    1. 颠覆性创新,有10倍提升,只有这样才能让最终用户感知到技术的提升;
    2. 给客户提供显而易见的优势
  2. the timing question
    1. 需要指数级增长
  3. the monopoly question
    1. 小市场里的大份额
    2. 客户不关心什么新奇的技术,除非 其能够以一种超级牛的方式解决某种特定问题;
  4. the people question
  5. the distribution question
  6. the durability question
    1. 10-20年的可持续市场
  7. the secret question
    1. 了解其他人不知道的事情