Hiển thị các bài đăng có nhãn Xampp. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Xampp. Hiển thị tất cả bài đăng

Thứ Năm, 27 tháng 12, 2012

Setting Up Virtual Hosts for XAMPP


Running a Web server on your desktop computer is a great way to speed up Web site development. By previewing your Web pages directly through a Web server on your own computer you can test out server-side programming like server-side include files, form processing scripts, or database-driven Web pages. However, there’s one problem associated with running a server on your own computer: by default, you only have a single "domain"–http://localhost/–so if you work on more than one Web site you put them all under "localhost" in different directories. This isn’t very real world and can cause problems when using server-side includes and root-relative links. Fortunately there’s a better way.
For information on setting up XAMPP, visit the XAMPP instructions page.

Virtual Hosts

Virtual Hosts give you the ability to "host" more than one Web site and domain on your computer. With a virtual host you can have separate local domain names for each of your Web sites: for example, http://clientA/ for one site and http://clientB/ for another. When you type the URL for the Virtual Host in your Web browser, the browser doesn’t go out onto the internet to find the site, but instead asks for the proper file from the Web server running on your computer. Not only does a Virtual Host let you run multiple Web sites on your computer, but it also lets you store the files for those sites anywhere on your computer and not just in the C:\XAMPP\htdocs folder.
Adding a Virtual Host is a 2-step process:
  1. Add a new entry to your computer’s hosts file.
    A hosts file can be used to point requests for a domain to a particular IP addressin other words, it lets you re-direct communications to a particular domain. In the case of a virtual host, it can tell the computer to NOT go out on the internet when you type a particular URL like http://clientA/, but instead look for that particular domain on your own computer.
  2. Edit the Apache configuration file to accept Virtual Hosts and define the particular Virtual Hosts you want to setup on your computer.
    The first step above, merely redirects requests from a particular domain to your computer, but this step prepares the Web server on your computer for handling those requests. In this step, you not only provide the name of the Virtual Host, but also tell Apache where the files for the site are located on your computer.

Detailed Steps

  1. Launch Notepad and open the hosts file located at C:\windows\system32\drivers\etc\hosts. (You may not be able to see the windows folder–some files are hidden by default under Windows. Here are instructions to make those files visible.)
    On Vista, you’ll also need to have access to change the hosts file. To do that, launch Notepad by right clicking on Notepad from the Start menu and choosing "Run As Administrator." This will give you permission to edit and save the file.
  2. At the end of that file type:
    127.0.0.1      clientA.local
    127.0.0.1 is how a computer refers to itself—it’s an IP address that points back to the computer, kind of like a computer’s way of saying "ME." The second part (clientA.local) is the "domain" of the virtual host. To visit this domain in a Web browser you’d type http://clientA.local. You don’t have to add the .local part to the hosts files—you could just as easily add 127.0.0.1 clientA and access the site in your Web browser withhttp://clientA—but I find it helpful for differentiating between a real Web site out on the Internet like clientA.com, and the test sites I have running on my own computer.
  3. Save and close the hosts file.
    That finishes the first part of this task. You’ve prepared your computer to handle requests to http://clientA.local. Now you need to tell the Web server, Apache, how to handle those requests.
  4. In Notepad open the Apache configuration file located at C:\xampp\apache\conf\extra\httpd-vhosts.conf
  5. At the bottom of that file add:
    NameVirtualHost *
      <VirtualHost *>
        DocumentRoot "C:\xampp\htdocs"
        ServerName localhost
      </VirtualHost>
      <VirtualHost *>
        DocumentRoot "C:\Documents and Settings\Me\My Documents\clientA\website"
        ServerName clientA.local
      <Directory "C:\Documents and Settings\Me\My Documents\clientA\website">
        Order allow,deny
        Allow from all
      </Directory>
    </VirtualHost>
      
    The first five lines of code turn on the Virtual Host feature on Apache, and set up the C:\xampp\htdocs folder as the default location for http://localhost. That’s important since you need to be able to access the XAMPP web pages at http://localhost/ so that you can use PHPMyAdmin.
    The stuff in yellow represents a single Virtual Host. You’ll add one chunk of code just like this for each Virtual Host (or Web site) on your computer
    You’ll need to modify the stuff highlighted in blue. The first item — DocumentRoot — indicates where the files for this site are located on your computer. The second part–ServerName — is the name you provided in step 2 above: the virtual host name. For example, clientA.local. The third item — the <Directory> part — is the same path you provided for the DocumentRoot. This is required to let your Web browser have clearance to access these files.
  6. Save and close the Apache configuration file, and restart Apache from the XAMPP control panel.
  7. Start a Web browser and type a URL for the virtual host. For example: http://clientA.local/.
    You should now see the home page for your site.

