cài-đặt-LAMP-Server

 

Step 1 Cài đặt Mysql

1a. Tạo thư mục sources chứa các gói cần thiết:

– Để dễ dàng quản lý các gói cài đặt ta nên tạo 1 thư mục để chứa tất cả các gói cài đặt như trường hợp ở đây là thư mục sources được đặt trong thư mục tmp( đây là thư mục lưu các tập tin được tạo ra tạm thời)

[user@localhost ~]$ cd /tmp[user@localhost tmp]$ mkdir sources

1b. Download Mysql package về trong thư mục /tmp/source

-Trước tiên ta cần tìm sources của mysql, ta lên trang web của mysql(www.mysql.com) tìm gói cài đặt thích hợp download về.

-Ở đây ta có thể download bằng 2 cách sau

  • Dùng lệnh wget trong chính terminal để lấy sources mysql về như sau:
[user@localhost tmp]$ cd  /sources[user@localhost  sources]$ wget http://mirrors.dotsrc.org/mysql/Downloads/MySQL-5.0/mysql-5.0.51a.tar.gz
  • Dùng trình download của Firefox download về

Cài Đặt LAMP trên Centos 1
Cài Đặt LAMP trên Centos 1

1c. Tạo nhóm mysql và user mysql

-Ở đây về vấn đề bảo mật ta không nên cho chương trình mysqld của ta chạy dưới quyền root mà phải tạo 1 user thường và gán các thuộc tính đăt biệt cho phép user đó có quyền để chạy mysql.

-Như command bên dưới ta tạo 1 group mysql và 1 user mysql thuộc group đó.

-Trong Linux chỉ có root mới có quyền tạo được group và user. Ta dùng lệnh su để chuyển từ account user thường qua account root và thự hiện việc add user và group theo command sau:

[user@locallhost ~]cd /usr/sbin[user@locallhost sbin]suPassword:[root@locallhost sbin]$./groupadd mysql[root@localhost sbin]$ ./useradd -g mysql mysql

Lưu ý: Để tạo được group và user ta phải vào chính thư mục chứa đoạn script chạy được những groupadd và useradd ở trên. Ở CentOS thì những script chạy lệnh groupadd và useradd là nằm trong thư mục /usr/sbin

1d.  Giải nén gói mysql-5.0.51a.tar.gz

-Sau khi đã có được source của mysql với đuôi .tar.gz ta phải thực hiện giải nén gói đó với lệnh tar và những option đi kèm.(*)

[root@localhost tmp]# cd sources/[root@localhost sources]# lshttpd-2.2.4.tar.gz  mysql-5.0.51a.tar.gz  php-5.2.4[root@localhost sources]#[root@localhost sources]# tar -xvzf mysql-5.0.51a.tar.gz

[root@localhost sources]#

1e. Kiểm tra và cấu hình nơi cài đặt cho Mysql

-Cấu hình nơi cài đặt cho Mysql với những option cần thiết theo yêu cầu của hệ thống mình.

-Với cầu hình hệ thống trước mắt ta chỉ cần thêm option –prefix. Ở đây option –prefix cho phép ta xác định thư mục ta sẽ cài đặt mysql.

[root@localhost sources]#[root@localhost sources]# cd mysql-5.0.51a[root@localhost mysql-5.0.51a]# ./configure –prefix=/usr/local/mysql/checking build system type… i686-pc-linux-gnu

checking host system type… i686-pc-linux-gnu

checking target system type… i686-pc-linux-gnu

checking for a BSD-compatible install… /usr/bin/install -c

checking whether build environment is sane… yes

checking for gawk… gawk

checking whether make sets $(MAKE)… yes

checking “character sets”… default: latin1, collation: latin1_swedish_ci; compiled in: latin1 latin1 utf8

checking whether to compile national Unicode collations… yes

checking for gcc… gcc

checking for C compiler default output file name… a.out

checking whether the C compiler works… yes

checking whether we are cross compiling… no

checking for suffix of executables…

checking for suffix of object files… o

checking whether we are using the GNU C compiler… yes

checking whether gcc accepts -g… yes

checking for gcc option to accept ANSI C… none needed

checking for style of include used by make… GNU

checking dependency style of gcc… gcc3

checking for g++… g++

checking whether we are using the GNU C++ compiler… yes

checking whether g++ accepts -g… yes

….

MySQL has a Web site at http://www.mysql.com/ which carries details on the latest release, upcoming features, and other information to make your work or play with MySQL more productive. There you can also find information about mailing lists for MySQL discussion.

