This section covers the steps to setting up a webserver using apache/php/mysql and the pear-DB module. This webserver will be able to effectively serve LAN clients and give you a developing environment. For setting up a production server you would simply need to take these steps and continue to set it up so other clients can access it. This is not the setup I'm using, so I can't explain how to do it.
MySQL
Apache
PHP
PearDB
phpMyAdmin
You could use PostgreSQL or any other database at this point. However, I'm familiar with MySQL, and it suits my purposes nicely. We are going to set up the pearDB module, however, so it will be simple for you to switch databases at anytime with minimal modifying of your code. At this time I was using server 4.0. It'll probably be different for you, so make sure you know which one you want. Now lets install this bugger:
cd /usr/ports/databases/mysql40-server
make install clean
I'm not going to get into usage, as that is a very long topic I'm not suited to teach. However let's set up a root user.
mysqladmin -u root password your_password_here
Now you have created your user with the password you specified. To bring up mysql in the console, issue:
mysql -u root -p
Enter your password at the prompt, and you are gold. I'd also like to note that you will find your mysql files stored at /var/db/mysql. Finally, we need to have MySQL startup at boot time. Add this line to /etc/rc.conf
mysql_enable="YES"
ApacheApache is a very popular and very nice webserver. You will probably be using a different version of Apache as well.
cd /usr/ports/www/apache13
make install clean
Just a minor amount of configuring here. We'll be editing /usr/local/etc/apache/httpd.conf. Make sure you have these two lines, edit or add them appropriately.
ServerName 127.0.0.1
DocumentRoot "/usr/local/www/"
ServerName says that you will type localhost to access your server. The other line says where to grab documents for the root of your server at. If you had a file /usr/local/www/jim.php you would access it at localhost/jim.php. Get it? Got it? Good. If you type in localhost to firefox (you'd best be using it) you'll get a nice message from Apache. We also want to start Apache at boot time, so in /etc/rc.conf:
apache_enable="YES"
PHPPERL would be another choice at this point, but PHP seems to be more popular, and looked a bit nicer to me when I was researching how to set this up. So, it's our choice. We need to set some options in /etc/make.conf
WITH_MYSQL=yes
Obviously replace MySQL with PostgreSQL if that was your choice, for instance. I had difficulty getting PHP to compile with mysql support, so I also modified the makefile for good measure.
cd /usr/ports/lang/php4
vi Makefile
Under the CONFIGURE_ARGS we will want to add one line, just above --disable-all
--with-mysql
Now we can say with certainty we're going to get what we bargained for.
make install clean
As is PHP will just run with a default config. There are two options which we can use as a base. I chose the one for development, but if you want to run a production server, definately use -recommended.
cd /usr/local/etc
cp php.ini-dist php.ini
PearDB is a php database abstraction class. What this allows us to do is write code for this abstract class, and then simply choose which database we want to interface with. This is extremely useful, as it allows much more portability of database code, allowing a simple transfer between database backends. Convinced you want it yet? If not, you can skip this section.
Glad to see you're still here. Now lets install pear.
cd /usr/ports/databases/pear-DB
make install clean
Just a little bit of configuring this time.
vi /usr/local/etc/php.ini
Add this line:
include_path = "/usr/local/share/pear"
Now you can enjoy writing nice abstract PHP code.
phpMyAdminThis is not a necessary step by any means. However, if you don't like working with mysql at the console, I recommend you make this installation.
cd /usr/ports/databases/phpmyadmin
make install clean
If you set up a password for your root user for mysql, then you will need to tell phpMyAdmin what that password is.
vi /usr/local/www/phpMyAdmin/config.inc.php
Now edit the line that reads:
$cfg['Servers'][$i]['password'] = 'yourpasswordhere'; // MySQL password (only needed
Now you can go to it from localhost/phpMyAdmin