Ubuntu APM (Apache + PHP + My-SQL) 설치 방법

Ubuntu APM (Apache + PHP + My-SQL) 설치 방법

in

Package Update && Upgrade

설치하기 앞서 패키지 목록을 업데이트, 업그레이드 해줍니다.

$ sudo apt-get update && sudo apt-get upgrade

Install Apache2

아래 명령어로 Apache2를 설치해줍니다.

$ sudo apt-get install apache2

참고로, Apache2 의 default Document Root 경로는 “/var/www/html” 이며, “/etc/apache2/apache2.conf” 파일을 수정하면 디폴트 Document Root를 수정할 수 있습니다.

이후 “localhost” or “127.0.0.1” 을 접속하여 Apache2의 설치를 확인할 수 있습니다.

Install My-SQL

Install My-SQL

아래 명령어로 설치해 줍니다.

$ sudo apt-get install mysql-server

ReInstall My-SQL

삭제 후 재설치 하는 방법 입니다.

$ sudo apt-get remove --purge mysql*
$ sudo apt-get purge mysql*
$ sudo apt-get autoremove.
$ sudo apt-get autoclean.
$ sudo apt-get remove dbconfig-mysql.
$ sudo apt-get dist-upgrade.
$ sudo apt-get install mysql-server.

My-SQL Setting

sihaku@sihaku-pc:~$ sudo mysql_secure_installation



Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: // y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: // 1
Please set the password for root here.

// root 패스워드를 입력합니다.
New password:   

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : // y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : // 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.
// y를 입력하면 원격 접속으로 root 계정을 사용할 수 없습니다. 별도의 계정을 생성해야 합니다.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : // y Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : // 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? (Press y|Y for Yes, any other key for No) : // y
Success.

All done!

My-SQL 계정 생성

User Account

mysql> create user 'USER_NAME' identified by 'USER_PASSWORD';
Query OK, 0 rows affected (0.00 sec)

Root Account

이후 사용할 PhpMyAdmin 에서는 mysql의 Root 계정으로 접속해야 하므로 비밀번호를 설정해 줍니다. mysql에서는 root로 접속할 경우 mysql -u root -p 명령어로 접속하면 됩니다.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new-password';

Install PHP

Install PHP

아래 명령어로 php를 설치해 줍니다.

$ sudo apt-get install php php-mysql

Test PHP

PHP가 정상적으로 작동 되는지 확인하려면 아래와 같이 ‘info.php’ 파일을 만들어 테스트 가능합니다. 해당 파일 추가 이후 브라우저를 이용해 localhost/info.php 에 접속하여 PHP info가 나오는지 확인 합니다.

$ sudo vim /var/www/html/info.php

<?php phpinfo(); ?>

TIP

Apache 웹서버 구축에서 알고있으면 유용한 커맨드 입니다.

// 실행중인 서비스들을 나열 합니다.
$ service --status-all

// 서비스 중지, 시작, 재시작
$ service [패키지이름] [stop|start|restart]

// 호스트 활성화(페이지 설정) 명령어
$ sudo a2ensite [도메인주소]

// 호스트 비활성화(페이지 설정) 명령어
$ sudo a2dissite [도메인주소]

References