Tạo tên miền ảo trên localhost (Xampp)


Đầu tiên các bạn sẽ phải vào đường dẫn sau, mình đang cài xampp trên ổ E nhé: E:\xampp\apache\conf\extra và mở file httpd-vhosts.conf và tìm đến dòng NameVirtualHost *:80 nếu nó có dấu # đằng trc thì bỏ đi và thêm đoạn code sau vào:

<VirtualHost *:80>

ServerName mobile.loc
DocumentRoot “E:\xampp\htdocs\vidu”
<Directory “/Applications/XAMPP/xamppfiles/htdocs”>
</Directory>
</VirtualHost>

Đây chính là đoạn ta tạo tên miền ảo mobile.loc, các bạn chú ý E:\xampp\htdocs\vidu đoàn này là thư mục mà chứa project của chúng ta.

Tiếp theo vào đường dẫn: C:\Windows\System32\drivers\etc mở file host (cái này hay chỉnh để vào fb 🙂 ) và thêm vào đoạn code sau:

———–

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
127.0.0.1 mobile.loc <- thêm vào cái này

———–

OK! nếu bạn muốn thêm 1 domain mới nữa vào thì chỉ việc copy thêm đoạn này và sửa lại thông tin thôi 🙂

<VirtualHost *:80>

ServerName xxx.com
DocumentRoot “E:\xampp\htdocs\xxx”
<Directory “/Applications/XAMPP/xamppfiles/htdocs”>
</Directory>
</VirtualHost>

 

Nào hãy khỏi động lại xampp và tận hưởng thành quả nào!

Hãy để lại comment nếu bạn có gặp rắc rối nhé!

5 thoughts on “Tạo tên miền ảo trên localhost (Xampp)

  1. 1:14:13 PM [Apache] Error: Apache shutdown unexpectedly.
    1:14:13 PM [Apache] This may be due to a blocked port, missing dependencies,
    1:14:13 PM [Apache] improper privileges, a crash, or a shutdown by another method.
    1:14:13 PM [Apache] Press the Logs button to view error logs and check
    1:14:13 PM [Apache] the Windows Event Viewer for more clues
    1:14:13 PM [Apache] If you need more help, copy and post this
    1:14:13 PM [Apache] entire log window on the forums

    mình không khởi động apache được

    Liked by 1 person

  2. nếu không khởi động lại được xampp thì hãy đổi port vừa copy vào nhé

    ServerName mobile.loc
    DocumentRoot “E:\xampp\htdocs\vidu”

    đổi 80 thành con số bất kỳ

    Liked by 1 person

Để lại comment đê!