Tuesday 6 November 2012

raspberry pi server

Installing Servers On Raspberry PI
The following is to remind me what steps I've performed so far whilst setting up my PI.

Download 2012-10-28-wheezy-raspbian.zip from http://www.raspberrypi.org/downloads

Download win32diskimager-binary (0.6 series released 2012-04-16) from https://launchpad.net/win32-image-writer/+download

Use win32diskimager to put 2012-10-28-wheezy-raspbian on 32GB SD card.

Put the 32GB card in PI.
Power up.
On first boot it asks to configure the PI. I changed the following:
  • The default PI user password to ****
  • Enable SSH
  • Disabled auto boot to desktop
  • Resize boot partition to fill SD card
When it restarted it started resizing the partition:
'Performing an on-line resize of /dev/mmcblk0p2 to 7803648 (4k) blocks.'
This takes ages - like 30-45 mins.

PuTTY
Setup putty so I can do the rest from the laptop.
Based on this tutorial: http://elinux.org/RPi_Remote_Access:
Here's my summary:
It is possible to log in with putty from the laptop.
On the PI type ifconfig to get the ip address
Download PuTTY to the laptop. Run it.
Create a Profile:
Start Putty and type in the Host Name as 192.168.0.7 or whatever the PI ip address is.
Set Connection->SSH->X11 Enable X11 forwarding
If not already set, enter 22 as Port and select SSH as Protocol.
Go to Connection -> Data and type your Raspberry PI's username under Auto-Login username.
Now your profile is complete, you can save it under Session by typing a name for your profile under Saved Sessions and clicking on the Save button.
Establish a connection:
To establish a connection to your Raspberry PI simply click on Open. If you can't establish a connection make sure the SSH daemon is running on your Raspberry PI.
Usually you will get a security warning, you can simply click on yes.
Now enter your password in the terminal.

