본문 바로가기
Linux/Pogoplug

포고플러그 시리즈4에 아치리눅스 사용하기 (8) - 아파치 웹서버+mySQL+PHP+phpMyAdmin 설치하기

by 달토끼남편 2022. 10. 4.

[2013-08-06 업데이트]  

그누보드같은 설치형 게시판 설치가 안되던 문제가 있었습니다.

mysqli_ 로 시작하는 문법은 적용이 되는데  구 문법인 mysql_ 로 시작하는 문법이 먹히질 않아 초기 설정 부분부터 다시 봤는데, 역시나 빼먹은게 있었네요.

본문에 추가설정 사항으로 추가해 두었습니다. 

[2013-08-04 업데이트] 

확실히 DB가 메모리를 많이 점유하는 것 같네요.

굳이 PHP와 DB가 필요없으신 분들은 건너 뛰시고, 아파치만 설치하셔도 될 듯...뒤이은 WebDAV 설정하기에서도 아파치 서버만 필요한 관계로.

--------------------

 

 

LAMP는 Linux+Apache+MariaDB(또는 MySQL)+PHP을 이야기한다.

 

무엇보다 WebDAV를 사용해 보고 싶어 궁극적으로 웹서버를 설치하게 되었다.

요즘 인기급상승 중이라는 NginX를 설치해보고 싶었으나, 뭐 거의 혼자 테스트용으로 사용할 것이고 동시접속자도 거의 없는 관계로 아치리눅스에 AMP를 설치한다.

그리고 끝으로 DB 관리툴인 phpMyAdmin도 설치해 본다.

 

※ 참고 : https://wiki.archlinux.org/index.php/LAMP

             https://wiki.archlinux.org/index.php/PhpMyAdmin

 

현재 아파치 서버의 버전은 2.4 버전까지 나와 있지만 설치가능한 것은 2.2.25-1이다.

 

1. 아파치, PHP, maria DB 설치하기

 

pacman -S apache

pacman -S php php-apache

2013년 3월 이후 아치리눅스에서 mySQL이 mariaDB 로 대체되었다.

따라서, mysql을 설치하려고 해도 mariaDB로 변경되어 설치된다.

https://www.archlinux.org/news/mariadb-replaces-mysql-in-repositories/

 

pacman -S mariadb

 

2. 아파치 웹서버 설정하기

 

설치가 끝나면 httpd.conf 파일을 수정한다.

(앞서 DDNS를 설정하고 내 도메인을 가지고 있다는 가정 하에 수행)

 

nano /etc/httpd/conf/httpd.conf

--------

 

ServerAdmin nekojp@naver.com (필요하면 관리자 이메일주소 수정)

ServerName www.mydomain.com (#을 제거하고 내 도메인을 넣어준다.)
#LoadModule unique_id_module modules/mod_unique_id.so 을 찾아 # 주석처리한다.
 
DirectoryIndex index.html index.php (index.php 파일이 추가되어있는지 확인한다.)
hosts 파일을 열어 내 ip 주소 추가한다.
 
nano /etc/hosts
------
 
#<ip-address>   <hostname.domain.org>   <hostname>
포고플러그 내부 ip   내 도메인(DDNS)               도메인의 호스트명
 
ex) 192.168.1.17    nekojp.test.com     nekojp      
※ 참고 : 보틍 hostname 이라고 하면 도메인의 맨 앞에 있는 부분이다.
www.naver.com 이라고 하면 www가 호스트명인데 World Wide Web 서비스(흔히 말하는 웹서비스)를 하는 서버라는 뜻이다.
 
systemctl start httpd 
아파치 시작 후 테스트는 브라우저에서 http://내부 ip 또는 http://내 도메인 으로 접속을 해보면 아래와 같이 나오면 정상이다.
 
 
 
뭐 얼추 설치가 된 것 같기는 한데, 조금  보기가 그렇다.
간단하게 HTML 페이지를 만들어 표시해 보자.
 
nano /srv/http/index.html
 
<html>
<head>
<title>Welcome</title>
</head>
<body>
<p>Welcome to Pogoplug series 4</p>
<p>포고플러그에 오신 것을 환영합니다.</p>
</body>
</html>
ctrl+o 로 저장 후, ctrl+x 로 끝낸 후, 다시 브라우저로 접속해 보자.
브라우저 화면에 아래와 같이 표시가 된다.
 
 
이제 웹서버는 정상작동한다.
외부에서도 접속이 가능하게 하려면 마찬가지로 80포트를 포트포워딩 해주면 된다.
 
 
3. PHP 설정하기
 
자, 이제는 아파치 중지 후 이제 PHP를 설정해 보자.
 
systemctl stop httpd
nano /etc/httpd/conf/httpd.conf
------
 
맨 밑에 다음 라인을 추가한다.
 
# Use for PHP 5.x:
LoadModule php5_module modules/libphp5.so
AddHandler php5-script php
Include conf/extra/php5_module.conf
 
이제 php 파일을 웹서버에서 인식할 수 있도록 MIME 타입을 설정한다.
 
