1.安装nginx
$ sudo apt install nginx
2.安装php7.0
$ sudo apt install php7.2
直接运行 apt-get命令安装 PHP 会报错误:
> E: Unable to locate package php7.2
> E: Couldn't find any package by regex 'php7.2'
原因是 PHP7 等并不在 Ubuntu的软件库中,因此要使用 PPA ppa:ondrej/php库
使用下列命令:
$ apt-add-repository ppa:ondrej/php
$ apt-get update
然后再执行:$ sudo apt install php7.2
如果出现错误代码:
> add-apt-repository: command not found
这个是缺少程序,安装一下就可以了,只是不知道安装的名字,
按以下命令走一趟就可以的了。
$ sudo apt-get install software-properties-common python-software-properties
3.安装php7.2-fpm,这是php和nginx之间的连接器。
sudo apt install php7.2-fpm
4.安装php7.2-dev和php7.2-mysql
sudo apt install php7.2-dev
sudo apt install php7.2-mysql
5.安装正则表达式库pcre
sudo apt install libpcre32-3
安装mbstring
sudo apt-get install php7.2-mbstring
6.安装mysql
$ apt-get –y install mysql-server mysql-client
7.向/etc/nginx/sites-available输入以下内容
server {
listen 80;
server_name your_site_name.com;
root /usr/share/nginx/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}