More Virtual Hosts

If you want to add additional Virtual hosts add the proper entry to the hosts file and add another block of text like that in yellow above to the Apache configuration file. For example, say you had another Web site for ClientB. You’d add 127.0.0.1    clientB.local in the hosts file and the C:\xampp\apache\conf\extra\httpd-vhosts.conf would look like this:
NameVirtualHost *
  <VirtualHost *>
    DocumentRoot "C:\xampp\htdocs"
    ServerName localhost
  </VirtualHost>
  <VirtualHost *>
    DocumentRoot "C:\Documents and Settings\Me\My Documents\clientA\website"
    ServerName clientA.local
  <Directory "C:\Documents and Settings\Me\My Documents\clientA\website">
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>
<VirtualHost *>
    DocumentRoot "C:\Documents and Settings\Me\My Documents\clientB\website"
    ServerName clientB.local
  <Directory "C:\Documents and Settings\Me\My Documents\clientB\website">
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>
  

More Information


Source: http://sawmac.com/xampp/virtualhosts/

Thứ Sáu, 7 tháng 12, 2012

Tạo Home Server với XAMPP


* Việc tạo hosting tại nhà giúp công việc quản lý và sử dụng được dễ dàng và nhanh chóng.
* Chi phí hoạt động rẻ, không mất chi phí thuê host, không mất thời gian upload lên host,….
* Có thể tự điều chỉnh các tính năng ứng dụng mở rộng của host.
* Hoạt động trực tuyến trên Internet , mọi người có thể truy cập vào máy chủ của bạn trên khắp mọi nơi
* Yêu cầu máy có cấu hình trung bình, Modem hỗ trợ virtual server, và hoạt động liên tục để duy trì
hosting
“ Các bước chuẩn bị tạo host :
¢ Chuẩn bị Server : đây là chương trình hỗ trợ : Apache,PHP, MySQL, Python, perl.
>> Sử Dụng XAMPP ( Open Source) : Home & Download
¢ Công cụ chỉnh sửa : dùng để thay chỉnh sửa nội dung tệp tin được dễ dàng hơn.
>> Sử dụng Notepad ++ vì đây là open source : Home & Download
¢ Thông số MODEM : xem modem kết nối internet có hỗ trợ virtual Server không ?
–> Gõ 192.168.1.1 đề vào cấu hình Modem –> sau đó vào Avanced setup –> click vào tab NAT
xem có Virtual server. ( Hầu hết các Modem hiện nay đều có)
¢ Chuẩn bị DNS : khi sử dụng internet dùng gói cước các nhân hộ gia đình, … thì nhà cung cấp dịch vụ sẽ cấp phát địa chỉ IP động ( Mỗi ngày sẽ có 1 IP khác nhau). do đó ta cần phải có thiết lập
DNS để thay thế cho IP tĩnh mà ta không có. ( Chi phí để có IP tĩnh cũng khá đắt so với người dùng chỉ sử dụng internet thông thường ).
+ Sử dụng DNS quốc tế miễn phí tại : No-IP và DynDNS
+ Tại việt nam : VDNS và Pro

“ Cài đặt & Cấu Hình Server:
Bước 1 : Cài đặt Server sử dụng XAMPP :
- Mở Setup XAMPP và tiến hành cài đặt
Step+XAmpp+1 Tạo Home Server tại nhà để chạy Website
- Chọn nơi chứa bộ cài và bắt đầu cài đặt
Step+XAmpp+2 Tạo Home Server tại nhà để chạy Website
- Tùy chọn dịch vụ sau đó ấn Install để hoàn tất. 
+ Tích vào các ô : Install Apache as services và Install MySQL
Step+XAmpp+3 Tạo Home Server tại nhà để chạy Website
- Kích vào biểu tượng XAMPP trên desktop xem các services đã hoạt động chưa.
Step+XAmpp+4 Tạo Home Server tại nhà để chạy Website
—> Nếu đã giống trong hình thì việc cài XAMPP đã thành công.
Bước 2 : Cấu hình Virtual Server trong Modem
- Trước tiên cần xác lập địa chỉ IP trong LAN bằng cách : Vào Run gõ cmd rồi sử dụng lệnh
ipconfig/all 
- khi đã biết được địa chỉ IP máy ta tiến hành truy xuất vào cấu hình Modem : 192.168.1.1
điền toàn khoản và mật khẩu sử dụng.
- Sau đó chọn Avanced Setup –> Tab NAT :
Modem+1 Tạo Home Server tại nhà để chạy Website