Remember to check the platform specific part of the reference manual for hints about installing MySQL on your platform. Also have a look at the files in the Docs directory.

Thank you for choosing MySQL

1f. Cài đặt Mysql

-Dùng lệnh make và make install để cài đặt mysql.

[root@localhost mysql-5.0.51a]# makecd libmysql; make link_sources make[1]: Entering directory `/tmp/sources/mysql-5.0.51a/libmysql’ set -x; s=`echo strmov.lo strxmov.lo strxnmov.lo strnmov.lo strmake.lo strend.lo strtod.lo strnlen.lo strfill.lo is_prefix.lo int2str.lo str2int.lo strinstr.lo strcont.lo strcend.lo bcmp.lo ctype-latin1.lo bchange.lo bmove.lo bmove_upp.lo longlong2str.lo strtoull.lo strtoll.lo llstr.lo my_vsnprintf.lo ctype.lo ctype-simple.lo ctype-bin.lo ctype-mb.lo ctype-big5.lo ctype-czech.lo ctype-cp932.lo ctype-eucjpms.lo ctype-euc_kr.lo ctype-win1250ch.lo ctype-utf8.lo ctype-extra.lo ctype-ucs2.lo ctype-gb2312.lo ctype-gbk.lo ctype-sjis.lo ctype-tis620.lo ctype-ujis.lo ctype-uca.lo xml.lo my_strtoll10.lo str_alloc.lo  | sed “s;.lo;.c;g”`;    ds=`echo dbug.lo  | sed “s;.lo;.c;g”`; ………………………..

…………………….

[root@localhost mysql-5.0.51a]# make install

 

1g. Coppy file cấu hình của SQL Server vào /etc/my.cnf. Vào thư mục cài đặt và thay đổi quyền sờ hữu thư mục mysql.

-Coppy file cấu hình của mysql vào thư mục /etc và lấy tên là my.cnf

-Do khi giải nén gói mysql ta sử dụng account Root nên quyền sở hữu thư  mục này là Root.

-Để user 1 user bất kỳ có thể thực thi được chương trình mysql ta cần thay đổi quyền chủ sở hữu thư mục cài đặt mysql cho user đó.

-Cụ thể ở đây ta thay đổi chủ sở hửu thư mục mysql (/usr/local/mysql) cho user mysql.

-Thay dổi chủ sở hữu nhóm của thư mục mysql(/usr/local/mysql) cho nhóm mysql

-Option –R đi kèm theo có ý nghĩa thực hiện quyền sở hưu thư mục và tập tin theo đệ quy.

[root@localhost mysql-5.0.51a]# cp support-files/my-medium.cnf /etc/my.cnf[root@localhost mysql-5.0.51a]# cd /usr/local/mysql/[root@localhost mysql]# chown -R mysql .[root@localhost mysql]# chgrp -R mysql .

1h. Khởi tạo databases mặc định

-Option –user=[parameter username], với parameter username chính là user mysql đã tạo ở trên.

[root@localhost mysql]# bin/mysql_install_db –user=mysqlInstalling MySQL system tables… OK Filling help tables… OKTo start mysqld at boot time you have to copy support-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/local/mysql/bin/mysqladmin -u root password ‘new-password’ /usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain password ‘new-password’See the manual for more instructions. You can start the MySQL daemon with: cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/mysql/bin/mysqlbug script!

The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com

1i. Thay đổi quyền sở hữu thư mục.

-Hầu hết việc cài đặt mysql đều thực thi với account root. Ngoại trừ những database mặc định dược khởi tạo ở bước trên phải có chủ sở hữu là user mysql.

-Ta thực hiện trả lại quyền chủ sở hữu toàn bộ thư mục mysql(/usr/local/mysql) cho account root.

-Riêng với thư mục database mặc định (var) thì chủ sở hữu vẫn là user mysql.

[root@localhost mysql]# chown  -R root .[root@localhost mysql]# chown -R mysql var[root@localhost mysql]#ls -l

Cài Đặt LAMP trên Centos 2
Cài Đặt LAMP trên Centos 2

1j. Auto start mysql khi CentOS start

-Để cho hệ thống hoạt động tốt và xuyên suốt ta cần cấu hình cho mysql khởi dộng cùng lúc khi CentOS khởi động.

-Trước tiên ta coppy file support-files/mysql.server vào thư mục /etc/init.d/mysqld.

-Thay đổi quyền thực thi file mysqld.

