Kiểm soát cài đặt PHP với tệp Php.ini tùy chỉnh
Bài viết này mô tả cách sử dụng các tệp php.ini tùy chỉnh để kiểm soát cài đặt PHP cho trang web của bạn.
Bài viết này áp dụng cho các gói lưu trữ không quản lý TURBO với giao diện quản lý cPanel. Đối với các gói lưu trữ turbo, xin vui lòng xem bài viết này.
Thiết lập tệp Php.ini tùy chỉnh
Tệp Php.ini chứa các chỉ thị để kiểm soát nhiều cài đặt PHP. Bạn có thể thiết lập một hoặc nhiều tệp php.ini tùy chỉnh để xác định cách thức hoạt động của trang web của bạn. Ví dụ: bạn có thể có một tệp tùy chỉnh trong thư mục/home/username/public_html của bạn cho các trang chính của trang web của bạn và một tệp tùy chỉnh riêng trong thư mục/home/username/public_html/hình ảnh của bạn cho các tệp hình ảnh của trang web của bạn.
Để thiết lập tệp php.ini tùy chỉnh, hãy làm theo các bước sau:
- Đăng nhập vào cPanel.
Nếu bạn không biết cách đăng nhập vào tài khoản cPanel của mình, vui lòng xem bài viết này.
- Sử dụng trình quản lý tệp, điều hướng đến thư mục nơi bạn muốn sửa đổi hành vi của PHP. Theo mặc định, một php.ini tùy chỉnh chỉ ảnh hưởng đến thư mục có vị trí. & Nbsp;
- Nhấp vào nút Tệp trong thanh công cụ Trình quản lý tệp để tạo tệp mới và đặt tên cho nó Php.ini.
- Nhấp vào tệp mới và sau đó nhấp vào nút Chỉnh sửa trong thanh công cụ Trình quản lý tệp để chỉnh sửa Php.ini mới.
- Thêm các chỉ thị PHP vào php.ini mới và sau đó nhấp vào nút Lưu Thay đổi.
- Sau khi bạn tạo tệp php.ini và đặt quyền của nó, bạn có thể xác minh rằng cấu hình đang hoạt động. Để thực hiện việc này, hãy tạo tệp PHPINFO trong thư mục nơi bạn đã tạo Php.ini
- Tải tệp PHPINFO trong trình duyệt web của bạn và xác định vị trí một trong các chỉ thị bạn đặt. Đảm bảo các thay đổi được hiển thị.
- Bạn có thể tạo các tệp php.ini tùy chỉnh cho mỗi thư mục trong trang web của bạn, nhưng nhiều người định cấu hình cài đặt trong một tệp php.ini và sau đó áp dụng nó cho toàn bộ trang web. Để thực hiện điều này, hãy thêm dòng sau vào tệp .htaccess trong thư mục gốc tài liệu của trang web của bạn. Thay thế tên người dùng bằng tên người dùng lưu trữ A2 của bạn:
lsapi_phpini /home/username/public_html/php.ini
username with your A2 Hosting username:lsapi_phpini /home/username/public_html/php.ini
Thêm thông tin
Để xem danh sách đầy đủ các chỉ thị php.ini, vui lòng truy cập //www.php.net/manual/en/ini.list.php.
Tệp cấu hình [php.ini] được đọc khi PHP khởi động. Đối với các phiên bản mô -đun máy chủ của PHP, điều này chỉ xảy ra một lần khi máy chủ web được khởi động. Đối với các phiên bản CGI và CLI, nó xảy ra trên mỗi lần gọi.
Php.ini được tìm kiếm ở các địa điểm này [theo thứ tự]:
- Vị trí cụ thể của mô -đun SAPI [Chỉ thị
PHPIniDir
trong Apache 2,-c
Tùy chọn dòng lệnh trong CGI và CLI] - Biến môi trường PHPRC.
- Vị trí của tệp
php.ini
có thể được đặt cho các phiên bản khác nhau của PHP. Rễ của các khóa đăng ký phụ thuộc vào độ 32 hoặc 64 bit của HĐH và PHP đã cài đặt. Đối với PHP 32 bit trên HĐH 32 bit hoặc PHP 64 bit trên hệ điều hành 64 bit sử dụng[[HKEY_LOCAL_MACHINE\SOFTWARE\PHP]
cho phiên bản PHP 32 bit trên hệ điều hành 64 bit sử dụng[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP]
]. Đối với cùng một cài đặt bitness, các khóa đăng ký sau đây được kiểm tra theo thứ tự:[HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z]
, ____10 và; PHP_MEMORY_LIMIT is taken from environment memory_limit = ${PHP_MEMORY_LIMIT}
1, trong đó X, Y và Z có nghĩa là các phiên bản chính, nhỏ và phát hành PHP. Đối với 32 phiên bản PHP trên hệ điều hành 64 bit, các khóa đăng ký sau được kiểm tra theo thứ tự:; PHP_MEMORY_LIMIT is taken from environment memory_limit = ${PHP_MEMORY_LIMIT}
2,; PHP_MEMORY_LIMIT is taken from environment memory_limit = ${PHP_MEMORY_LIMIT}
3 và; PHP_MEMORY_LIMIT is taken from environment memory_limit = ${PHP_MEMORY_LIMIT}
4, trong đó X, Y và Z có nghĩa là các phiên bản chính, nhỏ và phát hành PHP. Nếu có giá trị cho; PHP_MEMORY_LIMIT is taken from environment memory_limit = ${PHP_MEMORY_LIMIT}
5 trong bất kỳ khóa nào trong số này, thì cái đầu tiên được tìm thấy sẽ được sử dụng làm vị trí củaphp.ini
[chỉ Windows]. -
; PHP_MEMORY_LIMIT is taken from environment memory_limit = ${PHP_MEMORY_LIMIT}
7 hoặc[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP]
, giá trị của; PHP_MEMORY_LIMIT is taken from environment memory_limit = ${PHP_MEMORY_LIMIT}
5 [chỉ Windows]. - Thư mục làm việc hiện tại [trừ CLI].
- Thư mục của máy chủ web [cho các mô -đun SAPI] hoặc thư mục của PHP [nếu không trong Windows].
- Thư mục Windows [C: \ Windows hoặc C: \ WINNT] [cho Windows] hoặc tùy chọn thời gian biên dịch
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"
0.
Nếu php-sapi.ini tồn tại [trong đó sapi là SAPI được sử dụng, vì vậy, ví dụ, php-cli.ini hoặc php-apache.ini], nó được sử dụng thay vì php.ini. Tên SAPI có thể được xác định bằng PHP_SAPI_NAME [].php_sapi_name[].
Ghi chú::
Máy chủ web Apache thay đổi thư mục thành root khi khởi động, khiến PHP cố gắng đọc php.ini từ hệ thống tập tin gốc nếu nó tồn tại.
Sử dụng các biến môi trường có thể được sử dụng trong php.ini như hình dưới đây.
Ví dụ #1 Biến môi trường Php.ini
; PHP_MEMORY_LIMIT is taken from environment memory_limit = ${PHP_MEMORY_LIMIT}
Các chỉ thị php.ini được xử lý bởi các tiện ích mở rộng được ghi lại trên các trang tương ứng của các phần mở rộng. Một danh sách các chỉ thị cốt lõi có sẵn trong Phụ lục. Không phải tất cả các chỉ thị PHP nhất thiết đều được ghi lại trong hướng dẫn này: Để biết danh sách đầy đủ các chỉ thị có sẵn trong phiên bản PHP của bạn, vui lòng đọc tệp PHP.ini được nhận xét tốt của bạn. Ngoài ra, bạn có thể tìm thấy »& nbsp; Php.ini mới nhất từ git cũng hữu ích.
Ví dụ #2 Php.ini ví dụ
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"
Có thể tham khảo các biến .ini hiện có từ các tệp .ini. Ví dụ:
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"1.
Thư mục quét
Có thể định cấu hình PHP để quét các tệp .ini trong thư mục sau khi đọc php.ini. Điều này có thể được thực hiện tại thời điểm biên dịch bằng cách đặt tùy chọn--with-config-scan-scan-DIR. Thư mục quét sau đó có thể được ghi đè tại thời gian chạy bằng cách đặt biến môi trường PHP_INI_SCAN_DIR.--with-config-file-scan-dir option. The scan directory can then be overridden at run time by setting the PHP_INI_SCAN_DIR environment variable.
Có thể quét nhiều thư mục bằng cách tách chúng bằng bộ phân cách đường dẫn dành riêng cho nền tảng [
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"2 trên Windows, NetWare và RISC OS;
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"3 trên tất cả các nền tảng khác; Php giá trị đang sử dụng có sẵn dưới dạng hằng số
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"4]. Nếu một thư mục trống được đưa ra trong PHP_INI_SCAN_DIR, PHP cũng sẽ quét thư mục được đưa ra tại thời điểm biên dịch thông qua--with-config-file-scan-dir.
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"4 constant]. If a blank directory is given in PHP_INI_SCAN_DIR, PHP will also scan the directory given at compile time via --with-config-file-scan-dir.
Trong mỗi thư mục, PHP sẽ quét tất cả các tệp kết thúc theo
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"5 theo thứ tự bảng chữ cái. Một danh sách các tệp đã được tải và theo thứ tự nào, có sẵn bằng cách gọi PHP_INI_SCPENT_FILES [] hoặc bằng cách chạy PHP với tùy chọn -ini.php_ini_scanned_files[], or by running PHP with the --ini option.
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.
Weili ¶ ¶
1 năm trước
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"6
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"7
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"8
OHCC tại 163 dot com ¶ ¶
6 năm trước
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"9
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.0
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.1
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.2
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.3
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.4
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.5
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.6
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.7
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.8
Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is :... $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.9
; any text on a line after an unquoted semicolon [;] is ignored [php] ; section markers [text within square brackets] are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"8