2015년 8월 24일 월요일

NGINX1.8.0 설치 PHP, MARIADB, WORDPRESS [Centos7.1503 Minimal]

NGINX 설치 (PHP MARIADB WORDPRESS)
1. 새로운 root 계정 만들기와 권한 설정
adduser root_New_ID
passwd root_New_ID
visudo 
   root_New_ID       ALL=(ALL)       ALL

   :wq


gpasswd -a root_New_ID wheel


2.0 NGINX 최신 Stable Version 다운로드 설치(2.1 방법 추천)
curl -LO 주소  //다운로드

rpm -Uvh "Saving name" //설치

2.1 위의 방법은 Update시 불편하므로 repository를 작성하여 설치한다.

su root  //아래 명령이 안되면 root 계정으로 접속해서 타이핑 할것!

vi /etc/yum.repos.d/nginx.repo //이명령을 실행하여 아래 타이핑 할것!!
  [nginx]
  name=nginx repo
  gpgcheck=0
  enabled=1
:wq

참고
centos : 이자리에 운영체제 이름이 들어가면 됨. windows 또는 linux
7 : 이 숫자는 운영체제 버전으로 뒤에 소수점은 버리고 첫자리만 넣으면 됨.

3. NGINX 설치
sudo yum install nginx

4. php패키지, 데이타베이스 , unzip 설치
sudo yum install php-fpm php-mysql mariadb-server unzip

5. NGINX 설정 (붉은색 부분 수정 할 것)
sudo vi /etc/nginx/conf.d/default.conf
server_name localhost;
root /usr/share/nginx/html;

index index.html index.htm index.php; //바깥으로 빼주고 굵은 글씨 추가
location  / {
try_ files $uri $uri/ /index.php$is_args$args; //다른 부분 수정
}

//아래 부분 주석 모두 제거 

location ~ \.php$ {
//root html; //지우거나 주석처리 할것
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param   SCRIPT_FILENAME $request_filename; //굵은 글씨로 변경
include fastcgi_params;
}

5.1 NGINX Server Blocks (아파치의 VirtualHost 같은 개념) 설정

http://wiki.nginx.org/ServerBlockExample

6. php-fpm 설정
sudo vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx

참고 : 여기에서 nginx user는 웹서버를 구동하기 위한 시스템 유저이지 1번에서 만드는root user와는 관계가 없음. 즉 nginx라는 프로그램의 유저이다.

7. 서비스 실행
sudo systemctl start nginx mariadb php-fpm

8. 부팅시 자동으로 실행 시키기
sudo systemctl enable nginx mariadb php-fpm

8.1 방화벽 80포트 개방
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload

9. web 폴더에 파일 기존 파일 지우기
cd /usr/share/nginx/html/
ll

sudo  rm 50x.html index.html

10. 워드프레스 설치
sudo unzip latest.zip
sudo mv wordpress/* .
sudo rmdir wordpress/
sudo rm latest.zip
ll
 참고 : 현재 폴더에 모든 파일 지우기 rm -rf *

11. root계정 nginx 계정으로 변경(워드프레스가 설치된 html 디렉토리에서)
sudo chown nginx.nginx -R .
ll        //사용자가 nginx로 바뀐것을 볼수 있음

12. mysql 보안 설정
mysql_secure_installation
처음 root  비번 없으면 그냥 enter
Set root password? y
New password: 비번 넣고
Re-enter new password: 위와 같이 비번 넣기

Remove anonymous users? y
....잘 읽어 보고 yes, 만약 외부에서 관리 하려면 no!!!

13. MaridDB 데이타베이스 생성과 Database 사용자 권한 설정
mysql -u root -p
create database wordpress;
grant all privileges on wordpress.* to username@localhost identified by 'password설정';
flush privileges;
exit

참고 : username과 password는15번에 사용되며 잘 기억 해둘것!

14. MariaDB 한글 설정
vi /etc/my.cnf.d/server.cnf
   [mariadb-5.5]
   character_set_server = utf8      //이라인을 추가해 준다.
:wq

systemctl restart mariadb          //서비스 다시 시작해 준다.

확인 : mysql -u root -p
show variables like 'c%';

15. 웹사이트에서 NGINX로 접속
User Name : 위에서 입력한 username
password : 위에서 설정한 password
submit 누르기(db connect error 발생시 16번)

16. 워드프레스 데이터 접속 파일 설정
cd /usr/share/nginx/html/
sudo  cp wp-config-sample.php wp-config.php
sudo vi wp-config.php

define('DB_NAME', 'wordpress'); 
define('DB_USER', 'username'); 
define('DB_PASSWORD', '비번);

참고 : 13번에서 만든 database, username, 비번을 굵은 글씨 부분에 순서대로 넣을 것.

17. 워드프레스 Run the Install
Site Title : 제목 입력
Username : 
Password : 
E-mail
Install Wordpress

18. WordPress 로그인

19. 테마변경

20. 참고 MariaDB root 패스워드 변경
update 테이블명 set 컬럼명=password('123') where 컬럼명 = 'root';
flush privileges;

21. User 정리

* root user : centos라는 시스템 자원을 관리하기 위한 최상위 유저이다.

* nginx 라는 user와 group :
 - 이것은 nginx를 설치하면 자동으로 생성되며 시스템에서 서비스를 구동하기 위한 유저임
root 유저이름으로 nginx를 사용하여도 상관없지만 혼동이 생기므로 다른 이름으로 할것. 참고로 root유저의 group은 nginx가 아니다.

* mysql의 root users는 1번에서 root유저를 접속 못하게 하여도 프로그램이 시스템 자원을 사용하기 위한 root 유저는 구동이 된다.

* database user : 13번에서 wordpress DB에 유저를 생성했는데 이것은 DB를 사용하기 위한 유저이지 위에 user들과는 상관이 없다.




잘 안되거나 궁금증이 있다면 olleyo76@gmail.com으로 연락 주시길 바랍니다.

댓글 없음:

댓글 쓰기