Odynia.org blog
  • Home
  • Apple / Mac / iOS
    • iOS
    • iTransit
  • General
    • Dukan Diet
  • Web Development
    • Microsoft CRM
    • Xnyo
    • PHP
  • Unix / BSD
    • Server Build

Installing Apache and Its Ecosystem: Part 2

Jul13th
2012
avatar Written by Rob

Back here in Apache Land it is time to continue with the install. In this post I’ll be installing PHP. Part 3 will cover Subversion, and Part 4 I’ll be running through my standard configuration and website setup.

Installing PHP 5.4.4

At the time of writing PHP 5.4.4 is the current stable release of PHP, so we’ll be installing that and a dozen or so modules. I used to be a PHP developer in a past life (or so it feels, sometimes) so there are a lot of modules I used to make regular use of.

Additionally, I run a lot of the usual software like WordPress, Roundcube,  Gallery2, WebSVN, etc.

A quick look at the modules installed on Tyrande (the existing server):

Shell
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[root@tyrande /]$ php -m
# [PHP Modules]
# bz2
# Core
# ctype
# curl
# date
# dom
# ereg
# fileinfo
# filter
# gd
# gettext
# hash
# iconv
# imap
# json
# ldap
# libxml
# mbstring
# mcrypt
# mhash
# mysql
# mysqli
# openssl
# pcre
# PDO
# pdo_mysql
# pdo_pgsql
# pdo_sqlite
# pgsql
# posix
# Reflection
# session
# SimpleXML
# snmp
# soap
# sockets
# SPL
# SQLite
# ssh2
# standard
# tidy
# tokenizer
# xml
# xmlreader
# xmlwriter
# zip
# zlib
#
# [Zend Modules]
[root@tyrande /]$

Read on for full installation instructions..

Back on Shana, let’s go installing! We’ll be using the ports tree for the installation, so make sure it is up to date.

We want the following options in the port config:

  • CLI (default)
  • APACHE
  • IPV6 (default)
  • LINKTHR (default)

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@shana /]$ cd /usr/ports/lang/php5
[root@shana /usr/ports/lang/php5]$ make install clean
# ===>  License PHP301 accepted by the user
# ===>  Found saved configuration for php5-5.4.4
# => php-5.4.4.tar.bz2 doesn't seem to exist in /usr/ports/distfiles/.
# <snip>
# ***************************************************************
#
# Make sure index.php is part of your DirectoryIndex.
#
# You should add the following to your Apache configuration file:
#
# AddType application/x-httpd-php .php
# AddType application/x-httpd-php-source .phps
#
# ***************************************************************
# <snip>
# ===>  Cleaning for apache-2.2.22_5
# ===>  Cleaning for php5-5.4.4

Once we’ve installed PHP we can check what modules are installed by default:

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@shana /usr/ports/lang/php5]$ php -m
# [PHP Modules]
# Core
# date
# ereg
# libxml
# mysqlnd
# pcre
# Reflection
# SPL
# standard
#
# [Zend Modules]

Not many at all. Fortunately, installing the rest is easy, if a little bit time consuming. Lets start with bz2.

Installing PHP Modules

Modules are available to be installed through ports also. This is rather useful as it will check for dependencies and install those if necessary. To install a module, you need to locate its port. The ports are generally named php5-<modulename>, like so:

Shell
1
2
[root@shana /usr/ports/lang/php5]$ whereis php5-bz2
php5-bz2: /usr/ports/archivers/php5-bz2

To install it, change over to there and run the usual make install clean.

Shell
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
[root@shana /usr/ports/lang/php5]$ cd /usr/ports/archivers/php5-bz2
[root@shana /usr/ports/archivers/php5-bz2]$ make install clean
# ===>  License PHP301 accepted by the user
# ===>  Extracting for php5-bz2-5.4.4
# => SHA256 Checksum OK for php-5.4.4.tar.bz2.
# ===>  Patching for php5-bz2-5.4.4
# ===>   php5-bz2-5.4.4 depends on file: /usr/local/bin/phpize - found
# ===>   php5-bz2-5.4.4 depends on file: /usr/local/bin/autoconf-2.69 - found
# ===>  PHPizing for php5-bz2-5.4.4
# Configuring for:
# PHP Api Version:         20100412
# Zend Module Api No:      20100525
# Zend Extension Api No:   220100525
# <snip>
# ===>  Installing for php5-bz2-5.4.4
# ===>   php5-bz2-5.4.4 depends on file: /usr/local/include/php/main/php.h - found
# ===>   Generating temporary packing list
# ===>  Checking if archivers/php5-bz2 already installed
# ===>   Registering installation for php5-bz2-5.4.4
# ****************************************************************************
#
# The following line has been added to your /usr/local/etc/php/extensions.ini
# configuration file to automatically load the installed extension:
#
# extension=bz2.so
#
# ****************************************************************************
# ===>  Cleaning for php5-bz2-5.4.4

