Apache, PHP, MySQL, and Drupal in FreeBSD 10 – Part I: Apache24 and PHP5

Part I – Installing Apache24 and PHP5:

An Apache, PHP, MySQL and Drupal stack on FreeBSD is not difficult to install and configure.  In this case, the Drupal installation will contain only one website and will not employ the use of virtual hosts.  So let’s get started installing Apache24 and PHP5.

 

Update the FreeBSD 10 Ports Tree:

# portsnap fetch update

 

Update installed ports using portmaster:

# portmaster -ad

 

Apache 2.4:

# cd /usr/ports/www/apache24
# make install clean

 

httpd.conf:

To automatically startup Apache , include the following in the /etc/rc.conf:

# apache24_enable="YES"

 

Before starting Apache, first change the following items in /usr/local/etc/apache24/httpd.conf:

Listen 192.168.0.220:80
ServerAdmin admin@loga.us
ServerName ldap1.loga.us:80

 

To ensure the Apache 2.4 installation and preliminary configuration of /usr/local/etc/apache24/httpd.conf works, apache is started with the following command:

# apachectl start

 

After starting Apache, the following output is received on a successful start:

root@bsd220:/usr/local/etc/apache24 # apachectl start
 Performing sanity check on apache24 configuration:
 Syntax OK

 

PHP 5:

The next step is to install php5:

# cd /usr/ports/lang/php5
# make install clean

 

Make sure index.php is part of your DirectoryIndex.  To modify the DirectoryIndex directive, please edit the file /usr/local/etc/apache24/httpd.conf and add index.php to the DirectoryIndex directive:

<IfModule dir_module>
 DirectoryIndex index.php index.html
</IfModule>

 

Add the following at the end of the Apache configuration file /usr/local/etc/apache24/httpd.conf: 

<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>

<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>

 

Install php5-extensions:

# cd /usr/ports/lang/php5-extensions
# make install clean

 

Next, install mod_php5 port for Apache: 

# cd /usr/ports/www/mod_php5
# make install clean

 

Check to ensure php5_module has been installed in /usr/local/etc/apache24/httpd.conf:

LoadModule php5_module libexec/apache24/libphp5.so

 

Let’s see if Apache is working.  Open your browser and point to the ip address or dns name if you have a properly configured internal and/or external DNS.  In this example, the ip address of the Apache Server will be used. 

If everything was successful, you should see the following screenshot:

 

 

Apache Log File Rotation:

As with most installed programs, one must manage the associated log files.  For apache24, log file rotation is necessary in order to prevent log files from growing and using all available disk space.  To setup log rotation for Apache Log Files edit /etc/newsyslog.conf file and add the following lines to the bottom of the file:

 

/var/log/httpd-access.log          600   7     *    @T12    B    /var/run/httpd.pid 30
/var/log/httpd-error.log           600   7     *    @T12    B    /var/run/httpd.pid 30
/var/log/httpd-ssl_request.log     600   7     *    @T12    B    /var/run/httpd.pid 30

 

After modifying /etc/newsyslog.conf, restart the newsyslog service:

# service newsyslog restart

Summary:

Installing and configuring Apache24 and PHP5 on a FreeBSD 10 Server is not difficult.  In Part II of this article, the focus will change to installing MySQL and phpmysqladmin.

 

Additional Resources:

www.apache.org

www.php.net

Leave a Reply

Your email address will not be published.