FAMP (FreeBSD, Apache, MySQL & PHP stack) setup
This assumes the FreeBSD OS has been installed and setup ready for Apache, MySQL and PHP installation and configuration.
First navigate to Apache in the ports collection, then install the port at the given location and clean (note Apache version here is 24, this may change in future):
cd /usr/ports/www/apache24 && sudo make config-recursive install distclean
To add Apache to startup, edit the rc.conf
file with:
sudo ee /etc/rc.conf
Now add the following to the files, save and exit (alternatively, use sudo sysrc apache24_enable=yes
command to add this line to the end of the file):
apache24_enable="YES"
Startup Apache now with the following command, then input the server's IP address in the web browser to see "It Works" if Apache is successfully working:
sudo service apache24 start
Navigate to MySQL in the ports collection, then install the port and clean (note again that the MySQL version here is 5.6, but this can change as future version get released):
cd /usr/ports/databases/mysql56-server && sudo make config-recursive install distclean
To add MySQL to startup, edit the rc.conf
file with:
sudo ee /etc/rc.conf
Now add the following to the files, with the bind-address argument that sets MySQL to only allow connections on the localhost. Save and exit (alternatively, use sudo sysrc mysql_enable=yes
command to add each line to the end of the file):
mysql_enable="YES"
mysql_args="--bind-address=127.0.0.1"
Startup MySQL now with the following command:
sudo service mysql-server start
Once MySQL has started, configure MySQL for a production enviroment with the following (be sure to generate a password for root user when prompted, for the rest hit RETURN
for the default settings):
sudo mysql_secure_installation
Next start the MySQL terminal interface with the following (inputting the password when prompted):
mysql -u root -p
Change the root user's username to something a little more entropic and flush the currently loaded priveledges for it to take effect with:
UPDATE mysql.user set user = '[username]' where user = 'root';
flush privileges;
Exit the MySQL CLI and login again (entering password again when prompted) using the new username to ensure the change was successful:
mysql -u [username] -p
First navigate the ports collection, then install the ports (PHP, PHP Apache module, PHP MySQL module and PHP MySQLi module) at the given locations and clean (note the PHP version here is 5.6 and may change in future):
cd /usr/ports/lang/php56 && sudo make config-recursive install distclean
cd /usr/ports/www/mod_php56 && sudo make config-recursive install distclean
cd /usr/ports/databases/php56-mysql && sudo make config-recursive install distclean
cd /usr/ports/databases/php56-mysqli && sudo make config-recursive install distclean
OR
Use FreeBSD's PHP extensions ports to select and install all the common PHP modules (using the mouseclick to choose what gets installed) with:
cd /usr/ports/lang/php56-extensions && sudo make config-recursive install distclean
Restart Apache to load the new extension:
sudo apachectl graceful
Rehash the system to find binaries paths (note that rehash
can be used in place of this):
hash -r
Copy PHP's sample configuration file (for production) to be used as the current config:
sudo cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
Create/open a php.conf file for apache:
sudo ee /usr/local/etc/apache24/Includes/php.conf
Insert the following for Apache to process PHP files, then save and exit:
<IfModule dir_module>
DirectoryIndex index.php index.html
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
</IfModule>
Restart Apache for the changes to take effect:
sudo service apache24 restart
The FAMP stack is now setup, but it is important to make sure it is working correctly by testing it. Start to create a file in Apache's default DocumentRoot directory /usr/local/www/apache24/data
with:
sudo ee /usr/local/www/apache24/data/info.php
Enter the following, then save and exit to create the file:
<?php phpinfo(); ?>
Go to the IP address of the server with /info.php
. If it is working, then remove the info script with:
sudo rm /usr/local/www/apache24/data/info.php
According to the PHP documentation some PHP modules should be included as apart of PHP by default, one of these being Filter
(found here: http://php.net/manual/en/filter.installation.php). However, this is not included as part of the php56
port. To check the list of PHP modules that have been installed, enter:
php -m
If any modules that need to be installed, these can be installed seperatly when needed like so (using php5-filter
as an example):
cd /usr/ports/security/php5-filter && sudo make config-recursive install distclean
Restart Apache for the changes to take effect:
apachectl graceful