"Le cordonier est le plus mal chaussé" would be a great analogy of me and my web presence right now.

Monday, September 13, 2004

FAMP (FreeBSD, Apache, MySQL, PHP)

[Edit]I have an updated version of this article here[/Edit]


It's extremely easy to set up a PHP-aware web server in FreeBSD. Here's a quick how-to using the FreeBSD's ports system. The advantage of using the ports system is that updating the server is painless when new versions of the software come out. We'll install the latest version of Apache 1.3, the latest version of MySQL 4.0 and the latest version of PHP 5.

MySQL
Install MySQL first:

cd /usr/ports/databases/mysql40-server
make install clean


Apache
Install Apache with SSL support:

cd /usr/ports/www/apache13-modssl
make
make certificate

Follow the prompts to create the certificate. When you’re done, continue with the installation:

make install
make clean


PHP5
To install mod_php5:

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

Install PHP extensions (e.g MySQL support):

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

A ncurses menu will appear. Select whatever you need from the options.


Post-Installation Configuration
Edit the Apache configuration file /usr/local/etc/apache/httpd.conf and add these lines in the file:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Look through the file and edit the configuration to suit your needs. Next create a php.ini configuration file from the php.ini-recommended example configuration:

cd /usr/local/etc
cp php.ini-recommended php.ini

Again, look through the configuration file and see if you want to change anything. Next, configure your MySQL server. By default, no password is set for the MySQL root user. You should set a password for that user at this point:

mysqladmin -u root password "newpassword"

Replace "newpassword" with your own. MySQL comes with two anonymous accounts set up. These accounts don't have any passwords assigned by default. It is a good idea to just delete them. At the MySQL prompt, issue the following command:

delete from mysql.user where user = '';
flush privileges;

You may want to use a tool such as MySQL Administrator from a workstation on your network. In order to connect to the MySQL server from your network, you need to give the user whom you want to connect as the required priviledges. For example:

GRANT ALL ON *.* TO root@'192.168.0.%' IDENTIFIED BY 'yourPass';

To exit from the MySQL prompt, just type "exit".

Controlling your servers
You can start, stop or restart Apache by issuing the following commands:

/usr/local/etc/rc.d/apache.sh start
/usr/local/etc/rc.d/apache.sh stop
/usr/local/etc/rc.d/apache.sh restart

You can start or stop the MySQL server by doing:

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

The system will use the apache.sh and mysql-server.sh scripts to start Apache and MySQL the next time you reboot as well.


References
http://dev.mysql.com/doc/mysql/en/Default_privileges.html

7 Comments:

Blogger Jaeboy said...

nice tut, how about another one setting up php on win?

2:11 pm

 
Blogger Shane said...

PHP on Windows? Ugh. It's more tortuous. There are several guides around. Here's one. I haven't tried it though, so I don't know if it is accurate.

3:16 am

 
Blogger Shane said...

In FreeBSD 5.x, you need to have these in /etc/rc.conf:

apache_enable="YES"
mysql_enable="YES"

10:38 am

 
Anonymous Anonymous said...

For windows you can download WAMP preconfigured. No need to mess with manual configs. Thanks for the BSD tut it's what I've been searching for. I've been having trouble with mysql running it gives me a sock error.

5:04 am

 
Anonymous Anonymous said...

Minor typo: flush priviledges; should be flush privileges;. Thanks for the quick summary, I missed a step and this got me back on track. Cheers.

5:39 am

 
Blogger Shane said...

Thanks for pointing that out. I've fixed the typo.

9:58 am

 
Anonymous Anonymous said...

Don't forget to make your my.cnf

my-huge.cnf Large site, fully dedicated mysql server, 1-2GB RAM
my-large.cnf Large site, mostly dedicated mysql server, ~512MB RAM
my-medium.cnf Medium site, shared server running mysql, > 64MB RAM
my-small.cnf Small site, shared server running mysql, < 64MB RAM

11:54 am

 

Post a Comment

<< Home