Cài đặt webserver apache+php+mysql trên fedora

8 768 2
Tài liệu đã được kiểm tra trùng lặp
Cài đặt webserver apache+php+mysql trên fedora

Đang tải... (xem toàn văn)

Thông tin tài liệu

Cài đặt Webserver apache trên Linux

Trước tiên các bạn download Source cài đặt cho linux: Apache 2.2.2 (www.apache.org) files httpd-2.2.2.tar.gz Php 4.4.2 (www.php.net) files php-4.4.2.tar.gz Mysql 4.0.22 (dev.mysql.com) files mysql-4.0.22.tar.gz Trước khi cài đặt bạn phải login vào Root của linux. Để login vào root bạn dùng command: #su #password:******** Sau khi login vào root bạn giải nén source apache + php + mysql đã download bằng command sau : #tar -zxf httpd-2.2.2.tar.gz (enter) #tar -zxf mysql-4.0.22.tar.gz (enter) #tar -zxf php-4.4.2.tar.gz (enter) Sau khi giải nén xong bạn sẽ nhìn thấy những thư mục tương ứng. Ví dụ: httpd-2.2.2 , php-4.4.2 , mysql-4.0.22 . Phần 1:. Cài đặt Apache. Trỏ đến thư mục vừa giải nén bộ cài apache #cd httpd-2.2.2 (enter) và đánh vào command sau : #./configure --prefix=/usr/local/apache2 --enable-mods-shared=most (enter) Câu lệnh trên có nghĩa là chúng ta sẽ cài đặt Apache vào thư mục /usr/local/apache2 . Sau khi quá trình xử lý xong màn hình terminal sẽ trả lại dấu nhắc lệnh bạn đánh vào : #make (enter) Đợi một vài phút trở lại dấu nhắc lệnh bạn đánh tiếp vào : #make install (enter) Sau khi quá trình xử lý xong là Apache đã thực sự được install trên Pc Linux của bạn. Bước tiếp theo là cấu hình cho Apache. #gedit /usr/local/apache2/conf/httpd.conf Tìm đoạn : Thêm vào bên dưới nó : LoadModule php4_module modules/libphp4.so Tìm tiếp : DirectoryIndex index.html Thay bằng: DirectoryIndex index.html index.html.var index.php Tìm tiếp đoạn : AddType application/x-gzip .gz .tar Thêm vào bên dưới nó : AddType application/x-httpd-php .php Save lại files config. Bạn đã cấu hình xong apache cho linux. Bây giờ sang phần 2 cấu hình Mysql. Phần 2: cấu hình Mysql Đánh command để trở lại thư mục root: #cd (enter) Trỏ đến thư mục chứa source cài đặt php #cd mysql-4.0.2.2 (enter) Đánh tiếp vào terminal command config mysql: #./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --disable-maintainer-mode --with-mysqld-user=mysql --enable-large-files-without-debug (enter) Bạn ngồi đợi cho tới lúc dấu nhắc lệnh quay trở lại tiếp tục đáng vào: #make (enter) Rồi tiếp theo đó #make install (enter) Sau khi quá trình xử lý xong mysql đã thực sự được cài đặt trên server của bạn. Bây giờ đến bước cấu hình cho mysql. Trước tiên bạn phải tạo một nhóm cho mysql : #/usr/sbin/groupadd mysql (enter) Tiếp đó bạn tạo một User là mysql theo nhóm đã tạo: #/usr/sbin/useradd -g mysql mysql (enter) Cài đặt database files : #./scripts/mysql_install_db (enter) Then we make a couple minor ownership changes # chown -R root:mysql /usr/local/mysql (enter) Bây giờ chỉnh sửa trong files ld.so.conf #gedit /etc/ld.so.conf Thêm vào dòng sau : /usr/local/mysql/lib/mysql Sau khi edit xong bạn save lại.Tiếp theo ta chỉnh sửa files /etc/my.cnf #gedit /etc/my.cnf Thêm vào đưới những đoạn sau đây : [client] socket=/var/lib/mysql/mysql.shock Sau đó ta save lại rồi khởi động mysql bằng command: #/etc/rc.d/init.d/mysqld start #/usr/local/mysql/bin/mysqld_safe --user=mysql & Tạo mật khẩu root config cho mysql: mysqladmin -u root password new_password new_password bạn có thể thay bằng password của bạn. Bây giở login vào mysql root để add user cho mysql. #mysql -u root -p (enter) #Enter password: (nhập pass của bạn) Bây giờ add user cho mysql mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' --> IDENTIFIED BY 'some_pass' WITH GRANT OPTION; mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%' --> IDENTIFIED BY 'some_pass' WITH GRANT OPTION; mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost'; mysql> GRANT USAGE ON *.* TO 'dummy'@'localhost'; Chú ý: Thay đổi username phần này ------> 'monty'@'localhost' = 'tenban'@'localhost' Thay đổi password phần này ------> 'some_pass' = 'matkhau_cuaban' 2 dòng dưới cùng là admin'@'localhost và 'dummy'@'locahost bạn không được thay đổi. Theo như hình minh họa trên tôi đã tạo ra một user là: qhoa và password là : check Một số command thông dụng trên mysql : mysql> create database name; ( tạo database cho mysql ) mysql> drop database name; ( xóa database ) mysql> show databases; ( xem tất cả những database mysql có ) vậy là đã cấu hình xong mysql phần còn lại là cấu hình Php Phần 3: Cấu hình php Đánh command để trở lại thư mục root: #cd (enter) Trỏ đến thư mục chứa source cài đặt php #cd php-4.4.2 (enter) Đánh tiếp vào terminal command config php: #./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with- mysql=/usr/local/mysql (enter) Đợi cho đến khi dấu nhắc lệnh trở lại bạn lại làm thêm hai bước sau: #make (enter) Sau đó đánh tiếp #make install (enter) Sau khi install xong bạn copy files php.ini bằng command sau : #cp php.ini-recommended /usr/local/php/lib/php.ini (enter) Edit files php.ini #gedit /usr/local/php/lib/php.ini (enter) Tìm đoạn doc_root thay thế bằng : doc_root= "/usr/local/apache2/htdocs/" Sau đó save lại. Thế là xong. Đến bây giờ còn chờ gì nữa ta khởi động toàn bộ apache webserver: #/usr/local/apache2/bin/apachectl start (enter) Bây giờ ta test php: #cd /usr/local/apache2/htdocs (enter) #gedit test.php Với nội dung trong files test.php như sau: <?php phpinfo(); ?> Save lại sau đó bạn bật trình duyệt web và đánh vào: localhost/test.php nếu thấy màn hình như sau là bạn đã config thành công php: Vậy là bạn đã cấu hình thành công php rồi đấy. Bước tiếp theo test mysql: #cd /usr/local/apache2/htdocs (enter) #gedit connect.php files connect.php với nôi dụng như sau : <?php $link = mysql_connect("ip_host", "qhoa", "check") or die ("Could not connect"); print("Connected successfully"); mysql_close($link); ?> Save lại sau đó bạn bật trình duyệt web và đánh vào: localhost/connect.php nếu thấy màn hình xuất hiện Connected successfully là mysql của bạn đã chạy tôt. Bây giờ chỉ còn bước cuối cùng là cấu hình cho Apache và Mysql tự động chạy khi linux startup: Trước tiên quay trở lại thư mục cài đặt mysql ban đầu #cd (enter) Trỏ đến thư mục chứa source cài đặt php #cd mysql-4.0.2.2 (enter) ta copy files mysql.server vào thư mục /etc/init.d : #cp support-files/mysql.server /etc/init.d/mysql Tiếp đến ta thiết lập link tới thư mục khởi động ở cấp độ 3 và 5 : #cd /etc/rc3.d <enter> #ln -s /init.d/mysql S85mysql <enter> #ln -s /init.d/mysql K85mysql <enter> #cd /etc/rc5.d <enter> #ln -s /init.d/mysql S85mysql <enter> #ln -s /init.d/mysql K85mysql <enter> #cd /init.d <enter> #chmod 755 mysql <enter> Tiếp theo đến apache server : #cd /usr/local/apache2/bin <enter> copy files apachectl vào thư mục /etc/init.d/httpd : #cp apachectl /etc/init.d/httpd <enter> #cd /etc/rc3.d <enter> #ln -s /init.d/httpd S85httpd <enter> #ln -s /init.d/httpd K85httpd <enter> #cd /etc/rc5.d <enter> #ln -s /init.d/httpd S85httpd <enter> #ln -s /init.d/httpd K85httpd <enter> Sau khi cấu hình xong bạn restart lai server đánh vào localhost bạn sẽ một trang web khác là Fedora Core Test Page . Bây giở thư mục để lưu trữ website sẽ nằm trong đường dẫn sau đây /var/www/html . Vậy ta đã hoàn tất quá trình cấu hình Apache + Mysql + Php trên Linux PC. Để chỉnh sửa cấu hình cho apache, cái này không chỉ tiện cho localhots mà cả khi muốn mở server nữa. dùng lệnh vi hay gedit để mở file htpd.conf chỉnh lại những dòng sau: ------------------------------------------------ tìm đến: ServerTokens OS sửa thành: ServerTokens Prod không hiển thị tên OS trên trang báo lỗi Tìm đến: ServerAdmin root@localhost sửa thành: ServerAdmin webmaster@tendomaincuaban.com địa chỉ email của người quản lý hiển thị trên trang báo lỗi Tìm đến: Options Indexes FollowSymLinks sửa thành: Options Includes ExecCGI FollowSymLinks Cho phép sử dụng CGI, SSI. không cho phép hiển thị list trong trường hợp không có index tìm đến: # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None sửa thành: AllowOverride All Cho phép sử dụng file .htaccess tìm đến: # # The following directives define some format nicknames for use with # a CustomLog directive (see below). # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined sửa thành: LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined ←không ghi lại log do lỗi 414 tìm đến: # # For a single logfile with access, agent, and referer information # (Combined Logfile Format), use the following directive: # Thêm vào: SetEnvIf Request_URI "default\.ida" no_log SetEnvIf Request_URI "cmd\.exe" no_log SetEnvIf Request_URI "root\.exe" no_log SetEnvIf Request_URI "Admin\.dll" no_log SetEnvIf Request_URI "NULL\.IDA" no_log (không ghi lại log truy nhập của worms) thêm vào: SetEnvIf Remote_Addr 192.168.1 no_log Không ghi lại log access nội bộ (địa chỉ của mạng LAN ở đây là 192.168.1.*) tìm đến: CustomLog logs/access_log combined sửa thành: CustomLog logs/access_log combined env=!no_log ghi lại log trừ những trường hợp ngoại lệ đã ghi ở trên . linux startup: Trước tiên quay trở lại thư mục cài đặt mysql ban đầu #cd (enter) Trỏ đến thư mục chứa source cài đặt php #cd mysql-4.0.2.2 (enter) ta copy files. --prefix=/usr/local/apache2 --enable-mods-shared=most (enter) Câu lệnh trên có nghĩa là chúng ta sẽ cài đặt Apache vào thư mục /usr/local/apache2 . Sau khi quá trình

Ngày đăng: 08/08/2013, 17:15

Tài liệu cùng người dùng

Tài liệu liên quan