본문 바로가기
IT

Ubuntu Server 20.04 Nginx+MariaDB+Php 설치 완료

by Oh.mogilalia 2021. 7. 25.

1. 우분투 설치 및 HDD 마운트

-----------------------------------자신만의 계정을 추가
sudo adduser mogibu
sudo usermod -G sudo mogibu 추가한 계정에 sudo 권한 부여
sudo passwd root 패스워드 변경

$ sudo groupadd your-group-name

$ sudo usermod -a -G your-group-name your-user-name
$ sudo passwd

$ sudo nano /etc/ssh/sshd_config
# Find "PermitRootLogin" and change it to "no".
$ sudo service sshd restart
Restart the shell and login again with your new account.

----------------------------------- 호스트 이름 변경
sudo nano /etc/hostname

원하는 이름 기재 후

hostname -F /etc/hostname

재접속하면...


------------------odroid 사용자 제거
sudo deluser -remove-all-files odroid
sudo rm -rf /home/odroid

---------------------------Update the system
Type the command lines below to update your ODROID.
$ sudo apt update && sudo apt full-upgrade
And install latest kernel.
$ sudo apt install linux-image-xu3
$ reboot
Set timezone/locale data
Set timezone.
$ sudo dpkg-reconfigure tzdata
Set locale.
sudo locale-gen "en_US.UTF-8"
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
sudo dpkg-reconfigure locales
# Select "en_US.UTF-8" for all of the steps.
To take effect, you should re-connect your shell and you can check using following command.
$ locale
# results


---------------------------------하드디스크 마운트
3. 설정 변경

1) 파티션 UUID 확인
66c37e71-5fdd-4af1-94a2-391b5238f2c9

2) boot.ini 설정 변경
root 파티션의 UUID를 mmcblk1p2에서 sda1로 변경

$ sudo cp /media/boot/boot.ini /media/boot/boot.ini.orig
$ sudo nano /media/boot/boot.ini

설정 변경

# Boot Args
setenv bootargs "console=tty1 console=ttySAC2,115200n8 root=UUID=66c37e71-5fdd-4af1-94a2-391b5238f2c9 rootwait ro fsck.repair=yes net.ifnames=0 ${videoconfig} ${hdmi_phy_control} ${hid_quirks} smsc95xx.macaddr=${macaddr} ${external_watchdog}"

3) fstab 설명 변경
root 파티션 mmcblk1p2에서 sda로 변경

$ sudo cp /etc/fstab /etc/fstab.orig
$ sudo nano /etc/fstab

설정 변경
UUID=e139ce78-9841-40fe-8823-96a304a09859 / ext4 errors=remount-ro,noatime 0 1
LABEL=boot /media/boot vfat defaults 0 1
==>
#UUID=e139ce78-9841-40fe-8823-96a304a09859 / ext4 errors=remount-ro,noatime 0 1
LABEL=boot /media/boot vfat defaults 0 1
/dev/sda / ext4 defaults,noatime 0 1

4. 루트 파티션 복사
$ sudo rsync -axv / /media/sys/

5. Root 파티션 확인
1) 리셋
2) Root 파티션 확인
$ df -h

sudo usermod -d /home/mogibu/ mogibu

-------------------------------apt upgrade 에러 발생
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock*

2. Nginx 설치

1. NGINX 설치

1) NGINX 설치
$ sudo apt install nginx -y
$ nginx -v
Connect http://192.168.101.210
------------------------------------------------
2) PHP 설치
$ sudo apt install php php-fpm php-mysql -y
$ sudo apt remove apache2 --purge -y
$ sudo rm -rf /etc/apache2
$ sudo netstat -an | grep php
3) PHP를 위한 NGINX 설정 변경
$ sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.orig
$ sudo rm /etc/nginx/sites-enabled/default
PHP 소켓 확인