-Dùng lệnh chkconfig để active mysqld khi hệ thống được boot.

[root@localhost mysql-5.0.51a]#cp ./support-files/mysql.server /etc/init.d/mysqld[root@localhost mysql]#cd /etc/init.d[root@localhost init.d]#chmod 755 ./mysqld[root@localhost init.d]#cd /sbin

[root@localhost sbin]#./service mysqld status

[root@localhost sbin]#./chkconfig –add mysqld

[root@localhost sbin]#./chkconfig –level 345 mysqld on

 

1k. Chạy chương trình và tạo 1 cơ sở dữ liệu là stagly

-Ở bước đầu tiên khi ta chua restat lai Máy bạn phải chạy mysql server bằng tay với lệnh sau:

[root@localhost mysql]# ./bin/mysqld_safe –user=mysql &[6] 30143   mailto:root@localhost mysql]# Starting mysqld daemon with databases from /usr/local/mysql/var[root@localhost mysql]# cd /usr/local/mysql/bin/[root@localhost bin]# ./mysql –u root -p

 

Welcome to the MySQL monitor.  Commands end with ; or g.

Your MySQL connection id is 2 Server version: 5.0.45-log Source distribution

iType ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql>

 

mysql> create database stagly

è ;

è  Query OK, 1 row affected (0.00 sec)

mysql>

 

Step 2 Cài đặt Apache

2a.  Download httpd-2.2.8 về thư mục /tmp/sorces

[root@localhost tmp]$ cd  /sources[root@localhost  sources]$ wgethttp://mirrors.24-7-solutions.net/pub/apache/httpd/httpd-2.2.8.tar.gz

 

2b. Giải nén file httpd.2.2.8.tar.gz

[root@localhost sources]#tar –xvzf httpd-2.2.8.tar.gz

2c. Vào thư mục httpd-2.2.8 để cấu hình nơi cài đặt chương trình

-Cấu hình nơi cài đặt cho Apache với những option cần thiết theo yêu cầu của hệ thống mình.

  • –prefix_ cho phép ta xác định thư mục ta sẽ cài đặt apache.Ở đây ta cài apache tại /usr/local/apache2
  • –enable-so_ Enable những module hỗ trợ cho nhũng thư viện .so của php
  • –enable-dav_ Enable WEBDAV protocol hỗ trợ cho SVN
[root@localhost sources]# cd httpd-2.2.8[root@localhost httpd-2.2.8]# ./configure –enable-so –enable-dav –prerfix=/usr/local/apachechecking for chosen layout… Apache checking for working mkdir -p… yes checking build system type… i686-pc-linux-gnu checking host system type… i686-pc-linux-gnu checking target system type… i686-pc-linux-gnu

Configuring Apache Portable Runtime library …

…………………….

config.status: creating support/dbmmanage config.status: creating support/envvars-std config.status: creating support/log_server_status config.status: creating support/logresolve.pl config.status: creating support/phf_abuse_log.cgi config.status: creating support/split-logfile config.status: creating build/rules.mk config.status: creating build/pkg/pkginfo config.status: creating build/config_vars.sh config.status: creating include/ap_config_auto.h config.status: executing default command

2d. Cài đặt chương trình

[root@localhost httpd-2.2.4]# makeMaking all in srclib make[1]: Entering directory `/tmp/sources/httpd-2.2.8/srclib’ Making all in apr make[2]: Entering directory `/tmp/sources/httpd-2.2.8/srclib/apr’ make[3]: Entering directory `/tmp/sources/httpd-2.2.4/srclib/apr’ /bin/sh /tmp/sources/httpd-2.2.8/srclib/apr/libtool –silent –mode=compile gcc -g -O2 -pthread   -DHAVE_CONFIG_H -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE   -I./include -I/tmp/sources/httpdivyphuongnguyen:       2.2.8/srclib/apr/include/arch/unix -I./include/arch/unix -I/tmp/sources/httpd-2.2.8/srclib/apr/include  -o passwd/apr_getpass.lo -c passwd/apr_getpass.c && touch passwd/apr_getpass.lo /bin/sh /tmp/sources/httpd-2.2.8/srclib/apr/libtool –silent –mode=compile gcc -g -O2 -pthread   -DHAVE_CONFIG_H -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE   -I./include -I/tmp/sources/httpd-2.2.8/srclib/apr/include/arch/unix -I./include/arch/unix -I/tmp/sources/httpd-2.2.8/srclib/apr/include  -o strings/apr_cpystrn.lo -c strings/apr_cpystrn.c && touch strings/apr_cpystrn.lo……………………….

