1、更新你的apt
$ sudo apt-get update && sudo apt-get upgrade
2、安装Nginx
$ sudo apt-get install nginx
nginx配置文件所在目录:/etc/nginx/
3、安装mysql5.7
$ sudo apt-cache search mysql | grep mysql | more
$ sudo apt-get install mysql-server-5.7
注:关于Mysql-server 和mysql-client,前面是服务器,后面是连接工具,所以暂时只安装server
创建子账号
> CREATE USER 'dige'@'%' IDENTIFIED BY '9012dIge';
给权限
> GRANT ALL ON dige.* TO 'dige'@'%';
4、安装php7.*(以7.3为例)
安装软件源扩展工具
$ sudo apt -y install software-properties-common apt-transport-https lsb-release ca-certificates
$ add-apt-repository ppa:ondrej/php
$ apt update
安装php7.3及扩展,一定要安装fpm扩展,fpm是管理fastcgi的工具,fastcgi容易崩溃,fpm可在其崩溃时重启fastcgi
$ sudo apt install php7.3-fpm php7.3-mysql php7.3-curl php7.3-gd php7.3-mbstring php7.3-xml php7.3-xmlrpc php7.3-zip php7.3-opcache -y
参考自:https://www.mf8.biz/ubuntu-debian-install-php7-3/
配置文件目录:/etc/php/7.3/
5、上传项目到某个地方,可以利用xshell开启文件传输,比较方便
6、配置nginx和php
nginx配置php以fpm方式运行的demo
# /etc/nginx/site-availible/default
server {
listen 81;
server_name www.chaojilaji.cn;
set $root_path '/var/www/dige/public';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
client_max_body_size 20m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
root $root_path;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index /index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
配置php
# /etc/php/7.3/fpm/php.ini
# 主要修改文件上传大小限制,url重写等内容
php.ini的demo下载地址:https://download.csdn.net/download/xielinrui123/11376604
7、对上传的文件做一些准备工作,例如我上传了一个laravel的项目,所以我需要使用 php artisan migrate 做数据迁移
8、文件操作完毕之后,来到nginx的目录 /etc/nginx ,使用 nginx -t 测试nginx的配置是否正确,如果返回successful,表明配置正确,利用 nginx -s reload可以平滑重新加载nginx而不需要重启Nginx。启动php7.3以fpm的形式运行,可以使用下列命令
$ sudo systemctl start php7.3-fpm
$ sudo systemctl stop php7.3-fpm
$ sudo systemctl restart php7.3-fpm
$ sudo systemctl reload php7.3-fpm