Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Monday, September 10, 2007

Creating a FAMP server

What is a FAMP server?
A FAMP server is a FreeBSD web server containing the following applications:
FAMP = FreeBSD + Apache + MySQL + Perl/PHP

Requirments

  1. You will need a basic install of FreeBSD, for more information on how to install FreeBSD please see: Installing FreeBSD
  2. You will need a copy of the ports, for more information please see: Using the Ports Collection.
Installing apache
I like using apache 1.3, I find it secure and stable, so I'll install it here. If you wish to use apache 2+ please see: httpd.apache.org.
# cd /usr/ports/www/apache13 && make install && make clean
# echo 'apache_enable="YES"' >> /etc/rc.conf


Installing PHP
This is the way I install PHP and needed PHP modules.
# cd /usr/ports/lang/php5 && make config
# cd /usr/ports/lang/php5 && make install && make clean
# cd /usr/ports/lang/php5-extensions && make install && make clean

If you are unsure which modules you will need check the system requirements of each application you will be using on the web-server (e.g. wordpress or mediawiki).

Installing MySQL
I will install MySQL 5.0 if you would like information on other MySQL versions please see: MySQL Home Page
# cd /usr/ports/databases/mysql50-server && make install && make clean
# echo 'mysql_enable="YES"' >> /etc/rc.conf


Installing Perl DBI and DBD support
Many programs which run using both Apache and MySQL will require the following Perl modules:
# cd /usr/ports/databases/p5-DBI && make install && make clean
# cd /usr/ports/databases/p5-DBD-mysql50 && make install && make clean


Configuration
It is important to add the web servers IP address to its hosts file. This suppresses errors from Apache and MySQL.
# edit /etc/hosts
adding:
192.168.0.252 Hostname.domainname.tld Hostname

Configuring Apache
Before editing any file on my system I like to make a backup of it.
# cp /usr/local/etc/apache/httpd.conf /usr/local/etc/apache/httpd.conf.orig
# edit /usr/local/etc/apache/httpd.conf


In httpd.conf you will need to change the following:
*Note: These options may not suit your needs for more information please see: FreeBSD Handbook - Apache HTTP Server, or httpd.apache.org
#If your web server is inside a jail it is important to change the Listen address:
# from:
#Listen 12.34.56.78:80
# to (Changing 192.168.0.252 to the IP address of the web server):
Listen 192.168.0.252:80

# Change the email address of the ServerAdmin (You)
ServerAdmin you@your.address

# Change the ServerName option,
# *Note: if you don't have a fully qualified domain name
# please change this to the servers IP address
# From:
#ServerName www.example.com
# To:
ServerName 192.168.0.252

# Add a DirectoryIndex option:
DirectoryIndex index.php index.html index.htm index.php3 index.php4

# In the AddType section add the following for PHP:
AddType application/x-httpd-php .php .htm .html
AddType application/x-httpd-php-source .phps

I like to do a diff on the original httpd.conf file and my changes, so that later I can see what I changed, especially if problems arise:
# diff --suppress-common-lines /usr/local/etc/apache/httpd.conf.orig /usr/local/etc/apache/httpd.conf > /root/.apache.conf-diff

Configuring php:
# cp /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini
To Test php5
# echo "<?php phpinfo() ?>" > /usr/local/www/data-dist/phptest.html

Configuring MySQL:
# cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
Start MySQL to add root passwords:
# /usr/local/etc/rc.d/mysql-server.sh start
# /usr/local/bin/mysqladmin -u root -h Hostname.domainname.tld password 'YourPassword'
# /usr/local/bin/mysqladmin -u root password 'YourPassword'


Now you need to reboot your web-server to startup all of your new services.

Testing your new Web Server
Once your server is up and running go to the web servers address either on the server (if it has a browser) or on your desktop box.

E.g. Open your browser and type the IP address of your server: http://192.168.0.252/

To test your php install type the following into your browser (changing 192.168.0.252 to the IP address of the server):
http://192.168.0.252/phptest.html

If you have problems check your firewall rules, if that doesn't help check your logs, and see if they shed some light on the problem.
Have Fun!!!

Sunday, July 08, 2007

OpenBSD Tip: Starting Apache

Apache is included in a basic install of OpenBSD. However it is not running by default. Starting Apache in OpenBSD is really easy. You can start the server manually or automatically.

Automatic: To start Apache every time the computer starts/restarts you need to do the following:

Edit /etc/rc.conf and change this line:
httpd_flags=NO
To read:
httpd_flags="" # note the use of two double-quotes
Then save the changes. When the computer is restarted, the Apache server (httpd) will automatically start.

Manual: To start Apache manually you need to run the following command:
# /usr/sbin/apachectl start
/usr/sbin/apachectl start: httpd started


Testing your Web Server: To test your webserver point your web browser to your servers IP address, or use lynx on the webserver like this:
# lynx localhost

[ lynx displays the following ...]
[OpenBSD]
Apache
It Worked!

If you can see this page, then the people who own this host have just
activated the Apache Web server software included with their OpenBSD
System. They now have to add content to this directory and replace this
placeholder page, or else point the server at their real content.
[ ... cut ... ]
The Document Root directory (the directory where all of the server's web pages are stored) is /var/www/htdocs. You can now place your web pages in this directory.