본문 바로가기
리눅스와 웹개발

PHP 프로그래밍을 위한 서버구축과 환경 설정 방법 정리

by kuksool 2023. 11. 27.
728x90
반응형

사진 설명을 입력하세요.
일단 php를 서버에 설치할 의도라면 웹서비스를 의도한 것이라고 보고 DB까지 설치하는걸 전제로 하겠습니다.
제가 아는 방법으로 저희 서버를 세팅할 때 하는 방법으로 작성하겠습니다.
일단 APM파일은 다 다운받아놓습니다.

1. 리눅스 설치
2. Mysql 설치
3. Proftpd 설치
4. 아파치 설치
5. PHP 설치


1. 리눅스 설치

리눅스는 사용자설치로 설치하고 APM은 소스로 설치할 것이므로 기타 서버는 설치하지 않고, 기본적인 옵션들만 설치

2. Mysql 설치

2-1. mysql그룹과 유저등록
shell> groupadd mysql
shell> useradd -g mysql mysql

2-2. mysql 압축풀기(MySQL5.0.17기준)
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
shell> cd mysql-VERSION

2-3. mysql 설치
shell> ./configure --prefix=/usr/local/mysql --with-charset=euckr --with-mysqld-user=mysql --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --localstatedir=/usr/local/mysql/var --with-extra-charsets=none
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.출

2-4. mysql 설정
shell> cd /usr/local/mysql
shell> bin/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql var
shell> chgrp -R mysql .
shell> bin/mysqld_safe --user=mysql &

사용계정/암호(1) : root/123456
사용계정/암호(2) : xxx/xxx_1234

2-5. 데이터베이스 로그인(root)
mysql -u root -p123456;

2-6. 데이터베이스 생성
create database xxx;

2-7. 데이터베이스 선택
use mysql;

