OpenSource

[ Ubuntu ] NextCloud구성

RI_Twins 2023. 2. 9. 13:48

개요

- Nextcloud는 클라우드 파일관리 서비스를 사용자의 컴퓨터나 모바일등에 설치해서 사용할 수 있게 해주는 클라우드 파일서버용 오픈소스 소프트웨어 입니다.

- 웹이나 어플에서 홈 서버의 파일을 사용하고, 홈서버에 파일을 전송하고 url를 통해 공유할 수 있습니다.

구성 순서

1. Apache2
 2. PHP 7.2 ( php의 경우 7.4아래 버젼으로 설치 )
 3. MariaDB 설치하기

구성방법

  1. Apache

# 패키지 최신화
$ sudo apt update
  
# Apache2 설치
$ sudo apt install apache2 -y

  1. Maria DB 설치

# Maria DB 설치
$ sudo apt-get install mariadb-server mariadb-client -y

  
# 기동 시 서비스 활성화
$ sudo systemctl enable mariadb.service

  
# 보안 설정 전 서비스 재 기동
# 재기동 안 할 시 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 에러 발생

$ sudo service mysql restart

  

# 보안 설정
$ sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
  

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
  

Enter current password for root (enter for none):  Enter 입력
OK, successfully used password, moving on...
  

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
  

Set root password? [Y/n] y
New password: 패스워드 입력
Re-enter new password: 패스워드 재 입력
Password updated successfully!
Reloading privilege tables..
 ... Success!

  
  

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
  

Remove anonymous users? [Y/n] y
 ... Success!
  

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
  

Disallow root login remotely? [Y/n] y
 ... Success!
  

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

  
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
  

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
  

Reload privilege tables now? [Y/n] y
 ... Success!

  
Cleaning up...

  
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

  1. PHP 7.2 설치

$ sudo apt -y install software-properties-common
  
$ sudo add-apt-repository ppa:ondrej/php
  
$ sudo apt update

  

# php7.2 설치 및 관련 패키지 설치
$ sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-gmp php7.2-curl php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-mysql php7.2-gd php7.2-xml php7.2-cli php7.2-zip -y

  
# Apahce 서비스 재 기동
$ sudo service apache2 restart

  1. NextCloud 설치

# 기본 웹 페이지 경로 이동
$ cd /var/www/html
  

# NextCloud 패키지 다운로드
$ sudo wget https://download.nextcloud.com/server/releases/latest-20.tar.bz2 -O nextcloud-20-latest.tar.bz2

  

# NextCloud 패키지 압축 풀기
$ sudo tar -xvjf nextcloud-20-latest.tar.bz2
  

# 사용자 권한 변경
$ sudo chown -R www-data:www-data /var/www/html/nextcloud/

  
# 읽고 쓰기 권한 변경
$ sudo chmod -R 755 /var/www/html/nextcloud/

  1. Apache 설정

# Conf 파일을 생성해서 NextCloud 컨텐츠에 액세스 하는 방법을 제어
$ sudo vi /etc/apache2/sites-available/nextcloud.conf

  

ServerAdmin 이메일주소
DocumentRoot /var/www/html/nextcloud/
ServerName 서버 ip
ServerAlias 서버 ip
  

Alias /nextcloud "/var/www/html/nextcloud/"
  
  
Options +FollowSymlinks
AllowOverride All
Require all granted
 

Dav off
  
SetEnv HOME /var/www/html/nextcloud
SetEnv HTTP_HOME /var/www/html/nextcloud
  
  
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
  

# 모듈 활성화
$ sudo a2enmod rewrite
$ sudo a2enmod headers
$ sudo a2enmod env
$ sudo a2enmod dir
$ sudo a2enmod mime

   

# Aapche 서비스 재기동
$ service apache2 restart

  1. DB 설정

# mysql 접속
$ sudo mysql -u root -p

# DB 생성
MariaDB [(none)]> CREATE DATABASE nextcloud;
  

# User 생성
MariaDB [(none)]> CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY '비밀번호';

  

# 권한 부여
MariaDB [(none)]> GRANT ALL ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY '비밀번호' WITH GRANT OPTION;

  

# 저장
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

  1. 계정 생성 및 활성화

- IP/nextcloud로 사이트 접속


1.  관리자 정보 입력 -  관리자 계정을 생성하기위해 원하는 아이디와 패스워드를 입력합니다.
  

2.  DB연결을 위해  데이터 베이스 사용자 ,  데이터베이스 암호 , 데이터 베이스 이름을 입력합니다.  ( 앞서 DB설정에서 입력한 값을 입력해줍니다)

  

데이터베이스 사용자 : nextclouduser

데이터베이스 암호 :  nextcloud DB 패스워드

데이터 베이스 이름 : nextcloud

  

3. 입력완료 후 하단에  설치완료 클릭