记录又一次惨痛的安装经历之 使用 LNMP 在Linux on Windows 上搭建Nextcloud

更新:果然很惨痛,最后不能上传文件,这样的配置,啥也干不了。
先直接上正确的安装教程。

打开 控制面板 程序 添加windows功能 子系统开关。

打开应用商店,搜索Ubuntu 16.04 LTS,等待安装。

安装完点击启动,稍等片刻。系统会分别要求输入用户名、密码、确认密码。

切换到root用户:

sudo -i
[输入刚才创建的密码]

配置清华镜像源:

1
2
cp /etc/apt/sources.list /etc/apt/sources.list.bak  //备份原有镜像源
vim /etc/apt/sources.list //修改
使用以下替换原文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

修改完毕,保存退出。更新安装源缓存:

1
2
apt install  -y update   //更新安装源缓
apt install -y upgrade //安装更新

安装mysql并确认

1
2
3
apt install -y mysql-server //安装过程中会提示输入root用户密码
apt install -y mysql-client
dpkg -l | grep mysql* //查看是否安装成功

启动mysql并确认

1
2
service mysql start
ps -ef | grep mysql* //查看是否有相应程序启动

安装nginx、PHP7.0及其扩展

1
2
apt install -y  nginx-full 
apt install -y php7.0 php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip

下载Nexcloud源码并转移至服务器路径

1
2
3
4
wget 'https://download.nextcloud.com/server/releases/latest.zip'
apt install unzip //安装解压程序
unzip latest.zip
cp -r nextcloud /var/www/html

设置目录权限

chown -R www-data:www-data /var/www/nextcloud/

创建虚拟主机

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
vim /etc/nginx/sites-available/nextcloud

#将以下内容写入
server {
server_name example.com;
access_log log/nextcloud_access.log;
error_log log/nextcloud_error.log;
root /var/www/html;
add_header Strict-Transport-Security "max-age=63072000;";
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}

location ~ ^(.+\.php)(.*)$ {
root /var/www/html;
include fastcgi_params;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME /var/www/example.com/$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}

让虚拟主机生效

1
2
3
4
nginx -t        //测试刚刚的配置是否存在问题,若有请自行解决
service nginx reload
service nginx restart
service php7.0-fpm restart

创建 Nextcloud 所需的数据库和账户

1
2
3
4
5
6
7
mysql -u root -p
[输入之前设置的数据库密码]
create database nextcloud;
create user nextcloud@localhost identified by 'password'; //用实际密码调整password
grant all on *.* to 'nextcloud'@'localhost' identified by 'password' with grant option; //同上
flush privileges; //刷新权限记录
exit; //退出

测试用户是否创建成功

1
2
mysql -u nextcloud -p
[输入之前设置的nextcloud用户密码]

配置NextCloud

在浏览器中访问http://localhost/nextcloud,打开成功即成功安装。