LAMP (Linux, Apache, MySQL(MariaDB), PHP)
WAMP (Windows, Apache, MySQL, PHP)
Apache => NginX, NodeJS 웹서버 사용 증가 (빠른 속도)
MEAN Stack
웹개발을 위한 프로그램 세트 중의 하나로 Mongo DB, Express JS, Angular JS, Node JS 로 구성되어 있음
Apache Web Server
apache2.conf (/etc/apache2)
- 핵심 구성 파일로서 필요한 파일이 어느 곳에 있어야 한다든가, 그런 파일을 어떻게 로드 해야 하는지
정의해 놓은 파일
/var/www/html/index.html ==> 웹브라우저 메인화면
Apache에 인증 암호 설정하는 방법
원하는 디렉터리에 가서 .htpasswd 파일 생성하면 됨
Apache Web Server에서 .htaccess 파일 설정하는 방법
.htaccess 파일
.htaccess는 Apache web server에 대한 configuration 파일
.htaccess 를 Enable 시키는 방법
주 Configuration 파일 편집
관리자가 해야 할 작업 : apache2.comf 파일 설정
==> document root를 유지하는 /var/www 디렉토리에 대한 <Directory> 블록을 찾아서, 블록내 “AllowOverride” 지시어(directive)를 “None”에서 “All”로 바꾸어 .htaccess를 ON시킴
Directory Listings을 제한하도록 하는 설정
당신의 web sites를 방문한 사람은 디렉토리 구조와 파일 구조를 볼 수 있으며, 웹 서버의 파일에 대한 접근 권한을 가짐
directory access를 제한하는 한가지 방안은 .htaccess을 통해 수행
.htaccess : Options -Indexes(-옵션 : 기능제거)
==> 사용자 web sites에서 다른 폴더로 이동하고자 할 경우 “Forbidden" 메시지 출력
특정 IP를 제한 혹은 허용하는 방안
<특정 IP를 차단하는 방법>
.htaccess :
order allow,deny =>순서 중요
deny from xxx.xxx.xxx.xxx
<특정 IP만 접근을 허용하는 방법>
모든 IP를 접근 금지 후, 특정 IP 혹은 IP의 영역을 허용하는 방식
.htaccess :
order deny,allow =>순서 중요
deny from all
allow from xxx.xxx.xxx.xxx
Handle Redirects
.htaccess 파일을 사용하여 traffic을 redirect 가능
‘Redirect’ 명령 뒤에 오는 첫 번째 인자는 HTTP status code 임
.htaccess :
Redirect 301 /index.html /test1/index.html
404 Error Page를 설정
.htaccess 파일을 설정하여 방문자가 존재하지 않는 page를 접근하고자 할 경우, error page가 표시되도록 설정 가능
.htaccess :
ErrorDocument 404 /404.html
MariaDB 생략
PHP
Backend(서버용) 프로그램
<특징>
1. 인터프리터형 언어
- 소스 프로그램을 실행하기 전에 기계어로 변환시킬 필요 없이 바로 실행되는 언어
2. 서버 사이드 스크립트
- 프로그램이 HTML 파일 내부에 포함되거나 독립적인 파일로 존재
3. 데이터베이스와 연계
4. 오픈 소스
5. PHP 프로그램의 테스트는 웹서버가 설치된 곳에서만 가능
6. 소문자와 대문자를 구별함
7. PHP 문은 모두 세미콜론으로 끝남
HTML은 정적인 페이지만 제공 => 초기에 CGI(Common gateway Interface)를 쓰다가
PHP는 웹 페이지에 동적 기능을 불어 넣기 위한 시스템
Javascript
<script type="text/javascript">
document.write("Hello World")
</script>
//그냥 메인화면 출력
<script type="text/javascript">
function sayHello() {
alert("Hello World")
}
</script>
<input type="button" onclick="sayHello()" value="Say Hello" />
//함수불러서 팝업창 불러오는거
자동갱신
<head>
<meta http-equiv="refresh" content="60" />
</head> // 자동갱신
<head>
<meta http-equiv="refresh" content="60;url=___________" />
</head> // 자동갱신 후 특정url로 이동
DHT 11용 Sensor Monitoring System 구현
Linux에서 Python3.x로 “TESTDB”에 연결하는 예
import pymysql
# Open database connection
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
# prepare a cursor object using cursor() method
cursor = db.cursor()
# execute SQL query using execute() method.
cursor.execute("SELECT VERSION()")
# Fetch a single row using fetchone() method.
data = cursor.fetchone()
print ("Database version : %s " % data)
# disconnect from server
db.close()
import RPi.GPIO as GPIO
import dht11
# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
# read data using pin 23
instance = dht11.DHT11(pin = 23)
result = instance.read()
if result.is_valid():
print("Temperature: %-3.1f C" % result.temperature)
print("Humidity: %-3.1f %%" % result.humidity)
else:
print("Error: %d" % result.error_code)
Crontab으로 특정 시간마다 예약 실행 설정
$ crontab -e
편집으로 들어가서
*/1 * * * * python.py
==> 1분 마다 python.py 자동으로 실행
'수업정리 > 임베디드 시스템' 카테고리의 다른 글
인공지능과 머신 러닝(machine learning) (0) | 2020.12.09 |
---|---|
라즈베리파이 OpenCV (0) | 2020.12.09 |
라즈베리파이 GPIO 디지털 입출력(Python) (0) | 2020.12.09 |
단위 표시 (0) | 2020.12.09 |
Docker를 이용하여 NginX 웹 서버 작동 (0) | 2020.09.18 |