- Click vào Virtual Server : làm theo trong hình
+ Điền địa chỉ IP máy ( Trong LAN dùng IP tĩnh / động đều được cả miễn là kết nối được với internet ).
+ Chọn cổng 80 vì đây là dành cho HTTP server.
+ Chọn kiểu để biết và dễ dàng phân biệt.
Modem+2 Tạo Home Server tại nhà để chạy Website

-> Chú ý : làm đúng theo hướng dẫn và hình minh họa. để có thể thực hiện thành công.
Bước 3 : Đăng ký tên miền sử dụng DNS
- Để thuận tiện tôi sử dụng tên miền DNS của NO-IP : No-IP , được phép đăng ký sử dụng tối đa
3 Hosts / Acc
+ Tạo 1 tài khoản đăng nhập : Register
+ Đăng nhập vào tài khoản : Login
- khi đã đăng nhập , trên giao diện quản lý ta thấy :
DNS Tạo Home Server tại nhà để chạy Website

- Chỉ quan tâm đến phần Add hosts và Manager Hosts.
- Nếu chưa có HOSTS ta vào phần Add Hosts
+ chon tên host phù hợp
+ Sau đó giữ nguyên moi thông số như trong hình và Create Hosts
DND+1 Tạo Home Server tại nhà để chạy Website

- khi tạo xong ta vào mục Manager HOsts :
DND+2 Tạo Home Server tại nhà để chạy Website

–> Ghi nhớ tên Host vừa tạo để sử dụng trong config server.
Bước 4 : Hoàn thiện config server
->> Trước khi Config ta vào giao diện XAMPP và Stop Apache
- Cấu hình HOSTS File : tệp tin này nằm trong C:/Windows/System32/drivers/etc/hosts
>> dùng Notepad ++ để mở ra và chỉnh sửa .
+ Tại hosts file này ta thêm dòng lệnh mới như sau:
127.0.0.1 Tên HOSTS ta đã tạo ở NO-IP
Ví dụ : 127.0.0.1 phimhoathinh.zapto.org
- Cấu hình XAMPP:
+ Chỉ định ROOT : bằng cách chỉnh sửa tệp tin HTTPD-VHOSTS.CONF. tệp tin này nằm trong thư mục C:/xampp/apache/conf/extra/ . 
* Tệp tin này rất quan trong cho việc xác định nơi chứa website. bạn có thể đặt được ở bất kỳ ở 
đâu chỉ cần bạn trỏ đúng liên kết. Bạn thiết lập đường dẫn ởDocumentRoot “”
Trong tệp tin này ta thêm dòng thiết lập như sau.
<VirtualHost *:80>
ServerAdmin mrchucong@gmail.com
DocumentRoot “E:\WebMaster\Source\chatbox“
ServerName phimhoathinh.zapto.org
ServerAlias phimhoathinh.zapto.org
#ErrorLog “logs/dummy-host2.localhost-error.log”
#CustomLog “logs/dummy-host2.localhost-access.log” combined
</VirtualHost>
+ Thiết Lập Quyền Hạn Truy Cập : thiết lập bằng cách chỉnh sửa tệp tinHTTPD.CONF. tệp tin
nằm trong thư mục C:/xampp/apache/conf/ .
>> Tệp tin này giúp xác đinh quền hạn truy cập với từng mức độ. nếu cho phép truy cập thì chọn
allow from all . còn không thì chọn Deny from all
Trong tệp tin này bạn thêm dòng lệnh sau
alias /chatbox “E:\WebMaster\Source\chatbox”
<directory “E:\WebMaster\Source\chatbox“>
allowoverride all
order allow,deny
allow from all
</directory>
>>>>>>> Sau khi Config xong bạn vào XAMPP và Start Apache.
>>>>>>>>>>> Chúc các bạn thành công !!!
Nguồn vn-zoom.com