웹서버 메뉴얼/기본설정

Linux Apache and PHP 설치 및 설정하기

IT박스 2023. 5. 20. 10:56
HTTP daemon 설치하기

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

HTTP daemon 시작하기

[root@localhost ~]# systemctl start httpd
리눅스 방화벽 설치하기

[root@localhost ~]# yum -y install iptables-*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * extras: mirror.navercorp.com
 * updates: mirror.kakao.com
Package iptables-1.4.21-35.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package iptables-devel.x86_64 0:1.4.21-35.el7 will be installed
---> Package iptables-services.x86_64 0:1.4.21-35.el7 will be installed
---> Package iptables-utils.x86_64 0:1.4.21-35.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                  Arch          Version               Repository   Size
================================================================================
Installing:
 iptables-devel           x86_64        1.4.21-35.el7         base         57 k
 iptables-services        x86_64        1.4.21-35.el7         base         52 k
 iptables-utils           x86_64        1.4.21-35.el7         base         62 k

Transaction Summary
================================================================================
Install  3 Packages

Total download size: 171 k
Installed size: 99 k
Downloading packages:
--------------------------------------------------------------------------------
Total                                              693 kB/s | 171 kB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : iptables-utils-1.4.21-35.el7.x86_64                          1/3 
  Installing : iptables-services-1.4.21-35.el7.x86_64                       2/3 
  Installing : iptables-devel-1.4.21-35.el7.x86_64                          3/3 
  Verifying  : iptables-devel-1.4.21-35.el7.x86_64                          1/3 
  Verifying  : iptables-services-1.4.21-35.el7.x86_64                       2/3 
  Verifying  : iptables-utils-1.4.21-35.el7.x86_64                          3/3 

Installed:
  iptables-devel.x86_64 0:1.4.21-35.el7                                         
  iptables-services.x86_64 0:1.4.21-35.el7                                      
  iptables-utils.x86_64 0:1.4.21-35.el7                                         

Complete!
리눅스 방화벽 설정하기

[root@localhost ~]# vi /etc/sysconfig/iptables
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
방화벽 재실행하기
[root@localhost ~]# systemctl restart iptables
IP주소 확인하기
[root@localhost ~]# ip addr

link/ether 00:0c:29:a3:8a:1c brd ff:ff:ff:ff:ff:ff
inet 192.168.88.129/24 brd 192.168.88.255 scope global noprefixroute dynamic ens33 valid_lft 1655sec preferred_lft 1655sec
inet6 fe80::8a1e:1133:f101:b076/64 scope link noprefixroute valid_lft forever preferred_lft forever
크롬브라우저에 리눅스서버 IP를 넣어서 정상적으로 웹서버가 되는지 결과를 확인한다.
http://192.168.88.129

 

결과가 만약에 정상적인 페이지가 나오지 않을때의 해결법

[1]PHP 설치가 제대로 되어 있지 않음

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

[2]<? ?>를 인식하지 않음

두번째 것은 php.ini를 수정해야 합니다. short_open_tag를 활성화 시키셔야 합니다.

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

short_open_tag = On;

만일 PHP가 설치 되어 있는데 위의 코드가 실행되지 않는다면 간단히 다음과 같은 소스로 테스트 해보겠다.

<?php echo "Testing<br/>"; ?>