2-8. 데이터베이스 유저생성
Insert into user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,Super_priv,Create_tmp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Create_user_priv,ssl_cipher,x509_issuer,x509_subject)
values('%', 'xxx', password('xxx_1234'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y', 'Y','Y','Y','Y', 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','');

insert into user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,Super_priv,Create_tmp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Create_user_priv,ssl_cipher,x509_issuer,x509_subject)
values('localhost', 'xxx', password('xxx_1234'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y', 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','');

insert into user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,Super_priv,Create_tmp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Create_user_priv,ssl_cipher,x509_issuer,x509_subject)
values('localhost.localdomain','xxx',password('xxx_1234'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','');


2-9. 새로 생성한 데이터베이스 등록하기
insert into db (Host, Db, User,Select_priv,Insert_priv, Update_priv, Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv, Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv, Create_routine_priv,Alter_routine_priv,Execute_priv)
values('%','mysql','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv, Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Execute_priv)
values('%','xxx','xxx','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Execute_priv)
values('localhost','xxx','xxx','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

2-10. 접근가능 호스트 등록
insert into host (Host,Db,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Execute_priv)
values('localhost','mysql','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

insert into host (Host,Db,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Execute_priv)
values('localhost','xxx','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

insert into host (Host,Db,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Execute_priv)
values('%','xxx','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');


2-11. 데이터베이스 재기동
mysqladmin -u root -p reload

2-12. 새로운 유저로 다시 로그인(xxx)
mysql -u xxx -pxxx_1234 --local-infile=1;

use xxx;

2-13. DB 접속후(한글깨짐방지)
set names euckr;
flush privileges;

한글깨지는 문제 관련하여 셋팅

1). /etc/php.ini 캐릭터셋 변경
default_charset = "euc-kr"

2). /etc/my.cnf 파일의 아래 각 항목에 추가/변경
[client]
default-character-set = utf8

[mysqld]
default-character-set = euckr
init_connect = SET collation_connection = euckr-korean_ci
init_connect = SET NAMES euckr
character-set-server = euckr
collation-server = euckr_korean_ci

[mysqldump]
default-character-set = euckr

[mysql]
default-character-set = euckr

3). /etc/httpd/httpd.conf

AddDefaultCharset EUC-KR

4). 웹소스 캐릭터셋

<META http-equiv="Content-Type" content="text/html; charset=euc-kr" />

3. Proftpd 설치

./configure -prefix=/usr/local/proftpd -enable-autoshadow
make
make install

cp /usr/local/proftpd/sbin/proftpd /etc/rc.d/init.d/
vi /usr/local/proftpd/etc/proftpd.conf -> user -> root
group -> nobody

4. Apache 설치

./configure --prefix=/usr/local/apache --enable-rule=SHARED_CORE --enable-module=so --enable-shared=max
make
make install

4-1. 설정 변경

설치경로 변경
DocumentRoot "/home/kuksool"

Html과 php확장자 사용할수있게 변경
AddType application/x-httpd-php .php .html .inc
AddType application/x-httpd-php-source .phps
AddType application/x-tar .tgz

5. PHP 설치

./configure --with-apxs=/usr/local/apache/bin/apxs --with-language=korean --with-charset=euc_kr --with-config-file-path=/usr/local/apache/conf --with-exec-dir=/usr/local/apache/bin --with-enable-track-vars=yes --with-enable-socket --with-enable-modules=so --enable-sigchild --disable-debug --with-enable-ftp --with-mysql=/usr/local/mysql

make

make install

5-1. PHP환경 설정
cp php.ini-dist /usr/local/apache/conf/php.ini
cp php.ini-dist /usr/local/lib/php.ini
register_globals = On
expose_php = Off
output_buffering=On

보통 웹서버 APM설치는 이정도로 합니다.
나머지 보안세팅등은 생략하였습니다.


If you intend to install the php on the server, we will consider that the web service was intended and install the DB.
I will write it in the way I know how to set up our server.
First, download all APM files.

1. Linux installation
2. Installing Mysql
3. Installing Proftpd
4. Apache Installation
5. PHP Installation

1. Linux installation

Linux will be installed as a user installation and APM will be installed as a source, so install only basic options, not other servers

2. Installing Mysql

2-1. Mysql group and user registration
shell> groupadd mysql
shell> useradd -g mysql mysql

2-2. Mysql compressor (based on MySQL 5.0.17)
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
shell> cd mysql-VERSION

2-3. Installing mysql
shell> ./configure --prefix=/usr/local/mysql --with-charset=euckr --with-mysqld-user=mysql --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --localstatedir=/usr/local/mysql/var --with-extra-charsets=none
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.출

2-4. setting mysql
shell> cd /usr/local/mysql
shell> bin/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql var
shell> chgrp -R mysql .
shell> bin/mysqld_safe --user=mysql &

Used account/password (1): root/123456
Account/password (2): xxx/xxx_1234

2-5. Database login (root)
mysql -u root -p123456;

2-6. Create a database
create database xxx;

2-7. Select a database
use mysql;

2-8. Create database users
Insert into user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,Super_priv,Create_tmp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Create_user_priv,ssl_cipher,x509_issuer,x509_subject)
values('%', 'xxx', password('xxx_1234'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y', 'Y','Y','Y','Y', 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','');

insert into user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,Super_priv,Create_tmp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Create_user_priv,ssl_cipher,x509_issuer,x509_subject)
values('localhost', 'xxx', password('xxx_1234'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y', 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','');

insert into user (Host, User, Password, Select_priv, Insert_priv, Update_priv, Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,Super_priv,Create_tmp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Create_user_priv,ssl_cipher,x509_issuer,x509_subject)
values('localhost.localdomain','xxx',password('xxx_1234'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','');

2-9. Registering newly created databases
insert into db (Host, Db, User,Select_priv,Insert_priv, Update_priv, Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv, Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv, Create_routine_priv,Alter_routine_priv,Execute_priv)
values('%','mysql','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv, Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Execute_priv)
values('%','xxx','xxx','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

insert into db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Execute_priv)
values('localhost','xxx','xxx','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

반응형


2-10. Registering Accessible Hosts
insert into host (Host,Db,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Execute_priv)
values('localhost','mysql','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

insert into host (Host,Db,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Execute_priv)
values('localhost','xxx','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

insert into host (Host,Db,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Execute_priv)
values('%','xxx','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

2-11. Restarting the Database
mysqladmin -u root -p reload

2-12. Log in again as a new user (xxx)
mysql -u xxx -pxxx_1234 --local-infile=1;

use xxx;

2-13. After accessing DB (preventing break in Korean)
set names euckr;
flush privileges;

Setting about the problem of breaking Hangul

1). Change /etc/php.ini character set
default_charset = "euc-kr"

2)2). /etc/my.Add/change each item in the cnf file below
[client]
default-character-set = utf8

[mysqld]
default-character-set = euckr
init_connect = SET collation_connection = euckr-korean_ci
init_connect = SET NAMES euckr
character-set-server = euckr
collation-server = euckr_korean_ci

[mysqldump]
default-character-set = euckr

[mysql]
default-character-set = euckr

3). /etc/httpd/httpd.conf

AddDefaultCharset EUC-KR

4). Web Source Character Set

<META http-equiv="Content-Type" content="text/html; charset=euc-kr" />

3. Installing Proftpd

./configure -prefix=/usr/local/proftpd -enable-autoshadow
make
make install

cp /usr/local/proftpd/sbin/proftpd /etc/rc.d/init.d/
vi /usr/local/proftpd/etc/proftpd.conf -> user -> root
group -> nobody

4. Install Apache

./configure --prefix=/usr/local/apache --enable-rule=SHARED_CORE --enable-module=so --enable-shared=max
make
make install

4-1. Change settings

Change installation path
DocumentRoot "/home/kuksool"

Change Html and php extensions to be available
AddType application/x-httpd-php .php .html .inc
AddType application/x-httpd-php-source .phps
AddType application/x-tar .tgz

5. PHP Installation

./configure --with-apxs=/usr/local/apache/bin/apxs --with-language=korean --with-charset=euc_kr --with-config-file-path=/usr/local/apache/conf --with-exec-dir=/usr/local/apache/bin --with-enable-track-vars=yes --with-enable-socket --with-enable-modules=so --enable-sigchild --disable-debug --with-enable-ftp --with-mysql=/usr/local/mysql

make

make install

5-1. PHP Configuration Settings
cp php.ini-dist /usr/local/apache/conf/php.ini
cp php.ini-dist /usr/local/lib/php.ini
register_globals = On
expose_php = Off
output_buffering=On

This is how much the web server APM installation is usually done.
The rest of the security settings are omitted.

728x90
반응형

'리눅스와 웹개발' 카테고리의 다른 글

XML의 개념  (2) 2023.11.29
script language  (2) 2023.11.28
Unix/Linux System과 Windows System의 장/단점  (2) 2023.11.26
리눅스 클라우드 컴퓨팅  (6) 2023.11.25
리눅스 커뮤니티 및 지원  (6) 2023.11.24

loading