nano /etc/httpd/conf/mime.types 
-------
 
적당한 위치에 아래 항목을 추가해 준다.
application/x-httpd-php       php    php5
※ 참고 : MIME 타입은 컨텐츠의 종류를 정의하는 것으로 이 문서는 응용프로그램으로 실행가능한 문서다. 그 문서의 종류는 php이다. 라고 웹서버에게 알려주는 것이다. 이 MIME 타입을 정의하지 않으면, 아래 info.php 파일을 실행했을 때 서버에서 실행된 결과물이 나오는 것이 아니라, 그냥 문서에 적힌 내용 그대로 브라우저 화면에 나오게 된다. 
 
여기까지 했으면 웹서버의 루트디렉토리인 /srv/http 디렉토리에 info.php 파일을 만들고 내용을 아래와 같이 적어준다.
 
cd /srv/http
nano info.php
------
 
<?php phpinfo() ?>
systemctl restart httpd
그리고 브라우저에서 다시 http://내부 아이피/info.php 또는 http://도메인명/info.php 처럼 접속해 보면 아래와 같이 PHP 환경에 대해 나온다.
 
 
 
 
 
추가적으로 설정해야 할 사항들...
 
nano /etc/php/php.ini
-----------
 
date.timezone = Asia/Seoul (; 주석처리를 지우고 시간대를 맞춘다.)
extension=mysql.so (;주석 제거)
 
-----------
systemctl restart httpd
 
 
 
4. mariaDB 설정하기
 
systemctl start mysqld
mysql_secure_installation
DB 대몬을 실행하고 데이터베이스에 접근할 수 있는 별도의 패스워드를 설정하게 된다.
처음에는 루트(여기서는 DB의 루트) 패스워드가 없으므로 그냥 엔터를 치고, 다음에 나오는 패스워드 설정에서 DB에 접속하기 위한 패스워드 설정을 한다.
그리고, 나머지는 그냥 다 y 로 답하자.
 
[root@alarm ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
 
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] 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.
 
Thanks for using MariaDB!
끝으로 DB는 제대로 설치가 되었는지 접속테스트를 해보자.
 
mysql -u root -p
아래와 같은 화면이 나오는가?
패스워드는 ssh접속할 때 사용하는 루트의 패스워드가 아니라 앞서 설정한 mariaDB 루트의 패스워드이다. 
exit; 를 입력하고 끝낸다.
 
mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.32-MariaDB-log Source distribution
 
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]> exit;
Bye
 
이것으로 LAMP의 설치와 설정이 모두 끝났다.
하지만 추가적으로 하나 더 설치해보도록 하자.
바로 phpMyAdmin이다.
 
4. phpMyAdmin 설치하기
 
phpMyAdmin은 웹기반의 데이터베이스 관리툴이다.
앞서 DB에 접속해 본 것처럼 커맨드라인에서 작업을 할 수도 있지만 아무래도 웹 상에서 GUI 환경에서 하는 것이 관리도 편하고 이용도 쉽다.
 
pacman -S phpmyadmin php-mcrypt
 
설치가 끝나면 예제 설정파일을 복사한다.
 
cp /etc/webapps/phpmyadmin/apache.example.conf /etc/httpd/conf/extra/httpd-phpmyadmin.conf
 
httpd.conf 파일을 열어 include 줄을 찾아 다음을 마지막에 추가한다.
 
nano /etc/httpd/conf/httpd.conf 
--------
 
# phpMyAdmin configuration
Include conf/extra/httpd-phpmyadmin.conf
 
그리고 접근권한 설정을 위해 .htaccess 파일을 열어 수정한다.
 
nano /etc/webapps/phpmyadmin/.htaccess
--------
 
#deny from all
allow from all
 
만약 phpMyAdmin 내부 인증을 원한다면 mysqli과 mcrypt이 필요하다.
그래서, php.ini 파일을 열어 ctrl+w로 찾아서 아래 두 문장 앞의  ; 주석처리를 지운다.
 
nano /etc/php/php.ini
---------
 
extension=mcrypt.so
extension=mysqli.so
 
 
 
웹서버를 다시 시작한다.
 
systemctl restart httpd
 
그리고 브라우저에서 http://내부 ip/phpmyadmin 또는 http://내 도메인/phpmyadmin 으로 접속하면 아래와 같은 화면이 나온다.
 
 
그리고 앞서 설정한 DB의 패스워드를 입력하고 들어가면 웹기반의 DB 관리화면을 만날 수 있다.
지금 내가 웹호스팅업체에서 사용하고 있는 것보다 UI가 좀더 산뜻해지고 깔끔하다. 음...
 
 
phpMyAdmin을 이용해서 데이터베이스의 생성은 물론 레코드 삽입 등 일련의 DB 작업들을 모두 할 수 있어 커맨드라인에서 작업하는 것보다 훨씬 능률적이고 생산적이다.
 
 
 
끝으로 부팅 시 모두 동작하도록 실행한다.
 
systemctl enable httpd
systemctl enable mysqld