make[1]: Leaving directory `/tmp/sources/httpd-2.2.8′

[root@localhost httpd-2.2.8]#

[root@localhost httpd-2.2.8]# make install

Making install in srclib make[1]: Entering directory `/tmp/sources/httpd-2.2.8/srclib’ Making install in apr make[2]: Entering directory `/tmp/sources/httpd-2.2.8/srclib/apr’ sed ‘s,^(location=).*$,1installed,’ < apr-1-config > apr-config.out sed ‘s,^(apr_build.*=).*$,1/usr/local/apache/build,’ < build/apr_rules.mk > build/apr_rules.out make[3]: Entering directory `/tmp/sources/httpd-2.2.8/srclib/apr’ make[3]: Nothing to be done for `local-all’.

Installing CGIs mkdir /usr/local/apache/cgi-bin Installing header files Installing build system files

…………………………………..

Installing man pages and online manual mkdir /usr/local/apache/man mkdir /usr/local/apache2/man/man1 mkdir /usr/local/apache/man/man8 mkdir /usr/local/apache2/manual make[1]: Leaving directory `/tmp/sources/httpd-2.2.8′

[root@localhost httpd-2.2.8]#

[root@localhost httpd-2.2.8]# /usr/local/apache/bin/apachectl start

2e. Chạy chương trình và Test

[root@localhost httpd-2.2.8]# /usr/local/apache/bin/apachectl start

Cài Đặt LAMP trên Centos 3
Cài Đặt LAMP trên Centos 3

2f. Auto Start Apche

[root@localhost ~] cd /etc/rc5.d[root@localhost init.d]less S99Local

Cài Đặt LAMP trên Centos 4
Cài Đặt LAMP trên Centos 4

-Thêm dòng /usr/local/apache/bin/apachectl start vào để apache tự động start khi hệ thống reboot.

-Lưu lại file S99local với những chi tiết trên.

Step 3 Cài đặt PHP

3a. Download PHP

[root@localhost ~ ] wget http://vn.php.net/distributions/php-5.2.5.tar.gz /tmp/Sources

3b. Giải nén goi php-5.2.5.tar.gz vừa download

[root@localhost sources]# tar -xvzf php-5.2.5.tar.gzphp-5.2.5/php-5.2.5/ext/php-5.2.5/ext/gd/php-5.2.5/ext/gd/gd.c

php-5.2.5/ext/gd/gd_ctx.c

php-5.2.5/ext/gd/libgd/

php-5.2.5/ext/gd/libgd/gd.c

……………………………..

php-5.2.5/README.PHP4-TO-PHP5-THIN-CHANGES

php-5.2.5/CREDITS

php-5.2.5/README.UPDATE_5_2

php-5.2.5/README.UNIX-BUILD-SYSTEM

php-5.2.5/buildconf.bat

[root@localhost php-5.2.5]#

3c. Vào thư mục php-5.2.5 cài đặt của chương trình

-Cấu hình nơi cài đặt cho php với những option cần thiết theo yêu cầu của hệ thống mình.

[root@localhost sources]# cd php-5.2.5[root@localhost php-5.2.5]# ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache/bin/apxs –with-mysql=/usr/local/mysql –enable-mbstring –libexecdir=/usr/libexec –disable-rpath –with-pear –with-pic –disable-debug –with-bz2 –with-curl –with-exec-dir=/usr/bin –enable-gd-native-ttf –with-png –with-zlib –with-xml –with-gd –enable-xmlreader –enable-xmlwriter –enable-json –enable-pdo –enable-xml –enable-zip –with-openssl –enable-calendar –enable-ftp –with-gmp –without-sqlite –without-pdo-sqlitecreating cache ./config.cache checking for Cygwin environment… nochecking for mingw32 environment… no

checking for egrep… grep -E checking for a sed that does not truncate output… /bin/sed

checking host system type… i686-pc-linux-gnu

checking target system type… i686-pc-linux-gnu checking for gcc… gcc

checking whether the C compiler (gcc  ) works…

………………………….

+——————————————————————–+

| License:                                                         |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+——————————————————————–+

Thank you for using PHP.

[root@localhost php-5.2.5]#

[root@localhost php-5.2.5]#make && make test

[root@localhost php-5.2.5]#make install

3d. Nạp Php vào Apache

-Vào /usr/local/apache/module kiểm tra xem thư viện libphp5.so đã được nạp vào apache chưa

