Getting Started with symfony

Cấu hình Web Server

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


About

You are currently reading "Getting Started with symfony" which is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License license.

Tutorial Content

Master symfony

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Books on symfony

Learn more about symfony with the official guides.
books.sensiolabs.com

L'audit Qualité par SensioLabs

200 points de contrôle de votre applicatif web.
audit.sensiolabs.com

Chapter Content

Cách tồi

Cách bảo mật

Cấu hình Web Server

Kiểm tra cấu hình mới

symfony training
Be trained by symfony experts
May 29: Paris (Web Development with Symfony2 - Français)
May 31: Paris (Mastering Symfony2 - Français)
Jun 06: Paris (Introduction to Symfony2 - Français)
Jun 06: Paris (Introduction to Symfony2 - English)
Jun 06: Paris (Going Further with Symfony2 - English)
and more...

Search


powered by google
You are currently browsing "Getting Started with symfony" in for the 1.2 version - Switch to language:
Creative Commons License This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.

Cách tồi

Trong chương trước, chúng ta đã tạo một thư mục chứa project. Nếu bạn tạo nó trong thư mục web root, bạn đã có thể truy cập project từ trình duyệt.

Đó là một cách nhanh chóng và không cần phải cấu hình gì cả, nhưng thử truy cập file config/databases.yml từ trình duyệt để hiểu hậu quả của sự lười biếng này. Nếu người dùng biết được website được phát triển với symfony, anh ta có thể truy cập nhiều file nhạy cảm.

Không bao giờ sử dụng cách cài đặt này cho môi trường production server, và đọc mục tiếp theo để biết cách cấu hình đúng cho web server của bạn.

Cách bảo mật

Chỉ nên đặt trong thư mục web root những file có thể truy cập bởi trình duyệt, như file stylesheet, JavaScript và image. Mặc định, những file này nằm trong thư mục web/ của project symfony.

Thư mục này gồm các thư mục con css/, images/ và 2 file front controller. Các file front controller này là các file php duy nhất nằm trong thư mục web root. Tất cả các file PHP đều nên để ẩn đối với trình duyệt, và đó là cách tốt để bảo mật ứng dụng.

Cấu hình Web Server

Bây giờ hãy thay đổi cấu hình Apache để có thể truy cập project.

Mở file httpd.conf và thêm đoạn cấu hình sau vào cuối:

# Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080

# This is the configuration for your project
Listen 127.0.0.1:8080

<VirtualHost 127.0.0.1:8080>
  DocumentRoot "/home/sfproject/web"
  DirectoryIndex index.php
  <Directory "/home/sfproject/web">
    AllowOverride All
    Allow from All
  </Directory>

  Alias /sf /home/sfproject/lib/vendor/symfony/data/web/sf
  <Directory "/home/sfproject/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Alias /sf cho phép bạn truy cập file ảnh và javascript cần thiết để hiển thị các trang mặc định của symfony và web debug toolbar.

Ở Windows, bạn cần thay thế dòng Alias thành:

Alias /sf "c:\dev\sfproject\lib\vendor\symfony\data\web\sf"

/home/sfproject/web có thể thay thế bởi:

c:\dev\sfproject\web

Với cấu hình này, Apache sẽ lắng nghe cổng 8080, do đó website có thể truy cập theo đường dẫn sau:

http://localhost:8080/

Bạn có thể đổi cổng 8080 thành bất kì số nào lớn hơn 1024.

Kiểm tra cấu hình mới

Khởi động lại Apache, và kiểm tra xem bạn có thể truy cập ứng dụng chưa bằng cách mở trình duyệt và gõ http://localhost:8080/index.php/, hoặc http://sfproject.localhost/index.php/ tùy vào cấu hình bạn đã chọn ở mục trước.

Congratulations

Nếu module Apache mod_rewrite đã được cài đặt, bạn có thể bỏ đường dẫn index.php/ trên URL. Đó là nhờ cấu hình rewriting rule trong file web/.htaccess.

Bạn cũng có thể thử truy cập ứng dụng trong môi trường phát triển (xem phần tiếp theo để hiểu rõ hơn về các môi trường). Gõ đường dẫn sau:

http://sfproject.localhost/frontend_dev.php/

Web debug toolbar sẽ hiển thị ở góc phải, bao gồm các biểu tượng nhỏ nếu sf/ được cấu hình đúng.

web debug toolbar

Việc cài đặt có khác chút nếu bạn chạy symfony ở server IIS trong môi trường Windows. Bạn có thể đọc hướng dẫn cấu hình tại đây.

Các môi trường »
« Khởi tạo Project

Questions & Feedback

If you find a typo or an error, please register and open a ticket.

If you need support or have a technical question, please post to the official user mailing-list.