Ubuntu 18.04 LEMP Stack

Ubuntu 18.04 LEMP Stack




Mariadb 10.3 설치

mariadb 10.1 –> 10.3 으로 변경 10.1 repo 에서 정상적으로 설치 되지 않음


mariadb 레포지터리를 추가 합니다. 

test@ubuntu1804:~$ sudo apt-get install software-properties-common
test@ubuntu1804:~$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
test@ubuntu1804:~$ sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://ftp.kaist.ac.kr/mariadb/repo/10.3/ubuntu bionic main'


mariadb-server , mariadb-client 패키지를 설치 합니다.

test@ubuntu1804:~$ sudo apt update
test@ubuntu1804:~$ sudo apt -y install mariadb-server mariadb-client

# 패스워드를 설정 합니다.


mariadb 서비스를 실행 및 활성화 합니다.

test@ubuntu1804:~$ sudo systemctl start mariadb.service
test@ubuntu1804:~$ sudo systemctl enable mariadb.service


mysql_secure_installation 을 실행 합니다.

test@ubuntu1804:~$ sudo mysql_secure_installation


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):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
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.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

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.

Thanks for using MariaDB!


mariadb character set 을 utf8mb4 로 변경 합니다.

test@ubuntu1804:~$ sudo vi /etc/mysql/mariadb.cnf
# MariaDB-specific config file.
# Read by /etc/mysql/my.cnf

default-character-set = utf8mb4
# Default is Latin1, if you need UTF-8 set this (also in server section)
#default-character-set = utf8


character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci


mariadb.service 재시작후 character set 확인 합니다.

test@ubuntu1804:~$ sudo systemctl restart mariadb.service
test@ubuntu1804:~$ sudo mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 37
Server version: 10.3.10-MariaDB-1:10.3.10+maria~bionic-log mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> status;
mysql  Ver 15.1 Distrib 10.3.10-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Connection id:          37
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server:                 MariaDB
Server version:         10.3.10-MariaDB-1:10.3.10+maria~bionic-log mariadb.org binary distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:            /var/run/mysqld/mysqld.sock
Uptime:                 11 sec

Threads: 8  Questions: 61  Slow queries: 0  Opens: 32  Flush tables: 1  Open tables: 26  Queries per second avg: 5.545

MariaDB [(none)]> quit;


Nginx 설치

test@ubuntu1804:~$ sudo apt install -y nginx


nginx 서비스를 실행 및 활성화 합니다.

test@ubuntu1804:~$ sudo systemctl start nginx
test@ubuntu1804:~$ sudo systemctl enable nginx


nginx.conf 를 설정 합니다.

test@ubuntu1804:~$ sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.org
test@ubuntu1804:~$ sudo vi /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 1024;

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;


/etc/nginx/sites-enabled/default 설정

server {
    listen 80;
    listen [::]:80;
    root /var/www/html;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;

    location / {
        try_files $uri $uri/ =404;

     # pass PHP scripts to FastCGI server
        location ~ \.php$ {
               include snippets/fastcgi-php.conf;
        #       # With php-fpm (or other unix sockets):
               fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass;


nginx config 를 확인 합니다.

test@ubuntu1804:~$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


php 7.1 0설치

test@ubuntu1804:~$ sudo add-apt-repository ppa:ondrej/php
test@ubuntu1804:~$ sudo apt-get install -y php7.1
test@ubuntu1804:~$ sudo add-apt-repository universe
test@ubuntu1804:~$ sudo apt install -y php7.1-fpm php7.1-mcrypt php7.1-cli php7.1-xml php7.1-mysql php7.1-gd php7.1-imagick php7.1-recode php7.1-tidy php7.1-xmlrpc


php.ini 설정

test@ubuntu1804:~$ sudo vi /etc/php/7.1/fpm/php.ini
display_errors = On
display_startup_errors = On
date.timezone = Asia/Seoul


php-fpm 설정 www.conf

test@ubuntu1804:~$ sudo vi /etc/php/7.1/fpm/pool.d/www.conf
listen.owner = www-data
listen.group = www-data
listen.mode = 0660


php7.1-fpm.service 재시작

test@ubuntu1804:~$ sudo systemctl restart php7.1-fpm.service


phpinfo 확인

test@ubuntu1804:~$ sudo vi /var/www/html/test.php
<?php phpinfo(); ?> 로 접속하여 확인 합니다. 



댓글 남기기