Wednesday, November 18, 2009

FreeBSD 7.1 conf. Mysql apache22 php samba

FreeBSD 7.1 conf. Mysql apache22 php samba
Published on March 23, 2009 at 3 pm by hachik

The newly installed FreeBSD 7.1 amd64 based server needs to be configured. Mysql 5 database and samba will migrate from older ubuntu server, but other simple configuration is done from scratch.
Firstly I configured sshd to run, adding to rc.conf:

/etc/rc.conf
....
sshd_enable=“YES“

and running /etc/rc.d/sshd start after that.
Now install apache.
As I do not really know what exactly do I need, I install apache from ports without any options:

shell$ cd /usr/ports/www/apache22; sudo make install

apache installed, should be configured, we will do it later.
To install php5:

shell$ cd /usr/ports/lang/php5; sudo make install

need to install extensions aswell:

shell$ cd /usr/ports/lang/php5-extensions; sudo make install

I have chosen mysql support from a list and a few more other options.
Now I meet a problem, on old server we’ve run linux with samba. Windows uses cp850 econding but our server is default to US. I had to copy files with Estonian characters in their names, so I made a new login class in /etc/login.conf

/etc/login.conf:

estonian:Estonian User Accounts:\
:charset=UTF-8:\
:lang=et_EE.UTF-8:\
:tc=default:

after file editing it is neccecary to rebuild database:

shell$ cap_mkdb /etc/login.conf

then add new user with estonian class, and now had to mount samba share on old server:

shell$ mount_smbfs -I 192.168.1.101 -E cp850:cp850 //server/public/ /mnt
shell$ cp -r /mnt/* /somedir/dir/public
shell$ chmod -R +x /somedir/dir/public

now wait for few days until it finishes copy…
For some reason we use samba, so I should install it too :)

shell$ cd /usr/ports/net/samba33/
shell$ make install

I configured samba with default options.

/usr/local/etc/smb.conf:

[global]
workgroup = My Group
server string = %h
security = share
load printers = yes
log file = /var/log/samba/log.%m
max log size = 50
passdb backend = tdbsam
socket options = TCP_NODELAY
[public]
comment = Public Stuff
path = /somedir/dir/public
public = yes
writable = yes
create mask = 0777
directory mask = 0777
force user = nobody
force group = nobody

Now to be able to run samba, it is needed to add samba to rc.conf

/etc/rc.conf:

smbd_enable=”YES”
nmbd_enable=”YES”

shell$ /usr/local/etc/rc.d/samba start

It gave me error:

/libexec/ld-elf.so.1: shared object “libgcrypt.so.15” not found, required by “libcups.so.2”

this happened because libgcrypt was updated and installed again. So I need to reconfigure all depended on this port packages.
First install portupgrade with default options:

shell$ cd /usr/ports/ports-mgmt/portupgrade
shell$ make install

now it is needed to rebuild all ports that depend on libgcrypt.

shell$ portupgrade -rf libgcrypt
shell$ portmaster -r libgcrypt

From now samba started normally.
Other things I am interested in are php, mysql, apache.
Install apache:

shell$ cd /usr/ports/www/apache22/
shell$ make install

install php:

shell$ cd /usr/ports/lang/php5
shell$ make install
shell$ cd /usr/ports/lang/php5-extensions
shell$ make install

install mysql:

shell$ cd /usr/ports/database/mysql50-server
shell$ make install

add apache to rc.conf

/etc/rc.conf:

apache22_enable=”YES”

In my case it was also necessary to add servername to /etc/hosts. This name is the same that we have in httpd.conf under ServerName directive.

/etc/hosts:

192.168.0.100 servername

now it is necessary to configure php to work with apache. Loadmodule was present in httpd.conf, but was not configured, so It is necessary to add following lines to httpd.conf (I added them to very end):

/usr/local/etc/apache22/httpd.conf:


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


Now restart apache

shell$ apachectl graceful

and now check if it works.

shell$ echo “” > /var/www/phpinfo.php

shell$ links http://localhost/phpinfo.php

it seems I had a luck and all things work. Now I need to move database from one machine to another. Let’s find out how to do it. First of all it is needed to start mysql,

shell$ echo mysql_enable=\”YES\” >>
/etc/rc.conf && /usr/local/etc/rc.d/mysql-server start

Now I met a problem, I did not know old mysql root pass, but had a root account on system, so I need to change password on mysql. Previous mysql server was based on ubuntu, so I had to stop database

shell$ /etc/init.d/mysql stop

now it is need to run mysql with skipped grant tables, note that command should be at one shell string.

shell$ mysqld --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --datadir=/var/lib/mysql --skip-grant-tables --skip-networking

now run mysql and change password for user root;

shell$ mysql

use mysql;
select user,password,host from user;
update user set password = password('somepass') where user = 'root' and host='localhost';
flush privileges;
quit;

now kill the mysql process and start It from init script:

shell$ kill `cat /var/run/mysqld/mysqld.pid` && /etc/init.d/mysql start

now I am able to connect with new root pass to mysql.
Next step is to export databases. First we create database with same name on new server. Also create user, and set password and grant options for that database to that user.

shell$ mysql

create database my;
create user 'myuser'@'localhost' identified by 'somepass2';
grant all on my.* to 'myuser'@'localhost' idetified by 'somepass2';
flush privileges;
quit

Now on old server we run command to export database:

shell$ mysqldump -umyuser -psomepass2 my –single-transaction > ~/my.sql

on the new server is to run:

shell$ mysql -umyuser -psomepass2 my < ~/my.sql;

Now we should have database transferred. Repeat step to transfer other databases also.
Now enjoying working server.

No comments: