Hướng dẫn config apache php

|  Lập trình  |  Hướng dẫn cài đặt Apache, PHP, MySQL, PHPMyAdmin trên Windows 10 và cấu hình SendMail

Hướng dẫn cài đặt Apache, PHP, MySQL, PHPMyAdmin trên Windows 10 và cấu hình SendMail

1. Tải về các phần mềm cần cài đặt

  • Download Apache for Windows: https://www.apachelounge.com/download/
  • Download PHP 7 for Windows (chọn bản Thread Safe): http://windows.php.net/qa/
  • Download MySQL 8.0 for Windows (chọn bản ZIP Archive): http://dev.mysql.com/downloads/mysql/
  • Download phpMyAdmin: https://www.phpmyadmin.net/
  • Download bản cài đặt C++ Redistributable Visual Studio 2017 tương ứng với hệ điều hành Windows 64 bit hoặc 32 bit
  • Download bản cài đặt Visual C++ Redistributable Packages cho Visual Studio 2015 tại đây
Sau khi tải xong, chạy các file cài đặt Visual C++ vc_redist.x64.exevcredist_x64.exe

2. Tạo thư mục cài đặt

Đầu tiên hãy tạo một thư mục Server trong ổ C, sau đó tạo thư mục Bin trong thư mục Server (chúng ta sẽ cài đặt Apache, PHP và MySQL trong thư mục Bin).

3. Cài đặt Apache

Giải nén file cài đặt Apache (httpd-2.4.25-win64-VC14.zip) vào thư mục Apache24 năm trong thư mục C:\Server\bin\

Xong, mở file httpd.conf trong thư mục c:\Server\bin\Apache24\conf\ và sửa:

ServerRoot "c:/Apache24"

thành
ServerRoot "c:/Server/bin/Apache24"

Sửa
	
#ServerName www.example.com:80

thành
	
ServerName localhost

sửa
	
DocumentRoot "c:/Apache24/htdocs"

thành
	
DocumentRoot "c:/Server/data/htdocs/"

Sửa
	


thành
	


Sửa
	
DirectoryIndex index.html

thành
	
DirectoryIndex index.php index.html index.htm

Sửa
	
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None

thành
	
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All

Sửa
	
#LoadModule rewrite_module modules/mod_rewrite.so

thành
	
LoadModule rewrite_module modules/mod_rewrite.so

Lưu file httpd.conf. Đến đây bạn hoàn tất việc cấu hình Apache 2.4.

