Table of content
  1. Configuration
    1. php.ini
    2. Apache
  2. Apache

Installing the PHP module for Apache, including support for IPv6. Additional extensions will be installed and configured.

Build information

Ensure the following options:

lang/php74
1
2
3
4
5
6
7
8
9
[x] CLI           Build CLI version
[x] CGI           Build CGI version
[x] FPM           Build FPM version
[x] EMBED         Build embedded library
[x] DTRACE        Build with DTrace probes
[x] IPV6          IPv6 protocol support
[x] MYSQLND       Build with MySQL Native Driver
[x] LINKTHR       Link thread lib (for threaded extensions)
[x] ZTS           Force Zend Thread Safety (ZTS) build
lang/php74-extensions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[x] BCMATH        bc style precision math functions
[x] BZ2           bzip2 library support
[x] CTYPE         ctype functions
[x] CURL          CURL support
[x] DOM           DOM support
[x] EXIF          EXIF support
[x] FILEINFO      fileinfo support
[x] FILTER        input filter support
[x] FTP           FTP support
[x] GD            GD library support
[x] GETTEXT       gettext library support
[x] GMP           GNU MP support
[x] ICONV         iconv support
[x] INTL          Internationalization(ICU)
[x] JSON          JavaScript Object Serialization support
[x] LDAP          OpenLDAP support
[x] MBSTRING      multibyte string support
[x] MYSQLI        MySQLi database support
[x] OPCACHE       OPcache support
[x] OPENSSL       OpenSSL support
[x] PDO           PHP Data Objects Interface (PDO)
[x] PDO_MYSQL     PDO MySQL driver
[x] PDO_SQLITE    PDO sqlite driver
[x] PHAR          phar support
[x] POSIX         POSIX-like functions
[x] SESSION       session support
[x] SIMPLEXML     simplexml support
[x] SODIUM        Sodium encryption support
[x] SQLITE3       sqlite3 support
[x] TOKENIZER     tokenizer support
[x] XML           XML support
[x] XMLREADER     XMLReader support
[x] XMLWRITER     XMLWriter support
[x] XSL           XSL support (Implies DOM)
[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.

php.ini
1
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.

php.ini
1
display_errors      = Off
Memory

Limit memory usage to 20MB per web request.

php.ini
1
memory_limit        = 20M
Files

Sending files is allowed, but limited to 2MB per file, the value of post_max_size is also involved in sending file because the transfer is done by the POST.

php.ini
1
2
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 UTC as it is the international basis of civil time adopted by most countries worldwide.

php.ini
1
date.timezone       = UTC

Apache

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.

httpd.conf
1
LoadModule php7_module                  libexec/apache24/libphp7.so
Includes/php.conf
1
2
3
4
<IfModule php7_module>
    AddType application/x-httpd-php        .php
    AddType application/x-httpd-php-source .phps
</IfModule>

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:

_website_.conf
1
AddType application/x-httpd-php .php

Apache

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.

_website_.conf
1
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
PHP directives in apache

A configuration example, among others, is:

_website_.conf
1
2
3
4
5
6
7
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