WhyInstalling the PHP module for Apache, including support for IPv6. Additional extensions will be installed and configured.
- Requirement: Apache
- Reference: PHP documentation
Build information
Ensure the following options:
[x] CGI Build CGI version [x] CLI Build CLI version [ ] DEBUG Build with debugging support [x] DTRACE Build with DTrace probes [x] EMBED Build embedded library [x] FPM Build FPM version [x] IPV6 IPv6 protocol support [x] LINKTHR Link thread lib (for threaded extensions) [x] MYSQLND Build with MySQL Native Driver [ ] NOASLR Disable ASLR support [x] PCRE Use system pcre instead of bundled one [ ] PHPDBG Interactive PHP debugger [x] ZTS Force Zend Thread Safety (ZTS) build
[x] BCMATH bc style precision math functions [ ] BZ2 bzip2 library support [ ] CALENDAR calendar conversion support [x] CTYPE ctype functions [x] CURL CURL support [ ] DBA dba support [x] DOM DOM support [ ] ENCHANT Enchant spelling support [x] EXIF EXIF support [ ] FFI Foreign Function Interface support [x] FILEINFO fileinfo support [x] FILTER input filter support [x] FTP FTP support [x] GD GD library support [ ] GETTEXT gettext library support [x] GMP GNU MP support [x] ICONV iconv support [x] IMAP IMAP support [x] INTL Internationalization(ICU) [x] LDAP OpenLDAP support [x] MBSTRING multibyte string support [x] MYSQLI MySQLi database support [ ] ODBC ODBC support [x] OPCACHE OPcache support [ ] PCNTL pcntl support (CLI only) [x] PDO PHP Data Objects Interface (PDO) [ ] PDO_DBLIB PDO DBLIB-DB driver [ ] PDO_FIREBIRD PDO Firebird driver [x] PDO_MYSQL PDO MySQL driver [ ] PDO_ODBC PDO ODBC driver [ ] PDO_PGSQL PDO PostgreSQL driver [x] PDO_SQLITE PDO sqlite driver [ ] PGSQL PostgreSQL database support [x] PHAR phar support [x] POSIX POSIX-like functions [ ] PSPELL pspell support [x] READLINE readline support (CLI only) [x] SESSION session support [ ] SHMOP shmop support [x] SIMPLEXML simplexml support [ ] SNMP SNMP support [ ] SOAP SOAP support [ ] SOCKETS sockets support [x] SODIUM Sodium encryption support [x] SQLITE3 sqlite3 support [ ] SYSVMSG System V message support [ ] SYSVSEM System V semaphore support [ ] SYSVSHM System V shared memory support [ ] TIDY TIDY support [x] TOKENIZER tokenizer support [x] XML XML support [x] XMLREADER XMLReader support [x] XMLWRITER XMLWriter support [x] XSL XSL support (Implies DOM) [ ] ZIP ZIP support [x] ZLIB ZLIB support
Configuration
The main configuration file is /usr/local/etc/php.ini, it is also
possible to define most of the values in the Apache configuration
using directives: php_flag, php_value,
php_admin_flag and php_admin_value.
php.ini
- Interpreter
-
PHP will not use the short form (ie:
<?) as it conflicts with processing instructions for XML documents.short_open_tag = Off
- Error handling
-
For a production system, errors and warnings will not be saved as they can be particularly numerous even if the code is functional.
display_errors = Off
- Memory
-
Limit memory usage to 20MB per web request.
memory_limit = 20M
- Files
-
Sending files is allowed, but limited to 2MB per file, the value of
post_max_sizeis also involved in sending file because the transfer is done by thePOST.file_uploads = On upload_max_filesize = 2M
- Timezone
-
For the correct operation of a number of applications, it is advisable to set the time zone. By default we choose
UTCas it is the international basis of civil time adopted by most countries worldwide.date.timezone = UTC
Module loading
The main Apache configuration is located in the
/usr/local/etc/apache24/ directory, for PHP it is essentially made of
the module loading and the association of the PHP engine with *.php
and *.phps files.
LoadModule php_module libexec/apache24/libphp.so
<IfModule php_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>
The module lost its version number in PHP 8: it registers as
php_module and installs as
libphp.so, where PHP 7 had
php7_module and
libphp7.so. It also moved out of the language
port into one of its own — www/mod_php83
and its siblings — so selecting an option in
lang/php83 no longer produces it.
application/x-httpd-php-source is unchanged and still
registered by the module.
It can be decided to not create the Includes/php.conf file.
In that case, it will only be required to add the corresponding line
in the website configuration, if it need to run PHP.
The line to be added being:
AddType application/x-httpd-php .php
Per-site directives
In case of PHP use, we wish to have the index file for directories to be processed by PHP. To achieve this we must specify the processing order of index files.
DirectoryIndex index.php index.html
Thereafter special directives in PHP can be used to change the values
of various configuration elements, some will allow overloading using
the .htaccess file, others do not. They are listed below:
| Overloadable | Not overloadable | |
|---|---|---|
| Value | php_value |
php_admin_value |
| Flag | php_flag |
php_admin_flag |
A configuration example, among others, is:
php_value error_log /web/www.example.com/log/php.log php_value default_mimetype 'text/html; charset=utf-8' php_value memory_limit 36M php_value session.save_path /web/www.example.com/session/ php_value open_basedir /web/www.example.com/content/ php_admin_flag display_errors off php_admin_flag file_uploads off