FreeBSD – Apache/MySQL/PHP
This is a Typical Apache/PHP Walkthrough for FreeBSD. The biggest trick with *BSD i have found is that you must pay attention to the order your packages are installed. For the Base install, i use the netinstall with the Minimal package.. This was written with the assumption of installing with the FreeBSD 8.1/8.2 Codebase
If you start with the Minimal install, You may or not get the Ports tree installed. This is usually located in /usr/ports. If this does not exist. you can do portsnap fetch to grab the current snapshot. Then portsnap extract to make the ports tree…
Once your Ports Tree is established we can move on…
My servers are typically headless. So i edit /etc/make.conf & add WITHOUT_X11=yes to keep X from being installed, or at least down to a minimum….
The Ports we will Install in Order is the Following:
- Perl5 /usr/ports/lang/perl5.12
- MySQL 55 Server /usr/ports/databases/mysql55-server
- Apache22 /usr/ports/www/apache22
- PHP5 /usr/ports/lang/php52
- PHP5 Extensions /usr/ports/lang/php52-extensions
Other Highly Useful Ports
WGET /usr/ports/ftp/wget (make && make install)
Screen /usr/ports/sysutils/screen (make && make install)
Webmin /usr/ports/sysutils/webmin (make && make install & Follow Instructions)
Perl Install
From the root Prompt
Host# cd /usr/ports/lang/perl5.12
Host# make
Host# make install
MySQL 55 Server (Community Edition)
From the root Prompt
Host# cd /usr/ports/databases/mysql55-server
Host# make
Host# make install
By Default MySQL installs its dbdir in /var/mysql, I create a home directory, & run the DB from there, the /home partition is always larger then /var
After install:
Enable MySQL to start at boot:
vi /etc/rc.conf
Add:
mysql_enable=”YES”
mysql_dbdir=”/home/mysql”
Then:
mkdir /home/mysql
mkdir /home/mysql/tmp
cp /usr/local/share/mysql/my-medium.cnf /home/mysql/my.cnf
chown –R mysql:mysql /home/mysql
I put MySQL in its own directory because the /var partition can accumulate a lot of log files and fill up quickly. This avoids the whole problem..
Apache22 http server
cd /usr/ports/www/apache22 make && make install
Use the following modules:
Mysql
suexec
authen_dbd
dbd
After it completes Edit RC conf to enable apache at boot
vi /etc/rc.conf
apache22_enable=”YES”
PHP5
cd /usr/ports/lang/php5 make
Options
Cli
Cgi
Apache
Suhosin
Multibyte
Fastcgi
Pathinfo
After it Compiles Do make install
After install edit httpd.conf add the PHP Application type & add index.php to default pages
(restart apache to take affect httpd -k stop & httpd -k start)
vi /usr/local/etc/apache22/httpd.conf
insert:
Make sure index.php is part of your DirectoryIndex.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
PHP5 Extensions
cd /usr/ports/lang/php5-extensions make
Options: <Note:: These are provided for Reference. If you do not require these, Do Not enable them>
| CalendarCtypeCurl
Exif
Filter
Ftp
Gd
Gettext
Hash
Iconv
Json
Ldap
Mbstring
Mcrypt
Mhash
Ming
Mysql
Mysqli
Openssl
Pcre
Pdf |
PdoPdo_sqlitePosix
Session
Simplexlm
Snmp
Sockets
Spl
Sqlite
Tokenizer
Xml
Xmlreader
Xmlrpc
Xmlwriter
Xsl
Zip
Zlib |
Extension Options:
Curl
CA_ROOT_NSS
Check add etc symlink
PHP5-PCRE
Check bundled_pcre
PHP5-GD
Check
Tilib
Truetype
PHP5-MBSTRING
Check regex
PHP5-SNMP <Only required if we are building an NMS server>
No check snmp4 (don’t need UCD-SNMP as we are using net-snmp)
PHP5-SQLITE
No check UTF-8
LIBXSLT
No check MEM_DEBUG
After the Complete issue make install to Complete the Installation…
Now the installs for MySQL/Apache/PHP5 should be completed…
Just for good measure & to verify Boot Start options, I issue a reboot to bounce the server and verify the services startup at boot..
Notes:
- If any package Bombs the install & It does not get installed automagically. i.e. File not Found No access, You can Google the Package name to find it. Then go to /usr/ports/distfiles & use fetch to grab the missing package.
- If an Option presented by the Make command is broken. You can issue make rmconfig to remove the ticks you made and start over. Then issue make clean to clean for the removed options.
- If when Starting Apache you get:
[warn] (2)No such file or directory: Failed to enable the ‘httpready’ Accept Filter.
The resolution to the above problem is to add accf_http module, which function is to buffer incoming connections until a certain complete HTTP requests arrive, into FreeBSD kernel by using kernel linker:
kldload accf_http
To permanently load enable HTTP Accept Filter FreeBSD kernel module (accf_http), add the following line into /boot/loader.conf:
accf_http_load="YES"
Note: The default settings is located in /boot/defaults/loader.cnf. To see the related settings about accf, use:
grep accf /boot/defaults/loader.conf
which will returns:
accf_data_load=”NO” # Wait for data accept filter
accf_http_load=”NO” # Wait for full HTTP request accept filter
Sample rc.conf with the Changes Noted Above:
Located In /etc/rc.conf
Sample rc.conf
# Please make all changes to this file, not to /etc/defaults/rc.conf.
# This file now contains just the overrides from /etc/defaults/rc.conf.
defaultrouter=”192.168.1.1″
hostname=”server.yourdomain.com”
ifconfig_em0=”inet 192.168.1.51 netmask 255.255.255.0″
inetd_enable=”YES”
linux_enable=”YES”
sshd_enable=”YES”
mysql_enable=”YES”
mysql_dbdir=”/home/mysql”
webmin_enable=”YES”
sendmail_enable=”YES”
apache22_enable=”YES”
References:
FreeBSD for Internet Server
Apache accf Issue
FreeBSD WIKI