Apache/MySQL/PHP/phpMyAdmin on FreeBSD
Introduction:
This article describes how to setup Apache, MySQL, PHP and phpMyAdmin on a server running FreeBSD.
The article was written for the software versions below but is likely to work on newer
versions without too much difficulty.
Software:
Operating System: | FreeBSD 7.0 for i386 | Download |
Apache: | 2.2.8 | Installed from Ports Collection |
MySQL Server: | 5.0.51a | Installed from Ports Collection |
PHP & Extensions: | 5.2.5 | Installed from Ports Collection |
phpMyAdmin: | 2.11.5 | Installed from Ports Collection |
Before you begin:
-
This article assumes you have a working install of FreeBSD 6.2 for i386
logged in as root (or another user in the wheel group and you have used "su") with the ports collection installed.
You can use sysinstall, cvsup or portsnap to install the ports distribution if you have not already done so. See point 2 below.
-
Update your ports collection (portsnap fetch, portsnap extract.)
(See the FreeBSD Handbook Section 4.5.1)
Installing MySQL:
-
Go to the mysql50-server port directory by typing the command:
cd /usr/ports/databases/mysql50-server
|
-
Build the port by typing: (This takes AGES - good time for some food.)
make BUILD_OPTIMIZED=yes BUILD_STATIC=yes
|
-
Install by typing:
-
Open /etc/rc.conf with your favourite text editor and add the line shown below. This will ensure mysql is enabled and starts on boot.
-
Start mysql manually to avoid having to reboot now by typing:
/usr/local/etc/rc.d/mysql-server start
|
-
Set a password for the MySQL root user by executing the command, subtituting your own password
in place of new-password:
/usr/local/bin/mysqladmin -uroot password 'new-password'
|
And you're done! MySQL is installed.
Installing Apache
-
Go to the apache22 port directory by typing the command:
cd /usr/ports/www/apache22
|
-
Build and install the port by typing: (This takes a while, coffee time!)
Note: You may want to disable the two DAV options if you don't need them when prompted
-
Open /etc/rc.conf with your favourite text editor and add the line shown below. This will ensure apache is enabled and starts on boot.
Installing PHP
-
Go to the php5 port directory by typing the command:
-
Build and install the port by typing: (Just accept the default options, this takes a while, more coffee.)
Make sure the APACHE (Build Apache module) option is ticked when configuring the build, leaving all other options as default, before selecting OK.
-
Go to the php5-extentions meta port directory by typing the command:
cd /usr/ports/lang/php5-extentions
|
-
Build and install the port by typing: (Just accept the defaults here, phpMyAdmin will install any other extensions required itself)
-
Install the php.ini file:
cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini
|
-
Edit your Apache configuration file (/usr/local/etc/apache22/httpd.conf) and add the following
lines to the end of the file:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
|
Note: You can add additional extenions other than .php (eg .phtml) seperated by spaces.
Note: The second line is optional, it will show colour highlighted PHP source for .phps files.
-
You should also search for the line that reads:
DirectoryIndex index.html
|
and change it to read:
DirectoryIndex index.php index.html
|
Note: You may also add index.phtml or any other default page if you added additional extentions
in the previous step.
- Enable language settings by searching for the line:
#Include etc/apache22/extra/httpd-languages.conf
|
and removing the # comment mark so it reads:
Include etc/apache22/extra/httpd-languages.conf
|
-
Edit the language settings file (/usr/local/etc/apache22/extra/httpd-languages.conf)
and add the following line at the end of the file:
-
Start Apache using the startup script:
/usr/local/etc/rc.d/apache22 start
|
And you're done! Apache with PHP is installed.
Installing phpMyAdmin
-
Got to the phpmyadmin port directory by typing the command:
cd /usr/ports/databases/phpmyadmin
|
- Build and install the port by typing: (Just accept the default options)
-
phpMyAdmin is now installed in /usr/local/www/phpMyAdmin. To use it we need to create Alias and Directory entries in /usr/local/etc/apache22/httpd.conf.
To do this, add the following lines to the <IfModule alias_module> section (just search for where all the other Alias commands are.)
Alias /phpmyadmin /usr/local/www/phpMyAdmin
|
-
As /usr/local/www/phpMyadmin is outside of the Apache <DocumentRoot> you will have to make a <Directory> entry for it too. Add the
following lines to the end of the <Directory> section: (just search for </Directory>)
<Directory "/usr/local/www/phpMyAdmin">
Order allow,deny
Allow from all
</Directory>
|
Note:You may prefer to put the Alias entry inside a <VirtualHost> entry if you are hosting multiple sites using
name based virtual hosting and do not wish to enable phpMyAdmin on all the sites.
-
Create a config directory for phpMyAdmin and make it globally read/write/executable by typing the commands:
cd /usr/local/www/phpMyAdmin
mkdir config
chmod 777 config
|
-
Restart Apache so that the Alias and Directory entries take effect by typing:
/usr/local/etc/rc.d/apache22 restart
|
-
Configure phpMyAdmin by going to http://hostname/phpmyadmin/scripts/setup.php in your browser and set at least the following:
- Add Server
- Change the "Authentication type" dropdown to http to have phpMyAdmin prompt you for a username and password.
- Delete root from the "User for config" auth textbox so it is blank.
- You can leave all other settings as they are (even if they are blank.)
- Click the "Add" button to add the new server
Save the configuration using the Save button in the Configuration section.
-
For the changes to take effect you must copy the generated config file from the phpMyAdmin/config directory to the phpMyAdmin directory by typing
the following command: (Note the space dot at the end of the command)
cp config/config.inc.php .
|
-
You can now delete the config directory you created earlier and reset the permissions on the config.inc.php file to read only typing the commands:
rm -rf config
chmod 444 config.inc.php
|
-
That's it! You can place your web site in /usr/local/www/data/ and access phpMyAdmin at
http://hostname/phpmyadmin/ in your web browser and logging in using username root and the MySQL password you set earlier.
Addendum
-
Document Version: 2.7.0
-
Changes:
- 2.7.0
- Updated for FreeBSD 7.0, MySQL 5.0.51a and phpMyAdmin 2.11.5.
- 2.6.0
- Updated for Apache 2.2.8, MySQL 5.0.51, PHP 5.2.5 and phpMyAdmin 2.11.4.
- Removed register_globals reminder, nobody should be using this anymore.
- Updated Apache rc.d script name.
- Updated phpMyAdmin config procedure.
- 2.5.0
- Updated for Apache 2.2.6, PHP 5.2.4 & phpMyadmin 2.11.1.
- Some formatting updates.
- 2.4.0
- Updated for FreeBSD 6.2, Apache 2.2.4, MySQL 5.0.45 PHP 5.2.3 & phpMyAdmin 2.10.3
- 2.3.0:
- Clarified "Build Apache Module" option for php build
- Updated for phpMyAdmin 2.8.2
- 2.2.0:
- Updated for FreeBSD 6.1, Apache 2.2.2, MySQL 5.0.22, PHP 5.1.4, phpMyAdmin 2.8.1
- 2.1.0:
- Updated for Apache 2.2.0, MySQL 5.0.19, PHP 5.1.2, phpMyAdmin 2.8.0.2
- Changed install procedure for phpMyAdmin to install from Ports Collection rather than source tarball.
- Included link to appropriate section in the FreeBSD Handbook for obtaining/updating the Ports Collection.
- 2.0.0:
- Updated for FreeBSD 6.0, Apache 2.0.55, MySQL 5.0.16, PHP 5.1.1 and phpMyAdmin 2.7.0-pl1.
- Changed procedure to install from Ports Collection rather than build from source tarballs.
- 1.1.0:
- Removed instructions for installing the FreeBSD 4.x compatibility package as this is no longer required for MySQL.
- Updated for FreeBSD 5.4, MySQL 4.1.13 and phpMyAdmin 2.6.3-pl1.
- Fixed a couple of grammatical errors.
- Fixed mistake in command line to make symbolic link for MySQL install.
-
References:
|