Remote X desktop
Get Xming (http://sourceforge.net/projects/xming/files/latest/download)
Install it and run.
Run PuTTY. Load your saved PI settings that has X11 forwarding.
Log in and type something that causes a window to display, e.g. midori
Midori will pop up on the laptop display.
Type lxsession to get full desktop

Port forwarding on router
Forward ports 80 and 443 to the pi IP address.

Reduce video ram (I did not do this)
From http://www.penguintutor.com/linux/raspberrypi-webserver
Reduce video ram from 64GB to 32GB, i.e. 256-32 = 224:
sudo cp /boot/arm224_start.elf /boot/start.elf
or use
sudo raspi-config
to do this using the config menu
(you can restore the previous configuration sudo cp /boot/arm192_start.elf /boot/start.elf )

Creating new user (optional)
sudo useradd -m <new user>
sudo passwd <new user>

Then I set the new password when prompted.
sudo nano /etc/group
Go through the file adding ,user1 to the end of all of the groups that pi is in, where user1 is the new user name you just created.
eg.
adm:x:4:pi,user1
In fact from now on I used pi as the user, rather than this new one.

Install subversion (as pi user)
sudo apt-get install subversion

Install zlib
sudo apt-get install zlib1g-dev
(this was already installed when I ran it)

Install boost
sudo apt-get install libboost-dev

Setup web-based SSH access via proxy to Anyterm
I based the setup of Anytime this on:
http://djpate.com/2009/10/30/how-to-install-anyterm-on-ubuntu-karmic-koala/

cd /home/pi
mkdir tmp
cd tmp
svn co http://svn.anyterm.org/anyterm/trunk/ anyterm

<don't checkout the following or you get an sscanf build error>
svn co http://svn.anyterm.org/anyterm/tags/releases/1.1/1.1.29/ anyterm-1.1.29
However, there is a fix for this if you do want to use 1.1.29 - google for it.

cd anyterm
make
Wait ages.

sudo cp anytermd /usr/bin
anytermd -p 7777 --local-only
This sets up anytermd on port 7777

sudo a2enmod proxy ssl proxy_http
sudo service apache2 restart

sudo nano /etc/apache2/mods-enabled/proxy.conf
change to
Order allow,deny
Allow from all

save and exit nano
sudo mkdir /etc/apache2/ssl
sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/domain.pem

use cursor keys to select ok and press enter on each
sudo nano /etc/apache2/sites-available/anyterm
add the following lines:

<VirtualHost _default_:443> # HTTPS port
ServerName _default_
<Location /term>
ProxyPass http://localhost:7777 ttl=60
ProxyPassReverse http://localhost:7777
AuthType Basic
AuthName "domain"
require valid-user
AuthUserFile /etc/apache2/passwds/.passwdAnyterm
</Location>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/domain.pem
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>

Now save and exit nano.

sudo a2ensite anyterm
sudo service apache2 reload


sudo mkdir /etc/apache2/passwds
sudo htpasswd -c /etc/apache2/passwds/.passwdAnyterm pi

then asks to enter password and re-enter it

Now you can log in to your terminal at
https://localhost/term

PHP5
sudo apt-get install php5
sudo reboot

Now need to restart PuTTY as the pi has rebooted.

cd /var/www
sudo nano phpinfo.php


enter

<?php
phpinfo();
?>


save and exit nano and go to http://localhost/phpinfo.php to see php5 is installed


net2ftp


cd ~
cd tmp
mkdir net2ftp
cd net2ftp
sudo wget http://net2ftp.com/download/net2ftp_v0.98.zip
sudo unzip net2ftp_v0.98.zip
cd net2ftp_v0.98
sudo mv files_to_upload /var/www/
cd /var/www/
sudo mv files_to_upload ftp
cd ftp
sudo chmod 777 -R temp
sudo nano settings.inc.php
now set admin password to something as leaving blank won't let you log in
set log to never, or none
save and exit

vsftpd
cd ~
sudo apt-get install vsftpd
cd /etc
sudo nano vsftpd.conf
enabled (unhashed) write_enable=YES anon_upload_enable=YES anon_mkdir_write_enable=YES
save and exit
sudo /etc/init.d/vsftpd restart
cd /srv/ftp
Copy /get files here

The root folder cannot be 777 otherwise vsftpd wont let you log in.

cd /srv
sudo chmod 755 ftp
cd ftp
mkdir stuff
sudo chmod 777 stuff


Test using FTP
sudo apt-get install ftp
ftp -p 127.0.0.1
anonymous as user
no password

vsftpd with virtual users
Anonymous users are no good, so setup virtual users with passwords.
I found out how to do this after setting up anonymous usage.

Based on:
http://sigerr.org/linux/setup-vsftpd-custom-multiple-directories-users-accounts-ubuntu-step-by-step

sudo apt-get install vsftpd libpam-pwdfile
sudo mv /etc/vsftpd.conf /etc/vsftpd.conf.bak
sudo nano /etc/vsftpd.conf

Create with only these lines:
listen=YESanonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
nopriv_user=vsftpd
virtual_use_local_privs=YES
guest_enable=YES
user_sub_token=$USER
local_root=/var/www/$USER
chroot_local_user=YES
hide_ids=YES
guest_username=vsftpd

Save and exit nano.

sudo mkdir /etc/vsftpd
mv /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak
sudo nano /etc/pam.d/vsftpd

Create with only these lines:

auth required pam_pwdfile.so pwdfile /etc/vsftpd/ftpd.passwd
account required pam_permit.so

Should this be sudo? Not sure:
useradd --home /home/vsftpd --gid nogroup -m --shell /bin/false vsftpd

sudo /etc/init.d/vsftpd restart

Do for each user:
sudo htpasswd -c -d -b /etc/vsftpd/ftpd.passwd user1 user1pwd
sudo mkdir /var/www/user1
sudo mkdir /var/www/user1/www
sudo chmod 555 /var/www/user1
sudo chmod 755 /var/www/user1/www
sudo chown -R vsftpd:nogroup /var/www/user1

sudo /etc/init.d/vsftpd restart

Admin user:
sudo htpasswd -c -d -b /etc/ftpd.passwd theadmin theadminpwd
sudo nano /etc/vsftpd.conf
add:
chroot_list_enable=YES
save and exit nano
sudo nano /etc/vsftpd.chroot_list
add:
theadmim

save and exit nano

sudo /etc/init.d/vsftpd restart


mysql
sudo apt-get update
sudo apt-get mysql-server
enter new root password (normal)
sudo apt-get mysql-client
sudo apt-get php5-mysql
sudo reboot

phpmyadmin
apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
Select space on apache to select it
Press enter on next screen
Enter the password we just entered for the mysql root user (normal)
Enter password for phpmyadmin (normal)
Re-enter it when asked

sudo nano /etc/php5/apache2/php.ini
Goto 'Dynamic Extensions' section and uncomment the line
extension=mysql.so
save and exit nano
Goto http://192.168.0.7/phpmyadmin/
Enter user as root and the password we just set

wiki
cd /var/www
sudo wget http://wikkawiki.org/downloads/Wikka-1.3.3.zip
Note the case of the 'W' in Wikka
sudo unzip Wikka-1.3.3.zip
sudo mv Wikka-1.3.3/ wiki
sudo chmod 777 /var/www/wiki/config
sudo chmod 777 /var/www/wiki
cd wiki
cd setup
sudo nano install.php
Change all sql TYPE= to ENGINE=
It appears that in MySQL 5.1, support for the TYPE keyword was finally removed.
save and exit nano

Goto http://192.168.0.7/phpmyadmin/
Create a new database called wiki
Goto http://192.168.0.7/wiki/
MySQL host: localhost
MySQL database: wiki
MySQL user name: root
MySQL password: ?????
Table prefix: wikka
Your Wiki suffix: wikkamain
Enter Administrative Account Configuration
User: PiUser
Pwd: ?????

return priviledges to folders
sudo chmod 755 /var/www/wiki/config
sudo chmod 755 /var/www/wiki

coppermine migration
sudo mkdir /var/www/skitour
cd /var/www/skitour
sudo wget -m ftp://username:password@ftp.ski-tour.co.uk/www/gallery


move the downloaded gallery folder to /var/www/skitour/
goto ski-tour.co.uk cpanel then phpmyadmin
click on the coppermine database (skitou_ski) then select the export button
you end up with a .sql file
log in to the pi phpmyadmin console
create a new database called skitou_ski
create a new user called skitou_skitour with same password as the old skitour user
to find the old password open /skitour/gallery/include/config.inc.php
when creating the user make the host=localhost
now set the user privileges
go to the phpmyadmin main page
select Privileges at the top
select Edit Provileges next to the skitou_skitour user
set the Global Priveleges to all (select all checkboxes)
scroll down and at the Database-specific privileges
select Add privileges on the following database: skitou_ski
set the privileges to all (select all checkboxes)
now select the skitour_ski database and select Import button
choose the .sql file you exported earlier
Now go to 192.168.0.7/skitour/gallery to test it works


upgrading coppermine
The old one was 1.4.0.
Download 1.4.27 and unzip on the PC
From the unzipped files delete the albums folder, themes/classic folder, include/config.inc.php and anycontent.php.
Using filezilla upload all files to pi user. These end up in /var/www/pi/www/
copy the files over the existing ones
cd /var/www/pi/www
yes | sudo cp -r gallery/* /var/www/skitour/gallery/



tried this but did not allow me to co
http://trikks.wordpress.com/2010/06/15/setup-a-subversion-svn-server-in-debian/
I changed SVNParentPath /var/svn
then it worked
Need to clean up the other users and chowns I did!


sudo htpasswd  -c -d -b /etc/apache2/dav_svn.passwd user password

sudo mkdir -p /var/svn/poo
sudo svnadmin create /var/svn/poo
sudo chown -R www-data:www-data /var/svn/poo
svn co http://localhost/svn/poo

svn ci
then enter a checkin note and save and exit


cd ~
mkdir poostuff
sudo echo "stuff" >> ~/poostuff/flap.txt
svn import -m ~/poostuff/ http://localhost/svn/poo

pi user
normal password works and the one i added using htpasswd
what happens if username created with htpasswd is not the same as pi?


websvn
I did
sudo apt-get update
sudo apt-get install enscript
sudo spt-get install websvn
During install chose /var/svn for parent then added only /var/svn/poo as repository
Then did no more
Try this:
http://blog.mattsch.com/2011/03/21/setting-up-apache-and-subversion-on-debian-squeeze/

























No comments:

Post a Comment