What happens is the following:

  1. It extracts the PHP source into a separate working directory.
  2. Changes into the extensions subdirectory.
  3. Runs phpize, which will setup the subdirectory with your local PHP configuration ready to build.
  4. Runs ./configure in the extension’s subdirectory.
  5. Runs make in the extension’s subdirectory.
  6. Runs make install to install the extension and activates it in your /usr/local/etc/php/extensions.ini

Pretty easy, yes? It gets even easier. If you’ve installed portupgrade (and you should if you haven’t), you can condense the above into a single command:

Shell
1
2
3
4
5
6
7
8
9
[root@shana /]$ portinstall php5-dom
# [Updating the pkgdb <format:bdb_btree> in /var/db/pkg ... - 74 packages found (-0 +0)  done]
# [Gathering depends for textproc/php5-dom ................................................... done]
# ** Port marked as IGNORE: www/apache22:
#     Do not install. Installed manually.
# --->  Skipping 'textproc/php5-dom' because a requisite port 'www/apache22' failed (specify -k to force)
# ** Listing the failed packages (-:ignored / *:skipped / !:failed)
#     - www/apache22
#     * textproc/php5-dom

You will see that that failed because the dependency of apache22 is marked as IGNORE. What can we do? Just run portinstall -k <portname> and it will install it anyway.

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@shana /]$ portinstall -k php5-dom
[Gathering depends for textproc/php5-dom ................................................... done]
# --->  Installing 'php5-dom-5.4.4' from a port (textproc/php5-dom)
# --->  Building '/usr/ports/textproc/php5-dom'
# ===>  Cleaning for php5-dom-5.4.4
# <snip>
# ===>  License PHP301 accepted by the user
# ===>  Extracting for php5-dom-5.4.4
# => SHA256 Checksum OK for php-5.4.4.tar.bz2.
# ===>  Patching for php5-dom-5.4.4
# ===>   php5-dom-5.4.4 depends on file: /usr/local/bin/phpize - found
# ===>   php5-dom-5.4.4 depends on file: /usr/local/bin/autoconf-2.69 - found
# ===>   php5-dom-5.4.4 depends on executable: pkg-config - found
# ===>   php5-dom-5.4.4 depends on shared library: xml2.5 - found
# ===>  PHPizing for php5-dom-5.4.4

You can repeat this for the rest of your modules.

WARNING: Some of these ports have dependencies on x11 (the graphical user interface). To prevent ports from installing x11, you need to add WITHOUT_X11=yes to your /etc/make.conf.

Then you can install whatever modules you need.

Shell
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
[root@shana /]$ portinstall php5-ctype
[root@shana /]$ portinstall php5-curl
[root@shana /]$ portinstall php5-fileinfo
[root@shana /]$ portinstall php5-filter
[root@shana /]$ portinstall php5-gd
[root@shana /]$ portinstall php5-gettext
[root@shana /]$ portinstall php5-hash
[root@shana /]$ portinstall php5-iconv
[root@shana /]$ portinstall php5-imap
[root@shana /]$ portinstall php5-json
[root@shana /]$ portinstall php5-ldap
[root@shana /]$ portinstall php5-mbstring
[root@shana /]$ portinstall php5-mcrypt
[root@shana /]$ portinstall php5-mysql
[root@shana /]$ portinstall php5-mysqli
[root@shana /]$ portinstall php5-openssl
[root@shana /]$ portinstall php5-pdo
[root@shana /]$ portinstall php5-pdo_mysql
[root@shana /]$ portinstall php5-pgsql
[root@shana /]$ portinstall php5-pdo_pgsql
[root@shana /]$ portinstall php5-sqlite3
[root@shana /]$ portinstall php5-pdo_sqlite
[root@shana /]$ portinstall php5-posix
[root@shana /]$ portinstall php5-session
[root@shana /]$ portinstall php5-simplexml
[root@shana /]$ portinstall php5-snmp
[root@shana /]$ portinstall php5-soap
[root@shana /]$ portinstall php5-ssh2
[root@shana /]$ portinstall php5-tidy
[root@shana /]$ portinstall php5-tokenizer
[root@shana /]$ portinstall php5-xml
[root@shana /]$ portinstall php5-xmlreader
[root@shana /]$ portinstall php5-xmlwriter
[root@shana /]$ portinstall php5-zip
[root@shana /]$ portinstall php5-zlib

Enabling PHP support in Apache

Now that we’re setup, the last step is to enable support for PHP in Apache. It will have already done one step of this process for us, adding this line:

LoadModule php5_module        /usr/local/libexec/apache22/libphp5.so

to your /var/www/conf/httpd.conf file.

The other bit, as mentioned above when we installed PHP is to add the .php extension.

Open up your /var/www/conf/httpd.conf file, and search for the existing AddType references. It shows up on about line 359 for me.

Add these in anywhere there; I put mine in after the AddType application/x-gzip .gz .tgz line.

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

And we’re done! In the next part we’ll install Subversion, then in Part 4 we configure Apache and setup some websites.

Server Build    apache, freebsd, php, ports, server build, shana
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
← Installing Apache and its Ecosystem: Part 1
jubeat plus / jukebeat: An iOS Game Review →
Avatars by Sterling Adventures

EvoLve theme by Theme4Press  •  Powered by WordPress Odynia.org blog
I write about things.