얕고넓은지식/linux

rocky linux 웹 서버설치 한방에 따라하기

쪽마 2021. 12. 17. 14:49
반응형

시작전에 업데이트부터해준다

0. [root@localhost ~]# dnf update -y

 

1. 아파치설치

[root@localhost ~]# dnf install httpd -y

2. db설치

[root@localhost ~]# dnf module list mysql
Rocky Linux 8 - AppStream
Name           Stream           Profiles                    Summary
mysql          8.0 [d]          client, server [d]          MySQL Module

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@localhost ~]# dnf install @mysql -y

3. php 설치

[root@localhost ~]# dnf install php -y

4. php 버전확인

[root@localhost ~]# dnf module list php

 

5. php 7.4 사용으로 변경하기 (7.4가 아닐경우)

5-1 : [root@localhost ~]# dnf remove php -y             php 제거
5-2 : [root@localhost ~]# dnf module reset php -y             php 리셋
5-3 : [root@localhost ~]# dnf module enable php:7.4 -y             php 7.4 활성화
5-4 : [root@localhost ~]# dnf install php -y             php 재설치
5-5 : [root@localhost ~]# dnf module list php             php 재확인

 

6. 설치내역 확인

[root@localhost ~]# httpd -v
Server version: Apache/2.4.37 (rocky)
Server built:   Nov 15 2021 03:12:26
[root@localhost ~]# php -v
PHP 7.4.19 (cli) (built: May  4 2021 11:06:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.19, Copyright (c), by Zend Technologies
[root@localhost ~]# mysql -V
mysql  Ver 8.0.26 for Linux on x86_64 (Source distribution)
※ mysql 버전확인할때 옵션은 V 대문자로 해야한다

 

7. 방화벽 적용

[root@localhost ~]# firewall-cmd --permanent --add-port=80/tcp
success
[root@localhost ~]# firewall-cmd --permanent --add-port=443/tcp
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp5s0
  sources:
  services: cockpit dhcpv6-client ssh
  ports: 80/tcp 443/tcp
  protocols:
  forward: no
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

7-1 : 아파치 재구동 
[root@localhost ~]# systemctl start httpd
7-2 : 재부팅시 아파치 자동실행
[root@localhost ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

 

8. httpd 아파치 설정파일 수정

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf

※ 앞숫자는 라인

    167 <IfModule dir_module>
    168     DirectoryIndex index.html index.htm index.php       붉은색글씨 추가
    169 </IfModule>

    287     AddType application/x-compress .Z
    288     AddType application/x-gzip .gz .tgz
    289     AddType application/x-httpd-php .php       붉은색글씨 추가
    290     AddType application/x-httpd-phps .phps       붉은색글씨 추가

 

 

 

여기까지만 따라해도

아래와같은 화면을 볼수있다

 

9. db구동

[root@localhost ~]# systemctl start mysqld

재부팅 시 자동 시작 활성화

[root@localhost ~]# systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

9-1 : nysql db 비번설정

[root@localhost ~]# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component?

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

비밀번호 정책 선택
0 : 길이 8 이하
1 : 길이 8 이하, 숫자, 대/소문자 혼합, 특수 문자 사용
2 : 길이 8 이하, 숫자, 대/소문자 혼합, 특수 문자, dictionary 파일 사용



Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2    원하는 정책 입력
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100      100나오면 비번 강력하다 뭐 그런거임..
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.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n   원격 루트 접속허용 안할꺼지?...만..난할꺼니까...n

 ... skipping.
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!

 

 

9-2 : db 접속해보자
[root@localhost ~]# mysql -u root -p

Enter password:    위에서 지정한 비번 넣어준다
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.26 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

 

 

나가기전에 버전확인한번

mysql> SELECT VERSION ();
+------------+
| VERSION () |
+------------+
| 8.0.26     |
+------------+
1 row in set (0.00 sec)

 

10. 가상호스트 설정

테스트 폴더만들어준다

[root@localhost ~]# mkdir /var/www/test

[root@localhost ~]# vi /var/www/test/index.php

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'?> 
 </body>
</html>

[root@localhost ~]# vi /etc/httpd/conf.d/vhost.conf

<VirtualHost *:80>
    ServerName www.zzokma.tistory.com
    ServerAlias zzokma.tistory.com
    DocumentRoot /var/www/test

    <Directory /var/www/test>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog /var/log/httpd/zzokma.tistory.info-error.log
    CustomLog /var/log/httpd/zzokma.tistory-access.log combined
</VirtualHost>

 

요기까지 입력했다면...

아래와같은 화면이뜬다

 

 

자..요기까지 왔다면..

이제 가상호스트까지 설정이 완료했다

사용하는 dns에서 설정해주어서

가상호스트에서 설정한 도메인으로 접속시에...

설정한 폴더로 쏴줄것이다.

 

 

 

 

추가 : php 세팅

[root@localhost ~]# nano /etc/php.ini

short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo =0
upload_max_filesize = 100M
post_max_size = 100M
max_execution_time = 360
date.timezone = Asia/Seoul

위 내용들 찾아서 바꿔주기~

찾는 방법은 컨트롤 + W 누르면 밑에 검색창이 나오는데, 앞부분을 복사해서 붙여넣고 엔터를 치면 찾아집니다.

예를들어 short_open_tag를 바꾸고 싶다면 short_open_tag 를 넣고 엔터를 치면 해당부분으로 갑니다.

참고로 short_open_tag는 처음 검색하면 설명 부분이 나오는데 한번더 검색하면 제대로 나옵니다.

cgi.fix_pathinfo는 아마도 ;cgi.fix_pathinfo = 1 이렇게 되어있을텐데요. 앞에 ; 은 주석으로 처리한다는 뜻이므로 이것도 빼야겠죠.

즉 ;cgi.fix_pathinfo = 1 을 cgi.fix_pathinfo = 0  이렇게 바꿔줘야 하는 것입니다.

그 뒤에 수정하면 됩니다.

참고로 upload_max_filesize와 post_max_size는 파일 업로드 용량과 매우 높은 관계가 있습니다.

업로드할 파일 크기가 크다면 100M 이상으로 해주셔도 됩니다.

그리고 밑에 Nginx 설정에서도 하나 더 변경해줘야 됩니다. 따로 설명드리겠습니다.

전부 찾아서 다 바꾼 후

컨트롤 + O, 엔터, 컨트롤 + X를 누르면 저장 후 빠져나와집니다.

 

 

 

그리고...추가로 아래것도 수정해준다

127번라인    httpd.conf

#<Directory "/var/www/html">
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>


134번라인

#<Directory "/var/www/html">
<Directory "/var/www">

 

 

 

끝으로....

서버 재부팅 혹은

서비스 재실행을 해주자

 


[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart php-fpm.service
[root@localhost ~]# systemctl restart mysqld.service

 

 

반응형