'lamp'에 해당되는 글 1건

  1. 2014.08.23 LAMP (Linux Based Apache, MariaDB, PHP) Install


OS : Centos 7


1. Install Apache on a CentOS 7

: 아파치 서버를 설치한다.

# yum install httpd

output : 

Loaded plugins: amazon-id, rhui-lb

Resolving Dependencies

--> Running transaction check

---> Package httpd.x86_64 0:2.4.6-17.el7 will be installed

--> Processing Dependency: httpd-tools = 2.4.6-17.el7 for package: httpd-2.4.6-17.el7.x86_64

--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.x86_64

--> Running transaction check

---> Package httpd-tools.x86_64 0:2.4.6-17.el7 will be installed

---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed

--> Finished Dependency Resolution

 

Dependencies Resolved

 

======================================================================================================

 Package            Arch          Version               Repository                               Size

======================================================================================================

Installing:

 httpd              x86_64        2.4.6-17.el7          rhui-REGION-rhel-server-releases        1.2 M

Installing for dependencies:

 httpd-tools        x86_64        2.4.6-17.el7          rhui-REGION-rhel-server-releases         77 k

 mailcap            noarch        2.1.41-2.el7          rhui-REGION-rhel-server-releases         31 k

 

Transaction Summary

======================================================================================================

Install  1 Package (+2 Dependent packages)

 

Total download size: 1.3 M

Installed size: 3.9 M

Is this ok [y/d/N]: y

Downloading packages:

(1/3): httpd-tools-2.4.6-17.el7.x86_64.rpm                                     |  77 kB  00:00:00

(2/3): httpd-2.4.6-17.el7.x86_64.rpm                                           | 1.2 MB  00:00:00

(3/3): mailcap-2.1.41-2.el7.noarch.rpm                                         |  31 kB  00:00:00

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

Total                                                                 2.0 MB/s | 1.3 MB  00:00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : httpd-tools-2.4.6-17.el7.x86_64                                                    1/3

  Installing : mailcap-2.1.41-2.el7.noarch                                                        2/3

  Installing : httpd-2.4.6-17.el7.x86_64                                                          3/3

  Verifying  : mailcap-2.1.41-2.el7.noarch                                                        1/3

  Verifying  : httpd-tools-2.4.6-17.el7.x86_64                                                    2/3

  Verifying  : httpd-2.4.6-17.el7.x86_64                                                          3/3

 

Installed:

  httpd.x86_64 0:2.4.6-17.el7

 

Dependency Installed:

  httpd-tools.x86_64 0:2.4.6-17.el7                   mailcap.noarch 0:2.1.41-2.el7

 

Complete!


: httpd 서비스를 활성화 및 부팅시에 자동적으로 활성화가 되도록 한다.

# systemctl enable httpd.service

output : 

ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'


# systemctl disable httpd.service 

- disable 명령을 하면 httpd 서비스가 중단되고 부팅하여도 활성화되지 않는다.


: httpd service 실행

# systemctl start httpd.service 

ex) systemctl {start | stop | restart } httpd.service - 시작, 중지, 재시작 명령

ex) systemctl is-active httpd.service - httpd 서버의 상태 확인 명령

apache server가 잘 동작하는지 확인하려면 127.0.0.1을 쳐봐서 확인할 수 있다.



: Gracefully 재시작

# apachectl graceful


: Test httpd/apache configuration file for errors on a centos

# apachectl configtest

- 아파치 서버의 설정파일 테스트인데 "syntax ok"가 나와서 정상이다.

하지만 아마도 처음 이것을 실행하면 서버네임 어쩌고저쩌고 에러가 나올 수 있다. 나중에 설정할 것이지만 미리 말하면 /etc/httpd/conf/httpd.conf  에서...

ServerName 127.0.0.1:80 으로 편집하면 에러가 나지 않을 것이다.


: httpd service default configuration

1. Default config file : /etc/httpd/conf/httpd.conf

2. configuration files which load modules : /etc/httpd/conf.modules.d/directory(e.g PHP)

3. Seelct MPMs (processing model) as loadable modules [worker, prefork(default)] and event:

/etc/httpd/conf.modules.d/00-mpm.conf

4. Default ports : 80 and 443(SSL)

5. Default log files : /var/log/httpd/}access_log, error_log}


***************************************************************************************************************

***************************************************************************************************************


2. MariaDB Install

: mariadb를 설치한다.

# yum install mariadb-server mariadb


: mariadb start

# systemctl start mariadb.service

이 명령을 실행 시켰을 때, error가 발생한다면... 제대로 설치가 되지 않은 것이다.

/var/lib/mysql 디렉토리를 지우고 다시 만든다. mkdir /var/lib/mysql

그런 다음, 

yum install mariadb mariadb-server

다시 한번 이 명령을 실행시키면 된다.



: 컴퓨터 켤 때 자동 실행

# systemctl enable mariadb.service

output :

ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service


ex)

sudo systemctl stop mariadb.service #<-- Stop mariadb server

sudo systemctl restart mariadb.service #<-- Restart mariadb server

sudo systemctl disable mariadb.service #<-- Disable mariadb server

sudo systemctl is-active mariadb.service   #<-- Is mariadb server running?


: Securing MariaDB

# /usr/bin/mysql_secure_installation

output :

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): PRESS-ENTER-KEY

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: YOUR-NEW-PASSWORD-HERE

