Promo

 

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:

1. 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.
2. Update your ports collection (portsnap fetch, portsnap extract.) (See the FreeBSD Handbook Section 4.5.1)

#
Installing MySQL:

1. Go to the mysql50-server port directory by typing the command:

cd /usr/ports/databases/mysql50-server

2. Build the port by typing: (This takes AGES - good time for some food.)

make BUILD_OPTIMIZED=yes BUILD_STATIC=yes

3. Install by typing:

make install clean

4. 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.

mysql_enable="YES"

5. Start mysql manually to avoid having to reboot now by typing:

/usr/local/etc/rc.d/mysql-server start

6. 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

1. Go to the apache22 port directory by typing the command:

cd /usr/ports/www/apache22

2. Build and install the port by typing: (This takes a while, coffee time!)

make install clean

Note: You may want to disable the two DAV options if you don't need them when prompted

3. 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.

apache22_enable="YES"

#
Installing PHP

1. Go to the php5 port directory by typing the command:

cd /usr/ports/lang/php5

2. Build and install the port by typing: (Just accept the default options, this takes a while, more coffee.)

make install clean

Make sure the APACHE (Build Apache module) option is ticked when configuring the build, leaving all other options as default, before selecting OK.

3. Go to the php5-extentions meta port directory by typing the command:

cd /usr/ports/lang/php5-extentions

4. Build and install the port by typing: (Just accept the defaults here, phpMyAdmin will install any other extensions required itself)

make install clean

5. Install the php.ini file:

cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini

6. 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.

7. 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.

8. 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

9. Edit the language settings file (/usr/local/etc/apache22/extra/httpd-languages.conf) and add the following line at the end of the file:

AddDefaultCharset On

10. Start Apache using the startup script:

/usr/local/etc/rc.d/apache22 start

And you're done! Apache with PHP is installed.

#
Installing phpMyAdmin

1. Got to the phpmyadmin port directory by typing the command:

cd /usr/ports/databases/phpmyadmin

2. Build and install the port by typing: (Just accept the default options)

make install clean

3. 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 section (just search for where all the other Alias commands are.)

Alias /phpmyadmin /usr/local/www/phpMyAdmin

4. As /usr/local/www/phpMyadmin is outside of the Apache you will have to make a entry for it too. Add the following lines to the end of the section: (just search for )


Order allow,deny
Allow from all


Note:You may prefer to put the Alias entry inside a entry if you are hosting multiple sites using name based virtual hosting and do not wish to enable phpMyAdmin on all the sites.

5. 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

6. Restart Apache so that the Alias and Directory entries take effect by typing:

/usr/local/etc/rc.d/apache22 restart

7. Configure phpMyAdmin by going to http://hostname/phpmyadmin/scripts/setup.php in your browser and set at least the following:
* Add Server
o Change the "Authentication type" dropdown to http to have phpMyAdmin prompt you for a username and password.
o Delete root from the "User for config" auth textbox so it is blank.
o You can leave all other settings as they are (even if they are blank.)
o Click the "Add" button to add the new server
Save the configuration using the Save button in the Configuration section.

8. 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 .

9. 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

10. 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.


 
Top