$ sudo netstat -an | grep php
$ sudo nano /etc/nginx/sites-available/default
설정 추가
---------------
server{

listen 80;
server_name test.local;
root /var/www/html;
index index.html index.htm index.php index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
---------------
$ cd /etc/nginx/sites-enabled/
$ ls -l
$ sudo -i
# cd /etc/nginx/sites-enabled/
# ln -s /etc/nginx/sites-available/default
# ls -l
# exit
$ sudo nano /var/www/html/phpinfo.php

설정 추사
<?php
phpinfo();
?>
Connect http://192.168.0.9/phpinfo.php


2. HTTPS 서비스 추가

1) SSL인증서 추가
개인키 생성
$ sudo openssl genrsa -des3 -out server.key 2048
Generate CSR(Certification sinning Request)
$ sudo openssl req -new -days 365 -key server.key -out server.csr
개인키 암호 삭제 /home/mogibu/apm/www
$ sudo cp server.key server.key.orig
$ sudo openssl rsa -in server.key.orig -out server.key
Enter pass phrase for server.key.orig:
writing RSA key
인증서 생성
$ sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Signature ok
subject=C = KR, ST = Ulsan, L = Ulsan, O = Internet Widgits Pty Ltd, emailAddress = mogibu@gmail.com
Getting Private key

인증서 확인
$ ls -l server.*
mogibu@mogibu:~/apm/www$ ls -l server.*
-rw-r--r-- 1 root mogibu 1245 Jul 25 14:44 server.crt
-rw-r--r-- 1 root mogibu 1054 Jul 25 14:43 server.csr
-rw------- 1 root mogibu 1675 Jul 25 14:44 server.key
-rw------- 1 root mogibu 1743 Jul 25 14:44 server.key.orig

$ sudo cat server.key | head -3
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA2lO9eqHZ3K7ZxsouesysOXheOtTUvnbndvzM2ulSOcsueGRh
91OworW6v4xreQdJ0saZC37INSfrQmBNvfL+3XQRPwP04nP6lIGCL0OYigBeJbsh

$ sudo cat server.crt | head -3
-----BEGIN CERTIFICATE-----
MIIDaTCCAlECFGZibEIwzwJohgoRsQyr8LDPmGxxMA0GCSqGSIb3DQEBCwUAMHEx
CzAJBgNVBAYTAktSMQ4wDAYDVQQIDAVVbHNhbjEOMAwGA1UEBwwFVWxzYW4xITAf

인증서 NGIX 디렉터리로 복사
$ sudo mkdir /etc/nginx/ssl
$ sudo cp ~/server.* /etc/nginx/ssl/
2) HTTPS를 위한 NGINX 설정
$ sudo nano /etc/nginx/sites-available/default
Insert Configuration
server{
listen 443 ssl;
server_name test.local;
root /var/www/html;
index index.html index.htm index.php index.nginx-debian.html;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

3. MariaDB 설치

1. MariaDB 설치
$ sudo apt install mariadb-server mariadb-common mycli python3-mysqldb -y

2. MariaDB 초기 설정

MariaDB 초기 설정
$ 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):
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]
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]
... 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]
... 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]
- 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]
... Success!

Cleaning up...

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

Thanks for using MariaDB!
MariaDB 접속 IP 변경
$ sudo cp /etc/mysql/mariadb.conf.d/50-server.cnf /etc/mysql/mariadb.conf.d/50-server.cnf.orig
$ sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
[server]

# this is only for the mysqld standalone daemon
[mysqld]

#
# * Basic Settings
#
user = mysql
pid-file = /run/mysqld/mysqld.pid
socket = /run/mysqld/mysqld.sock
#port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql

설정 변경
bind-address = 127.0.0.1
==>
bind-address = 192.168.0.9

$ sudo systemctl restart mariadb.service

3. 관리 계정 생성

Management Account
accout : test
password : test@test

MriadDB 접속
$ sudo mysql -u root -p
Create MariaDB Account
> create user 'mogibu'@'%' identified by 'Tmdahrl0)';
> grant all privileges on *.* to 'mogibu'@'%' with grant option;
> flush privileges;
> quit;

4. MariaDB 설정 검증

$ mycli -h 192.168.0.9 -u mogibu

/etc/mysql/mariadb.conf.d/override.cnf 파일을 생성하고 아래의 내용을 저장한다.

#vi /etc/mysql/mariadb.conf.d/override.cnf
/etc/mysql/mariadb.conf.d/override.cnf 에 추가
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

query_cache_type = ON
query_cache_limit = 4M
query_cache_size = 64M

max_allowed_packet = 64M

slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 5

skip-log-bin

sql_mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION






mysql 환경설정 문법 테스트 (mysql config file configtest)

반드시 아래의 명령어로 입력할 것.

# mysqld --verbose --help | grep configtest
오류메세지가 출력되지 않는다면 정상이다. ([Note] Plugin ‘FEEDBACK’ is disabled. 메세지는 무시해도 된다.)
설정파일 오류가 없다면 mysql 을 재시작하여 적용하도록 하자.

4. Wordpress 설치

1. 워드프레스 다운로드

$ sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip php-net-ldap2 php-net-ldap3 php-net-idna2 -y
$ wget https://wordpress.org/latest.zip
$ unzip latest.zip

2. 워드프레스를 위한 데이터베이스 생성

WordPress
SQL database : wordpress
SQL userid : wordpress
SQL password : test@test
※ 환경에 맞춰 설정 변경 필요

$ sudo mysql -u root
> create database wordpress;
> grant all on wordpress.* to mogibu@localhost identified by 'Tmdahrl0)';
> flush privileges;
> quit;

3. 워드프레스 설치

$ sudo chown -R www-data:www-data /home/mogibu/apm/www/wordpress
$ sudo ls /home/mogibu/apm/www/ -l

4. 워드프레스 기초 설정

WordPress
SQL database : wordpress
SQL userid : mogibu
SQL password : Tmdahrl0)
※ 환경에 맞춰 설정 변경 필요

http://192.168.0.9/wordpress 에 접속
언어 설정
데이터베이스 설정
워드프레스 추가 정보 설정
관리 계정 접속
테마 변경

service php7.4-fpm restart

nginx로 reverse proxy 를 사용할 때, 용량이 큰 파일을 업로드하면 413 Request Entity Too Large 라는 메시지를 볼 수 있다.

413 Request Entity Too Large

client_max_body_size 설정 때문이고, 너무 큰 사이즈의 request를 보내지 못 하도록 제한을 걸 수 있다. 기본값은 1MB이다. request의 Content-Length 헤더값이 여기 설정된 값을 넘을 수 없다. POST나 PUT 등의 request 사이즈 제한을 할 수도 있지만, 보통 악의적으로 큰 용량의 파일을 업로드해서 디스크를 가득 채우는 경우를 방지하는데 사용되지 않을까 싶다.

nginx.conf 파일에서 http, server, location에 설정이 가능하다.

http {
client_max_body_size 5M;

...
}

설정을 해주지 않으면 기본값은 1m이고, 제한을 두지 않으려면 0으로 설정하면 된다.

Syntax: client_max_body_size size;
Default: client_max_body_size 1m;
Context: http, server, location
nginx.conf 파일을 수정하고, 재시작해주면 끗

$ sudo service nginx reload

sudo apt install php-curl
sudo apt install php-dom
sudo apt install php-mbstring
sudo apt install php-imagick
sudo apt install php-zip
sudo apt install php-gd


https://webmaster.cafe/tools/nginx-conf-generator/my-example-site.com.php?s=mogibu&h=wordpress.mogibu.kro.kr&d=%2Fhome%2Fmogibu%2Fapm%2Fwww%2Fwordpress

'IT' 카테고리의 다른 글

Nextcloud 몇 가지 에러 문제...  (0) 2021.07.26
Phpmyadmin 설치  (0) 2021.07.26
ubuntu hdd mount  (0) 2021.07.25
ubuntu 16.04 Mysql 데이터 디렉토리 변경 방법  (0) 2021.07.23
우분투 서버 20.04, Odroi HC2 설치  (0) 2021.07.22