Re-enter new password: YOUR-NEW-PASSWORD-HERE

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!


:: 잘 설치되었는지 확인

# mysql -u root -p

위의 명령을 입력하여 비밀번호를 치고 들어가면 성공.


: mariaDB 가 잘 동작하는 지 확인

vi /var/www/html/db.php

 code :

<?php

mysql_connect("", "", "");

echo "db 작동 완료!!";

?>

이렇게 해서 "db 작동 완료" 라는 문구가 나오면 서로 잘 연동 된 것이다.


3. PHP Install

: php 설치

# yum install php php-mysql php-gd php-pear


: httpd 재시작

# systemctl restart httpd.service


:  모듈 설치

# yum install php-pgsql


: php가 잘 설치되었는지 확인

vi /var/www/html/test.php

code : 

<?php

phpinfo();

?>

파일을 저장하고 웹브라우저에서 127.0.0.1/text.php 를 입력하면 아래의 사진과 같은 결과물이 나오면 잘 설치가 된 것이다.




====================================================================================================


Configure Settings


:: 방화벽 설정

\

3306 포트는 mariadbServer에서 mysql를 열기위함이다. mysql 기본 포트가 3306인 것 같다.


방화벽 서비스 재시작



/etc/httpd/conf/httpd.conf

: apache가 php를 인식하도록 설정



/etc/httpd/conf.d/php.conf

:: AddType 추가


:: DirectoryIndex 추가



/etc/php.ini

upload_max_filesize = 100M

default_socket_timeout = 3000

max_execution_time = 30     ; Maximum execution time of each script, in seconds

max_input_time = 60     ; Maximum amount of time each script may spend parsing request data

memory_limit = 128M      ; Maximum amount of memory a script may consume

short_open_tag = On // XE 가  제대로 작동 안될때 사용.

 upload_tmp_dir = /tmp

upload_max_filesize = 100M

default_charset = "UTF-8"

mbstring.internal_encoding = UTF-8


# php.ini 에서 사용 금지할 명령어 추가

disable_functions = exec, shell



/etc/my.cnf

php에서 한글을 출력해 내는 것은 잘 되는데, MariaDB에서 DB 쿼리를 해서 한글을 출력시에는 전부 ?? 로 표시되는 문제가 발생했다.

인터넷상에서 알려진 PHP와 UTF-8의 설정법을 전부 적용해봤는데도 안되었는데, 최종적으로 /etc/my.cnf 에 [mysqld] 항목에서 skip-character-set-client-handshake 를 추가해주니깐 겨우 한글이 출력되기 시작했다. 클라이언트의 설정을 무시하고 서버쪽 설정에 따르도록 한다는 것 같다.

다른 부분을 전부 설정했음에도 저걸 안해주면 안되는 이유가 소스 설치를 했으면 모르겠는데, 내 경우는 yum 을 이용해서 설치했으며, yum 을 이용해서 설치하면 다른곳이 전부 utf8이라도 DB가 접속시 latin을 사용한다는 얘기가 있다. 따라서 꼭 skip-character-set-client-handshake 를 해준다.

이외에 기본적으로 CentOS 6.4에서 PHP와 MariaDB(MySQL)의 utf-8 입출력을 위한 설정을 남겨본다.

물론 기본적으로 php 파일은 utf-8 로 인코딩 되어 있어야 함.

1. DB 생성시 utf8_general_ci 로 생성.

2. /etc/my.cnf 파일 수정

※ 참고로 my.cnf 설정 잘못하면 my.cnf 설정 변경후 서비스 재시작시에 에러나서 실행이 안될수도 있다. 이 경우엔 설정을 하나씩 지우던가 해서 맞지 않는 설정을 제외시킨다.


[client]

default-character-set=utf8


[mysqld]

init_connect="SET collation_connection=utf8_general_ci"

init_connect="SET NAMES utf8"

character-set-server=utf8

collation-server=utf8_general_ci

skip-character-set-client-handshake


[mysql]

default-character-set=utf8

#

# This group is read both both by the client and the server

# use it for options that affect everything

#

[client-server]

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d


위와같이 my.cnf 를 바꿔준후 서비스를 재시작해주고 mysql 콘솔로 접속해서 show variables like 'c%'; 명령어를 이용해서 정상적으로 db가 utf8로 설정되어 있는지 확인한다.


:: /etc/php.ini 수정

default_charset = "utf-8"

mbstring.internal_encoding=UTF-8


일단 내가 설정한 부분은 여기까지 였으며 정확하게 utf-8이 동작한다. 내 경우에 핵심은 /etc/my.cnf 에 skip-character-set-client-handshake 추가를 해준후에 동작했다는 점. 



참고 페이지 : 

http://blog.keypointer.co.kr/?p=53

http://www.cyberciti.biz/faq/howto-install-linux-apache-mariadb-php-lamp-stack-on-centos7-rhel7/

http://www.if-not-true-then-false.com/2013/install-mariadb-on-fedora-centos-rhel/

http://www.nextstep.co.kr/250



'Programming > etc' 카테고리의 다른 글

Linux PHPStrom 설정  (0) 2014.09.06
Installing Xdebug on CentOS  (0) 2014.09.06
Python 학습 관련 자료 및 문서, WebSite  (0) 2014.03.25
Python PySide 설치  (1) 2013.03.07
윈도우환경을 리눅스환경처럼  (0) 2013.02.19
Posted by scii
: