Hướng dẫn cài đặt: Apache/PHP/MySQL/GD (DSO mode)

Deathknight

Active Member
Hướng dẫn cài đặt: Apache/PHP/MySQL/GD (DSO mode) trong Linux
Nguồn gốc : www.diendantinhoc.net

{nói chung là chạy Server tại nhà}

Sau nhiều lần cài đặt "bầm dập", tôi viết bài hướng dẫn này hi vọng giúp người mới làm quen với Linux có thể dễ dàng cài đặt bộ Apache/PHP/MySQL/GD bằng cách compile/install từ source.

Nội dung:

1. Kiểm tra các package đã cài đặt
2. Download & bung các package
3. Compile sources
- mysql
- jpeg
- zlib
- libpng
- freetype
- gd
- apache
- php
4. Đặt cấu hình và thử php - mysql - gd

Bước 1. Kiểm tra các package đã cài đặt cùng lúc với Linux
» Login với account root

» Dùng lệnh: rpm –qa | grep tên_package để kiểm tra các package đã cài đặt
Ví dụ: rpm –qa | grep mysql
nếu mysql đã có install từ trước rồi thì lệnh trên sẽ hiện kết quả danh sách các package của mysql, ta phải gỡ bỏ đi bằng lệnh: rpm –e tên_package

Ta phảI gỡ bỏ hết các package apache, mysql, php, gd rồi mới cài đặt mới. Nếu có báo kết quả là có vài package dependencies thì phảI gỡ bỏ các package dependencies này trước khi gỡ bỏ package chính.

Lưu ý: do đó, để tránh phiền phức, khi cài đặt Linux thì không nên chọn cài đặt các package này.

Ngoài ra, cần phải kiểm tra package jpeg, zlib, png xem có được cài đặt chưa, nếu chưa thì phải download các package này về (xem bước 2).

Bước 2. Download & bung các package
Lưu ý: đối với GD Lib thì có 2 phiên bản:
- bản gốc: http://www.boutell.com/gd/http/gd-2.0.1.tar.gz không còn hỗ trợ tạo file GIF do vấn đề bản quyền,
- bản patched: http://downloads.rhyme.com.au/gd/gd-2.0.1gif.tar.gz thì cho phép tạo GIF (cho nên ta sẽ dùng cái này, kể từ đây thì phần nào có dấu # ở đầu dòng có nghĩa là phần ghi chú, giải thích hay phần tuỳ chọn-để phân biệt với các dòng khác là các lệnh phải thực hiện hoặc là thông tin chính)

Các package bạn có thể download ở:
http://www.apache.org/dist/httpd/apache_1.3.22.tar.gz
http://www.php.net/do_download.php?downloa...hp-4.1.0.tar.gz
http://www.mysql.com/Downloads/MySQL-3.23/...-3.23.39.tar.gz
http://downloads.rhyme.com.au/gd/gd-2.0.1gif.tar.gz
#http://www.boutell.com/gd/http/gd-2.0.1.tar.gz
http://prdownloads.sourceforge.net/freetyp...pe-2.0.4.tar.gz

#Nếu chưa cài đặt zlib, png, jpeg, bạn download ở:
ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
http://www.info-zip.org/pub/infozip/zlib/zlib.tar.gz
http://www.libpng.org/pub/png/src/old/libpng-1.0.10.tar.gz

#Bạn copy các file mới download vào thư mục /usr/local/src, rồi thực hiện lần lượt các lệnh sau:

cd /usr/local/src

#Bung các package:
tar -xvzf apache_1.3.22.tar.gz
tar -xvzf php-4.1.0.tar.gz
tar -xvzf mysql-3.23.39.tar.gz
tar -xvzf gd-2.0.1gif.tar.gz
tar -xvzf freetype-2.0.4.tar.gz

#Nếu chưa cài đặt jpeg, zlib, png
tar -xvzf jpegsrc.v6b.tar.gz
tar -xvzf zlib-1.1.3.tar.gz
tar -xvzf libpng-1.0.11.tar.gz

Bước 3. Compile sources:
#vẫn còn đang ở trong thư mục /usr/local/src

#mysql
cd ./mysql-3.23.39
#cài đặt vào thư mục /usr/local/mysql
./configure --prefix=/usr/local/mysql
make
make install
scripts/mysql_install_db
#start mysql server
/usr/local/mysql/bin/safe_mysqld &
# bấm <Enter>
/usr/local/mysql/bin/mysqlshow –p

#tạo thư mục để cài đặt freetype
mkdir /usr/local/include

#jpeg
cd ../jpeg-6b
./configure --enable-shared --enable-static
make
make install
#Libraries đã được cài đặt trong: /usr/local/lib

#zlib
cd ../zlib-1.1.3
./configure
make
make test
make install
#Libraries đã được cài đặt trong: /usr/local/lib

#libpng
cd ../libpng-1.0.11
cp scripts/makefile.linux makefile
#sửa makefile dùng vi makefile
#bỏ dấu # trước dòng ZLIBLIB=/usr/local/lib, ZLIBINC=/usr/local/include
#và thêm dấu # trước dòng ZLIBLIB=../zlib, ZLIBINC=../zlib
make
make test
make install

#freetype
cd ../freetype-2.0.4
make setup
make
make install
#Libraries đã được cài đặt trong: /usr/local/lib

#gd
cd ../gd-2.0.1
#sửa makefile dùng vi Makefile
#tìm dòng INCLUDEDIRS=-I. -I/usr/include/freetype2 -I/usr/include/X11 -I/usr/X11R6/include/X11 -I/usr/local/include
#và thay bằng INCLUDEDIRS=-I. -I/usr/local/include/freetype2 -I/usr/include/X11 -I/usr/X11R6/include/X11 -I/usr/local/include
make
make install
make libgd.a
#libgd.so đã được cài đặt trong /usr/lib

#apache
cd ../apache_1.3.22
./configure --prefix=/usr/local/apache --enable-module=most --enable-shared=max
make
make install

#php
cd ../php-4.1.0
#config gồm 4 dòng liên tục
./configure --with-mysql=/usr/local/mysql --with-xml --with-apxs=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/apache/conf \
--enable-versioning --enable-ftp --enable-magic-quotes --with-gd --with-ttf=/usr/local/include/freetype2 \
--with-freetype-dir=/usr/local/include/freetype2 --with-png-dir=/usr/local --with-jpeg-dir=/usr/local --with-zlib-dir=/usr/local \
--enable-shared-pdflib --enable-bcmath --disable-debug --enable-memory-limit=yes --enable-track-vars --with-mod-charset
#chú ý: mỗi dòng ở trên được đánh dấu bằng một màu khác nhau và được gõ vào trên 4 dòng,
#để gõ một câu lệnh dài và ngắt thành nhiều dòng (như trên), bạn thêm ký tự sổ chéo ngược (\) ở cuối dòng
#dòng cuối cùng không có dấu sổ chéo
#lưu ý: ở trước dấu sổ chéo có một khoảng trắng, bạn phải gõ chính xác như vậy (kể cả chữ hoa/chữ thường)
make
make install
#copy file php.ini
cp /usr/local/src/php-4.1.0/php.ini-dist /usr/local/apache/conf/php.ini

Bước 4. Đặt cấu hình và thử php - mysql - gd
#Cài đặt cấu hình cho apache:
#sửa file httpd.conf dùng vi /usr/local/apache/conf/httpd.conf
#tìm đến dòng #ServerName localhost.localdomain,
#thêm dòng mới ServerName ip_address sau dòng này (ip_address bạn đặt tuỳ ý, ví dụ 192.168.1.1)
#tìm đến cụm
#<IfModule mod_dir.c>
# DirectoryIndex index.html
#</IfModule>
#thêm vào : index.htm index.php index.php3 index.phtml index.cgi phía sau index.html
#(dòng đó sẽ trở thành DirectoryIndex index.html index.htm index.php index.php3 index.phtml index.cgi)
#và để cho phép chạy PHP 4.x, bạn tìm đến dòng #AddType application/x-httpd-php .html .php
#bỏ dấu # ở đầu dòng và thêm: .php3 .phtml .phtm ở cuối dòng
(dòng đó sẽ trở thành AddType application/x-httpd-php .html .php .php3 .phtml .phtm)

#Start Apache:
/usr/local/apache/bin/apachectl start
#cấp quyền cho thư mục web
chmod 775 /usr/local/apache/htdocs

#Tạo file php.php để xem cấu hình php đã cài đặt
echo "<? phpinfo(); ?>" > /usr/local/apache/htdocs/php.php

#mở Web Browser và thử:
http://192.168.1.1/php.php

#nếu chạy tốt thì đã thành công rồi đó

#thử php_mysql
/usr/local/mysql/bin/mysql -u root
#lúc này sẽ xuất hiện dấu nhắc mysql>, bạn gõ lần lượt các lệnh:
use test;
CREATE TABLE books (
id int(3) not null auto_increment,
name char(50) not null,
unique(id),
primary key(id)
);
INSERT INTO books (name) values('PHP 4 Newbies');
INSERT INTO books (name) values('Red Hat Linux Server');
exit
#lưu ý: tổng cộng ở trên là 5 lệnh, lệnh exit sẽ thoát khỏi dấu nhắc của mysql

#tạo file mysql.php trong thư mục /usr/local/apache/htdocs/
#(có thể dùng vi /usr/local/apache/htdocs/mysql.php)
#nội dung file mysql.php như sau:
<?
$dbuser = 'root';
$dbhost = 'localhost';
$dbpass = '';
$dbname = 'test';
$dbtble = 'books';
$mysql_link = mysql_connect($dbhost, $dbuser, $dbpass);
$column = mysql_list_fields($dbname, $dbtble, $mysql_link);
for($i=0; $i< mysql_num_fields($column); $i++ ) {
print mysql_field_name($column,$i )."<br>";
}
?>
#rồi sang browser chạy thử
http://192.168.1.1/mysql.php

#tạo tiếp file mysql2.php với nội dung như sau:
#(có thể dùng vi /usr/local/apache/htdocs/mysql2.php)
<html><head><title>vi du mysql2</title></head>
<body bgcolor="white">
<?
$dbuser = 'root';
$dbhost = 'localhost';
$dbpass = ‘’;
$dbname = 'test';
$dbtable = 'books';
$mysql_link = mysql_connect($dbhost, $dbuser, $dbpass);
$column = mysql_list_fields($dbname, $dbtable, $mysql_link);
$sql = "SELECT * FROM $dbtable";
$result = mysql_db_query($dbname,$sql);
?>
<table>
<?
while($value = mysql_fetch_array($result)) {
print "<tr>";
for ($i=0; $i<mysql_num_fields($column); $i++) print "<td> $value[$i] </td>";
print "</tr>";
}
mysql_free_result($result);
mysql_close();
?>
</table></body></html>
#rồi sang browser chạy thử
http://192.168.1.1/mysql2.php

#thử tạo image với gd
#(dùng vi /usr/local/apache/htdocs/gd.php)
<?
header("Content-type: image/png");
$im = @ImageCreate (200,50) or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
ImageString ($im, 1, 5, 5, "A Simple Text String", $text_color);
ImagePng ($im);
?>
#rồi sang browser chạy thử
http://192.168.1.1/gd.php

#thử tạo image với font true type (phải copy file arial.ttf vào thư mục /usr/local/apache/htdocs/ trước)
#(dùng vi /usr/local/apache/htdocs/gdttf.php)
<?
Header("Content-type: image/png");
if(!isset($s)) $s=11;
if (!$text) $text='Thử nghiệm';
if (!$font) $font="arial.ttf";
$fontfile=realpath(".")."/".$font;
$size = imagettfbbox($s,0,$fontfile,$text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$xpad=9;
$ypad=9;
$im = imagecreate($dx+$xpad,$dy+$ypad);
$blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white);
ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, $fontfile, $text);
ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, $fontfile, $text);
Imagepng($im);
ImageDestroy($im);
?>
#rồi sang browser chạy thử
http://192.168.1.1/gdttf.php

#đặt cấu hình cho phép boot server apache, mysql lúc khởi động Linux
#(sửa file rc.local dùng vi /etc/rc.d/rc.local)
#thêm vào cuối file nội dung sau
if [ -f /usr/local/mysql/bin/safe_mysqld ]; then
/usr/local/mysql/bin/safe_mysqld &
fi
if [ -f /usr/local/apache/bin/httpd ]; then
/usr/local/apache/bin/apachectl start
fi

#đặt đường dẫn cho mysql
#(sửa file profile dùng vi /etc/profile)
#thêm vào đầu file nội dung sau
PATH="$PATH:/usr/local/mysql/bin"

XIN CHÚC MỪNG, bạn đã cài đặt THÀNH CÔNG Apache, PHP, mySQL, GD trong Linux!
 

Thanh Tùng

Member
Tất cả mọi việc sẽ trở nên đơn giản hơn khi bỏ ra 8.000VNĐ ra hàng đĩa mua một đĩa các phần mềm thiết kế web mới nhất ( bộ 2 đĩa ) , có cái PHP Triad bao gồm Apache/PHP/MySQL/GD , và chỉ với 2 cái click , là mọi việc đã xong xuôi.
Ý quên , cái này dành cho Window :p
 

Thanh Tùng

Member
??? làm thế là làm thế nào ??? mỉa mai gì đấy ???
bất cứ trang web nào trước khi upload nó lên mạng để cho hoạt động thì cũng phải chạy thử trên localhost đã chứ , chẳng lẽ bro ko biết điều đó ?
 

Deathknight

Active Member
Hix
chú em thông cảm
thì đúng là nó ko biết rì mà
chú có hỏi nó 127.0.0.1 là IP của "nước nào" nó cũng chẳng biết đâu
chú Ruin cũng từng có "giấc mơ" đưa 4rum lên đấy chứ
nhưng Dek bói đâu ra được con Host (mặc dù chú vẫn khoe là có CC)
nên chán quá làm 1 cái invisionfree (đã bị hack)
*@D.A: biết thì thưa thốt, ko biết thì dựa cột mà nghe,
ko biết rì thì đừng nói lung tung, gặp cao thủ họ cười cho đấy
 

Tra cứu điểm thi

Phần mềm mới

Quảng cáo

11223344550983550000
Top