Mở cửa sổ Command Promt (Run cmd as Administrator. Có thể thực hiện bằng cách bấm đồng thời 2 phím Win + X rồi chọn Windows PowerShell (admin) .

Chạy các lệnh cài đặt Apache như hình dưới đây:

Hướng dẫn config apache php


Ở bước này nếu xuất hiện cửa sổ cảnh báo của Windows firewall thì chọn Allow access.

Như vây bạn đã cài đặt xong Apache.

Chú ý: Khi chạy Apache bạn cần tắt các dịch vụ (nhập lệnh services.msc trong hộp thoại Run) sau (nếu có): SQL Server Reporting Services (MSSQLSERVER), SQL Server VSS WriterWorld Wide Web Publishing Service

4. Cài đặt và cấu hình MySQL 8.0

Trong thư mục C:\Server\bin\ giải nén file zip mysql-8.0.11-winx64.zip và đổi tên thư mục giải nén thành MySql năm trong thư mục bin.

Mở Notepad tạo một file có nội dung như sau và lưu thành file my,ini trong thư mục C:\Server\bin\mysql:

	
[mysqld]
  
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
datadir="c:/Server/data/DB/data/"
default_authentication_plugin=mysql_native_password

Cấu hình MySQL xong, bây giờ chúng ta sẽ khởi tạo và cài đặt MySQL bằng cách mở Command Promt run as Administrator rồi chạy các lệnh sau:

	
C:\Server\bin\mysql\bin\mysqld --initialize-insecure --user=root
C:\Server\bin\mysql\bin\mysqld --install
net start mysql

Kết thúc việc cài đặt MySQL bạn sẽ có thư mục C:\Server\data\DB\data\ được tự động tạo ra, đồng thời MySQl sẽ tự động khởi chạy khi khởi động Windows.

Chú ý: Nếu trong quá trình cài đặt MySQL gặp lỗi dạng sau dẫn đến việc dịch vụ MySQL không thể chạy được:

	
[ERROR] InnoDB: Operating system error number 87 in a file operation
[ERROR] InnoDB: File .\ib_logfile101: 'aio write' return OS error 187.
[ERROR] InnoDB: Cannot continue operation

thì bạn cần xóa tất cả các file trong thư mục Data nói trên và thêm dòng sau vào file my.ini

	
innodb_flush_method=normal

sau đó khởi tạo lại MySQL bằng lệnh các lệnh sau:

	
C:\Server\bin\mysql-8.0\bin\mysqld --initialize-insecure --user=root
C:\Server\bin\mysql-8.0\bin\mysqld --install
net start mysql

5. Cài dặt PHP 7

Giải nén vào copy toàn bộ nội dung của file cài đặt php-7.1.1RC1-Win32-VC14-x64.zip vào thư mục PHP được tạo trong C:\Server\bin.

Mở lại file c:\Server\bin\Apache24\conf\httpd.conf vào thêm đoan sau vào cuối file:

	
PHPIniDir "C:/Server/bin/PHP"
AddHandler application/x-httpd-php .php
LoadModule php7_module "C:/Server/bin/PHP/php7apache2_4.dll"

Lưu fie httpd.conf.

Tao file info.php có nội dung như sau và lưu vào thư mục c:\Server\data\htdocs\ - đây là thư mục root của Apache:

	

Khởi động lại Apache bằng lệnh:

	
c:\Server\bin\Apache24\bin\httpd.exe -k restart

Mở trình duyệt gõ: http://localhost/info.php, bạn sẽ nhận được kết quả tương tự như hình dưới đây:

Hướng dẫn config apache php


6. Cấu hình PHP 7

Trong thư mục c:\Server\bin\PHP\, đổi tên file php.ini-development thành php.ini.

Mở file php.ini và sửa:

	
; extension_dir = "ext"

thành

	
extension_dir = "C:\Server\bin\PHP\ext\"

Sửa

	
;extension=bz2
;extension=curl
;extension=fileinfo
;extension=gd2
;extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
;extension=ldap
;extension=mbstring
;extension=exif      ; Must be after mbstring as it depends on it
;extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=openssl
;extension=pdo_firebird
;extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop

thành

	
extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
extension=gmp
extension=intl
extension=imap
;extension=interbase
extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
extension=pgsql
extension=shmop

Tiếp tục bỏ dấu comment của đoạn

	
;extension=soap
;extension=sockets
;extension=sqlite3
;extension=tidy
;extension=xmlrpc
;extension=xsl

thành

	
extension=soap
extension=sockets
extension=sqlite3
extension=tidy
extension=xmlrpc
extension=xsl

Lưu file php.ini và khởi động lại Apache. Như vậy, đã cài xong Apace, MySQL và PHP.

6. Cài đặt PHPMyAdmin

Trong thư mục C:\Server\data\htdocs\ copy nội dung giải nén của bộ cài đặt PHPMyAdmin (ví dụ phpMyAdmin-4.6.5.2-all-languages - chú ý bạn file download bản 4.6 trở lên) vào thư mục PhpMyAdmin được tạo trong htdocs

Trong thư mục C:\Server\data\htdocs\phpmyadmin\ tạo file config.inc.php có nội dung như sau:

	

Xong lưu file config.inc.php.
Mở trình duyệt và gõ địa chỉ http://localhost/phpmyadmin/, nhập username là root, password để trống, bấng nut Go

Nếu xuất hiện màn hình như dưới đây thì bạn đã cài đặt thành cồng PHPmyAdmin.

Hướng dẫn config apache php


7. Cấu hình gửi mail trên localhost

Trong thư mục C:\Server\bin\ tạo thư mục Sendmail. Trong thư mục Sendmail tạo file sendmail.exe có nội dung như sau:

	

Mở file C:\Server\bin\PHP\php.ini và thêm đoạn code dưới đây vào cuối file.

	
sendmail_path = "C:\Server\bin\PHP\php.exe C:\Server\bin\Sendmail\sendmail.php --dir C:\Server\bin\Sendmail\emails"

Lưu file php.ini và khởi động là Apache. Bây giờ các email được gửi từ localhost sé tự động lưu vào thư mục emails trong C:\Server\bin\Sendmail\emails\

Đến đây bạn đã hoàn thành việc cài đặt Apache 2.4, PHP 7, MySQL 8.0 và PHPMyAdmin trên Windows 10 và cấu hình gửi mail trên máy chủ localhost Apache.

[Nghean-Aptech]

Các tin mới hơn:

Hướng dẫn config apache php
Hướng dẫn tích hợp giao diện trang quản trị SB Admin 2 vào Laravel 5.8.

Hướng dẫn config apache php
Hướng dẫn tích hợp Google ReCaptcha v2 vào Laravel bằng curl.

Hướng dẫn config apache php
Học lập trình React JS trong vòng 5 phút.

Hướng dẫn config apache php
Sử dụng trình soạn thảo CKeditor tích hợp CKFinder với Laravel.

Các tin cũ hơn:

Hướng dẫn config apache php
Tạo ứng dụng MVC cơ bản với Laravel 5 trong 10 phút.

Hướng dẫn config apache php
Tìm hiểu PHP 7, có điều gì mới, và hơn thế nữa.

Hướng dẫn config apache php
Quy tắc viết mã cơ bản trong lập trình web với PHP.

Hướng dẫn config apache php
Tại sao Laravel là framework PHP phổ biến nhất để phát triển ứng dụng Web.

Hướng dẫn config apache php
Lộ trình để trở thành 1 Web Developer trong năm 2017.