Installing a LAMP(Apache 2.2, MySQL 5.0.27, PHP 5.2)server On FreeBSD

Installing and configurating Apache 2.2

Installing Apache 2.2


First make sure your port tree is up to date with portsnap and update them with portmanager if they:
[root@www ~]# portsnap update
Ports tree is already up to date.
[root@www ~]# portmanager -u
Now install Apache with portmanager:
[root@www ~]# portmanager www/apache22

Configurating Apache 2.2

Starting ang stopping Apache 2.2

[root@www ~]# /usr/local/sbin/apachectl -k start
[root@www ~]# /usr/local/sbin/apachectl -k stop
To test if the server works, go to the computer's IP address with a internet browser. Like this for example: http://192.168.0.116/
It should say "It works!"
Then, edit the httpd.conf file that's located in here:/usr/local/etc/apache22/
To be able to use .htaccess files to protect our pages, you must replace this line: AllowOverride None with AllowOverride All
This line is somewhere in the this directory that contains your Document root path: <Directory "/usr/local/www/apache22/data">
Change the index.html for index.php since we will be using php files.
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
Then, add these lines into the <IfModule mime_module> dirrective so you can execute php and phps files.
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
Uncomment theses lines since we will be using virtual hosts and the
# Server-pool management (MPM specific)
Include etc/apache22/extra/httpd-mpm.conf

# Real-time info on requests and configuration
Include etc/apache22/extra/httpd-info.conf

# Virtual hosts
Include etc/apache22/extra/httpd-vhosts.conf
Now edit the httpd-info.conf file to restrict the access to the server informations. Don't forget to create a .htpasswd file.
<Location /server-status>
AuthName "Admin Zone; Configs"
AuthType Basic
AuthUserFile /usr/local/www/.htpasswd
Require valid-user
SetHandler server-status
Order deny,allow
Deny from all
Allow from all
</Location>

<Location /server-info>
AuthName "Admin Zone; Configs"
AuthType Basic
AuthUserFile /usr/local/www/.htpasswd
Require valid-user
SetHandler server-info
Order deny,allow
Deny from all
Allow from all
</Location>
Test your configurations:
http://192.168.0.116/server-info
http://192.168.0.116/server-status
It should ask you for a Username and Password.

Now we are going to set up a virtual host. Here's an example of the <VirtualHost> dirrective.
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog /var/log/dummy-host.example.com-error_log
CustomLog /var/log/dummy-host.example.com-access_log common
</VirtualHost>

Common errors

Failed to enable the 'httpready' Accept Filter

if you get this error,
[Sun Dec 17 22:08:53 2006] [warn] (2)No such file or directory: Failed to enable the 'httpready' Accept Filter
You can solve this problem temporarely by typing this:
[root@www /]# kldload accf_http
To solve this problem permanently, you must add this line to the /boot/loader.conf file:
accf_http_load="YES"


The webserver works only with local address, why?

If you have a router, it maybe blocking the www port (80). You have to unblock it in your router menu.
Adresses:
D-link: 192.168.0.1
Linksys: 192.168.1.1

Installing and configurating MySQL 5.0.27

Installing MySQL 5.0.27


[root@www /]# portmanager databases/mysql50-server

Configurating MySQL 5.0.27


To setup your mysql server, execute the startup script and test to see if you can start and stop the server:
[root@www ~]# /usr/local/bin/mysql_install_db --user=mysql
[root@www ~]# /usr/local/share/mysql/mysql.server start
[root@www ~]# /usr/local/share/mysql/mysql.server stop
Now setup the root account with a password:
[root@www ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.27

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');
Query OK, 0 rows affected (0.00 sec)
Now add another host that root can connect and it will be the computer you use to manage your server:
mysql> INSERT INTO mysql.user (Host,User,Password)VALUES('192.168.0.100','root',PASSWORD('newpassword'));
Query OK, 1 row affected, 3 warnings (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.0.100' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)

This let's you connect with the root user when you are on this ip 192.168.0.100(it's my desktop computer)

Installing and configurating PHP 5.2



Installing PHP 5.2


[root@www ~]# portmanager lang/php5

Configurating PHP 5.2


[root@www ~]#

installing PHP 5 modules


[root@www ~]# portmanager graphics/php5-gd
[root@www ~]# portmanager graphics/php5-exif
[root@www ~]# portmanager graphics/php-magickwand