Cài Đặt LAMP trên Centos 5
Cài Đặt LAMP trên Centos 5

-Chép file cấu hình của php vào thư mục /usr/local/lib

-Thêm những thông tin cần thiết của php vào file cấu hình htttpd.conf vào Apache

[root@localhost php-5.2.4]# cp php.ini-dist /usr/local/php/lib/php.ini[root@localhost php-5.2.4]#[root@localhost php-5.2.4]# cd /usr/local/apache2/conf

[root@localhost conf]#  vi httpd.conf

Cài Đặt LAMP trên Centos 6
Cài Đặt LAMP trên Centos 6

-Dòng AddType application/x-httpd-php .php .phtml .htm. Có ý nghĩa là những file có extension .htm, .php, .phtml sẽ được biên dịch thông qua compiler của php.

3e. Chỉnh sửa những thông tin trong file php.ini

-Ở đây ta disable dòng display_errors = on để không cho phép hiển thị những lỗi của php.

 

[root@localhost apache2]# cd /usr/local/lib[root@localhost lib]# less php.ini

ài Đặt LAMP trên Centos 7
ài Đặt LAMP trên Centos 7

-Sửa lại dòng error_reporting = E_USER_ERROR. Ý nghĩ chỉ hiển thị lỗi người dùng không hiển thị những những lỗi warning

Cài Đặt LAMP trên Centos 8
Cài Đặt LAMP trên Centos 8

-Để hệ thống có thể gửi mail được ta đưa đường dẫn nơi cài đặt sendmail vào phần sendmial_path trong file php.ini. Ở đây đường dẫn của ta sẽ là: sendmail_path =/usr/sbin

Cài Đặt LAMP trên Centos 9
Cài Đặt LAMP trên Centos 9

3f. Tạo trang phpinfo để test chương trình

-Để test xem php đã hoạt động hay chưa ta tạo 1 file index.php để test.

-Nên nhớ đường dẫn dến DocumentRoot của ta là /var/www/html. Do đó ta phải tạo file index.php trong đúng directory này.

-Vào file httpd.conf cho file index.php vào DerectoryIndex.

root@localhost apache2]# cd /var/www/html[root@localhost html]# cat > index.php<?phpinfo();?>

 

[root@localhost html] cd/usr/local/apache/conf/httpd.conf

Cài Đặt LAMP trên Centos 10
Cài Đặt LAMP trên Centos 10

3g. Test PHP

Chạy trang index.php để kiểm tra cấu hình php.

Cài Đặt LAMP trên Centos 11
Cài Đặt LAMP trên Centos 11

(*) Để hiểu thêm về những option đi kèm với bất cứ lệnh nào trong linux ta sử dụng lệnh man với cú pháp như sau: # man tenlenh vd: man tar

Step 4 Cài đặt phpMyAdmin:

 

4a. Giải nén package phpMyAdmin.tar.gz vào thư mục gốc của Apache server bằng command:

[root@Webser ~]#cp phpMyAdmin.tar.gz /var/www/html[root@Webser ~]#cd /var/www/html[root@Webser html]#tar –xvzf phpMyAdmin.tar.gz

4b. Cấu hình lại file config của phpMyAdmin:

[root@Webser html]#cd phpMyAdmin[root@Webser phpMyAdmin]#vi config.inc.php

4c. Chỉnh lại các thông số:

//đường dẫn đến nơi cài đặt phpMyAdmin

$cfg[‘PmaAbsoluteUri’] = ‘http://localhost/phpMyAdmin’;

//chọn kiểu xác thực account bằng dialog

$cfg[‘Servers’][$i][‘auth_type’] = ‘http’;

//ghi default username của mysql server

$cfg[‘Servers’][$i][‘user’] = ‘root’;

//ghi default password của mysql server

$cfg[‘Servers’][$i][‘password’] = ‘st017pass’;

//ghi địa chỉ của mysql server

$cfg[‘Servers’][$i][‘host’] = ‘192.168.10.26’;

4d. Chạy phpMyAdmin tại địa chỉ http://localhost/phpMyAdmin/index.php nếu webserver ở localhost.

Cài Đặt LAMP trên Centos 12
Cài Đặt LAMP trên Centos 12

4e. Sau khi login thành công, sẽ hiển thị màn hình:

Cài Đặt LAMP trên Centos 13
Cài Đặt LAMP trên Centos 13

 

PhatHuynh

BÌNH LUẬN