PHP
Last Updated on 2017-07-02 by Sture
Description
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
WWW: http://www.php.net.
Requirements
The following application(s) must be installed, configured and running before PHP is installed:
Preparation for Installation
Start PuTTY on a Windows PC, Terminal on a Mac or similar terminal application on a Linux PC.
In this example Terminal on a Mac is used.
Open a remote SSH session to the server with:
Mac:~ user$ ssh user@192.168.1.4 [enter]
N.B.: Replace user@192.168.1.4 with User ID and IP Address on Your server!
[user@server ~]$
Enable superuser privileges with:
[user@server ~]$ sudo -s [enter]
Password: <-- passwd [enter]
[root@server /usr/home/user]#
N.B.: Enter user password, not the root password!
Installation
N.B.: Current version of Appache will be installed if missing!
Search for “mod_php” in the remote package repositories with:
[root@server /usr/home/user]# pkg search "mod_php" [enter]
mod_php56-5.6.30 PHP Scripting Language
mod_php70-7.0.20_1 PHP Scripting Language
mod_php71-7.1.6_1 PHP Scripting Language
[root@server /usr/home/user]#
In this example php71, php71-extensions and mod_php71 will be installed with;
[root@server /usr/home/user]# pkg install php71 php71-extensions mod_php71 [enter]
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 27 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
php71: 7.1.6_1
php71-extensions: 1.0
mod_php71: 7.1.6_1
libxml2: 2.9.4
php71-session: 7.1.6_1
php71-opcache: 7.1.6_1
php71-xmlwriter: 7.1.6_1
php71-xmlreader: 7.1.6_1
php71-dom: 7.1.6_1
php71-xml: 7.1.6_1
php71-simplexml: 7.1.6_1
php71-ctype: 7.1.6_1
php71-posix: 7.1.6_1
php71-hash: 7.1.6_1
php71-filter: 7.1.6_1
php71-tokenizer: 7.1.6_1
php71-json: 7.1.6_1
php71-sqlite3: 7.1.6_1
sqlite3: 3.19.3_1
php71-pdo_sqlite: 7.1.6_1
php71-pdo: 7.1.6_1
php71-iconv: 7.1.6_1
php71-phar: 7.1.6_1
apache24: 2.4.26
apr: 1.5.2.1.5.4_2
gdbm: 1.13_1
db5: 5.3.28_6
Number of packages to be installed: 27
The process will require 109 MiB more space.
23 MiB to be downloaded.
Proceed with this action? [y/N]: y
[1/27] Fetching php71-7.1.6_1.txz: 100% 2 MiB 2.2MB/s 00:01
[2/27] Fetching php71-extensions-1.0.txz: 100% 1 KiB 1.1kB/s 00:01
[3/27] Fetching mod_php71-7.1.6_1.txz: 100% 1 MiB 1.2MB/s 00:01
[4/27] Fetching libxml2-2.9.4.txz: 100% 802 KiB 821.1kB/s 00:01
[5/27] Fetching php71-session-7.1.6_1.txz: 100% 31 KiB 32.3kB/s 00:01
[6/27] Fetching php71-opcache-7.1.6_1.txz: 100% 137 KiB 140.0kB/s 00:01
[7/27] Fetching php71-xmlwriter-7.1.6_1.txz: 100% 13 KiB 13.1kB/s 00:01
[8/27] Fetching php71-xmlreader-7.1.6_1.txz: 100% 13 KiB 12.9kB/s 00:01
[9/27] Fetching php71-dom-7.1.6_1.txz: 100% 54 KiB 55.4kB/s 00:01
[10/27] Fetching php71-xml-7.1.6_1.txz: 100% 20 KiB 20.1kB/s 00:01
[11/27] Fetching php71-simplexml-7.1.6_1.txz: 100% 23 KiB 23.3kB/s 00:01
[12/27] Fetching php71-ctype-7.1.6_1.txz: 100% 6 KiB 6.6kB/s 00:01
[13/27] Fetching php71-posix-7.1.6_1.txz: 100% 11 KiB 11.4kB/s 00:01
[14/27] Fetching php71-hash-7.1.6_1.txz: 100% 118 KiB 121.3kB/s 00:01
[15/27] Fetching php71-filter-7.1.6_1.txz: 100% 18 KiB 18.9kB/s 00:01
[16/27] Fetching php71-tokenizer-7.1.6_1.txz: 100% 9 KiB 8.8kB/s 00:01
[17/27] Fetching php71-json-7.1.6_1.txz: 100% 20 KiB 20.4kB/s 00:01
[18/27] Fetching php71-sqlite3-7.1.6_1.txz: 100% 17 KiB 17.9kB/s 00:01
[19/27] Fetching sqlite3-3.19.3_1.txz: 100% 707 KiB 723.9kB/s 00:01
[20/27] Fetching php71-pdo_sqlite-7.1.6_1.txz: 100% 12 KiB 12.1kB/s 00:01
[21/27] Fetching php71-pdo-7.1.6_1.txz: 100% 43 KiB 44.1kB/s 00:01
[22/27] Fetching php71-iconv-7.1.6_1.txz: 100% 18 KiB 18.0kB/s 00:01
[23/27] Fetching php71-phar-7.1.6_1.txz: 100% 102 KiB 104.2kB/s 00:01
[24/27] Fetching apache24-2.4.26.txz: 100% 5 MiB 5.0MB/s 00:01
[25/27] Fetching apr-1.5.2.1.5.4_2.txz: 100% 410 KiB 419.7kB/s 00:01
[26/27] Fetching gdbm-1.13_1.txz: 100% 150 KiB 153.5kB/s 00:01
[27/27] Fetching db5-5.3.28_6.txz: 100% 12 MiB 6.4MB/s 00:02
Checking integrity... done (0 conflicting)
[1/27] Installing libxml2-2.9.4...
[1/27] Extracting libxml2-2.9.4: 100%
[2/27] Installing php71-7.1.6_1...
[2/27] Extracting php71-7.1.6_1: 100%
[3/27] Installing gdbm-1.13_1...
[3/27] Extracting gdbm-1.13_1: 100%
[4/27] Installing db5-5.3.28_6...
[4/27] Extracting db5-5.3.28_6: 100%
[5/27] Installing php71-dom-7.1.6_1...
[5/27] Extracting php71-dom-7.1.6_1: 100%
[6/27] Installing php71-hash-7.1.6_1...
[6/27] Extracting php71-hash-7.1.6_1: 100%
[7/27] Installing sqlite3-3.19.3_1...
[7/27] Extracting sqlite3-3.19.3_1: 100%
[8/27] Installing php71-pdo-7.1.6_1...
[8/27] Extracting php71-pdo-7.1.6_1: 100%
[9/27] Installing apr-1.5.2.1.5.4_2...
[9/27] Extracting apr-1.5.2.1.5.4_2: 100%
[10/27] Installing php71-session-7.1.6_1...
[10/27] Extracting php71-session-7.1.6_1: 100%
[11/27] Installing php71-opcache-7.1.6_1...
[11/27] Extracting php71-opcache-7.1.6_1: 100%
[12/27] Installing php71-xmlwriter-7.1.6_1...
[12/27] Extracting php71-xmlwriter-7.1.6_1: 100%
[13/27] Installing php71-xmlreader-7.1.6_1...
[13/27] Extracting php71-xmlreader-7.1.6_1: 100%
[14/27] Installing php71-xml-7.1.6_1...
[14/27] Extracting php71-xml-7.1.6_1: 100%
[15/27] Installing php71-simplexml-7.1.6_1...
[15/27] Extracting php71-simplexml-7.1.6_1: 100%
[16/27] Installing php71-ctype-7.1.6_1...
[16/27] Extracting php71-ctype-7.1.6_1: 100%
[17/27] Installing php71-posix-7.1.6_1...
[17/27] Extracting php71-posix-7.1.6_1: 100%
[18/27] Installing php71-filter-7.1.6_1...
[18/27] Extracting php71-filter-7.1.6_1: 100%
[19/27] Installing php71-tokenizer-7.1.6_1...
[19/27] Extracting php71-tokenizer-7.1.6_1: 100%
[20/27] Installing php71-json-7.1.6_1...
[20/27] Extracting php71-json-7.1.6_1: 100%
[21/27] Installing php71-sqlite3-7.1.6_1...
[21/27] Extracting php71-sqlite3-7.1.6_1: 100%
[22/27] Installing php71-pdo_sqlite-7.1.6_1...
[22/27] Extracting php71-pdo_sqlite-7.1.6_1: 100%
[23/27] Installing php71-iconv-7.1.6_1...
[23/27] Extracting php71-iconv-7.1.6_1: 100%
[24/27] Installing php71-phar-7.1.6_1...
[24/27] Extracting php71-phar-7.1.6_1: 100%
[25/27] Installing apache24-2.4.26...
===> Creating groups.
Using existing group 'www'.
===> Creating users
Using existing user 'www'.
[25/27] Extracting apache24-2.4.26: 100%
[26/27] Installing php71-extensions-1.0...
[27/27] Installing mod_php71-7.1.6_1...
Extracting mod_php71-7.1.6_1: 100%
[activating module `php7' in /usr/local/etc/apache24/httpd.conf]
Message from php71-dom-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-dom.ini
configuration file to automatically load the installed extension:
extension=dom.so
****************************************************************************
Message from php71-hash-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-hash.ini
configuration file to automatically load the installed extension:
extension=hash.so
****************************************************************************
Message from php71-pdo-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-pdo.ini
configuration file to automatically load the installed extension:
extension=pdo.so
****************************************************************************
Message from php71-session-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-18-session.ini
configuration file to automatically load the installed extension:
extension=session.so
****************************************************************************
Message from php71-opcache-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-10-opcache.ini
configuration file to automatically load the installed extension:
zend_extension=opcache.so
****************************************************************************
Message from php71-xmlwriter-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-xmlwriter.ini
configuration file to automatically load the installed extension:
extension=xmlwriter.so
****************************************************************************
Message from php71-xmlreader-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-30-xmlreader.ini
configuration file to automatically load the installed extension:
extension=xmlreader.so
****************************************************************************
Message from php71-xml-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-xml.ini
configuration file to automatically load the installed extension:
extension=xml.so
****************************************************************************
Message from php71-simplexml-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-simplexml.ini
configuration file to automatically load the installed extension:
extension=simplexml.so
****************************************************************************
Message from php71-ctype-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-ctype.ini
configuration file to automatically load the installed extension:
extension=ctype.so
****************************************************************************
Message from php71-posix-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-posix.ini
configuration file to automatically load the installed extension:
extension=posix.so
****************************************************************************
Message from php71-filter-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-filter.ini
configuration file to automatically load the installed extension:
extension=filter.so
****************************************************************************
Message from php71-tokenizer-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-tokenizer.ini
configuration file to automatically load the installed extension:
extension=tokenizer.so
****************************************************************************
Message from php71-json-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-json.ini
configuration file to automatically load the installed extension:
extension=json.so
****************************************************************************
Message from php71-sqlite3-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-sqlite3.ini
configuration file to automatically load the installed extension:
extension=sqlite3.so
****************************************************************************
Message from php71-pdo_sqlite-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-30-pdo_sqlite.ini
configuration file to automatically load the installed extension:
extension=pdo_sqlite.so
****************************************************************************
Message from php71-iconv-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-20-iconv.ini
configuration file to automatically load the installed extension:
extension=iconv.so
****************************************************************************
Message from php71-phar-7.1.6_1:
****************************************************************************
The following line has been added to your /usr/local/etc/php/ext-30-phar.ini
configuration file to automatically load the installed extension:
extension=phar.so
****************************************************************************
Message from apache24-2.4.26:
To run apache www server from startup, add apache24_enable="yes"
in your /etc/rc.conf. Extra options can be found in startup script.
Your hostname must be resolvable using at least 1 mechanism in
/etc/nsswitch.conf typically DNS or /etc/hosts or apache might
have issues starting depending on the modules you are using.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- apache24 default build changed from static MPM to modular MPM
- more modules are now enabled per default in the port
- icons and error pages moved from WWWDIR to DATADIR
If build with modular MPM and no MPM is activated in
httpd.conf, then mpm_prefork will be activated as default
MPM in etc/apache24/modules.d to keep compatibility with
existing php/perl/python modules!
Please compare the existing httpd.conf with httpd.conf.sample
and merge missing modules/instructions into httpd.conf!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Message from mod_php71-7.1.6_1:
***************************************************************
Make sure index.php is part of your DirectoryIndex.
You should add the following to your Apache configuration file:
SetHandler application/x-httpd-php
SetHandler application/x-httpd-php-source
***************************************************************
[root@server /usr/home/user]#
Configuration
Create a configurations file for PHP from the recommended production template file with:
[root@server /usr/home/user]# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini [enter]
[root@server /usr/home/user]#
…and then edit /usr/local/etc/php.ini to meet your demands with:
[root@server /usr/home/user]# ee /usr/local/etc/php.ini [enter]
Got to line 663 and increase post_max_size from 8M to 32M;
; Maximum size of POST data that PHP will accept.
; http://php.net/post-max-size
post_max_size = 32M
Exit ee by pressing <esc> and save your changes.
Create an Includes configuration file, /usr/local/etc/apache24/Includes/php.conf, with:
[root@server /usr/home/user]# ee /usr/local/etc/apache24/Includes/php.conf [enter]
…and add the following text:
<IfModule dir_module>
DirectoryIndex index.php index.shtml index.html
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
</IfModule>
Exit ee by pressing <esc> and save your changes.
PHP Locale Settings
Display current active locale setting on the system with:
[root@server /usr/home/user]# locale [enter]
LANG=en_SE.UTF-8
LC_CTYPE="en_SE.UTF-8"
LC_COLLATE="en_SE.UTF-8"
LC_TIME="en_SE.UTF-8"
LC_NUMERIC="en_SE.UTF-8"
LC_MONETARY="en_SE.UTF-8"
LC_MESSAGES="en_SE.UTF-8"
LC_ALL=
[root@server /usr/home/user]#
You can list all UTF-8 locales on the system with:
[root@server /usr/home/user]# locale -a | grep '\.UTF-8$' [enter]
Locale settings for the server in this example is en_SE.UTF-8. This is a customized locale setting based on en_US.UTF-8 with modified TIME settings for 24h only display and with Swedish MONITARY and NUMERIC settings.
PHP will not read the locale settings when the charset type is appended to the locale name. ( ie: sv_SE.ISO8859-1, en_SE.UTF-8 ). The solution is to create a symbolic link to the selected locale directory.
Create a symbolic link to en_SE with:
[root@server /usr/home/user]# ln -s /usr/share/locale/en_SE.UTF-8 /usr/share/locale/en_SE [enter]
Restart Apache Service
Restart apache24 with:
[root@server /usr/home/user]# service apache24 restart [enter]
Performing sanity check on apache24 configuration:
Syntax OK
Stopping apache24.
Waiting for PIDS: 1302.
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.
[root@server /usr/home/user]#
Test your PHP installation
Create a test file with:
[root@server /usr/home/user]# echo "<?php phpinfo() ?>" > /usr/local/www/apache24/data/info.php [enter]
…then point your browser to: http://www.example.net/info.php.
Compiled in Modules
Show compiled in modules with:
[root@server /usr/home/user]# php -m [enter]
[PHP Modules]
Core
ctype
date
dom
filter
hash
iconv
json
libxml
mysqlnd
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
[Zend Modules]
Zend OPcache
[root@server /usr/home/user]#