Problem is that you find many advices for your total setup, and then the question is:
which part did I use from which website?
It makes a webserver that displays a page from which a LED can be switched on and off.
Very simple basics, but the steps are there, and can be followed. Easy when you update or change SD card or just want to clean up and start fresh.
Google on parts of the text will probably give the original websites
Step 1 Download Image
a. Download the image from a mirror or torrent http://www.raspberrypi.org/downloads
b. Extract the image file debianXXXXXX.img from the debianXXXXXXdirectory in the debianXXXXXX.zip
c. Insert the SD card into your SD card reader and check what drive letter it was assigned. You can easily see the drive letter (for example G:) by looking in the left column of Windows Explorer.
d. Download the Win32DiskImager utility. The download links are on the right hand side of the page, you want the binary zip.
e. Extract the zip file and run the Win32DiskImager utility. You may need to run the utility as Administrator.
f. Select the debianXXXXXX.img image file you extracted earlier
g. Select the drive letter of the SD card in the device box. Be careful to select the correct drive; if you get the wrong one you can destroy your computer's hard disk!
h. Click Write and wait for the write to complete.
i. Exit the imager and eject the SD card.
j. Insert the card in the Raspberry Pi, power it on, and it should boot up. Have fun!
Step 2 Startup
- Enable SSH
- Reformat to use all the space on SD Card
Step 3 Change the hostname: After SAMBA this works
!! do this from the HDMI screen... eth0 must go down and up
"sudo -i" [Return / Enter key]
"nano /etc/dhcp/dhclient.conf" [Return / Enter key]
Now look for the line "#send host-name "xxxxxx";" (on mine, xxxxxx is andare.fugue.com), and remove the "#" symbol from in front of it.
Then type "hostname xxxxxx" where "xxxxxx" is what you want to call your server (I chose "raspberryPi" to make it easy).
Please Note that you cannot have any spaces in the hostname.
Finally for this step, type in "ifdown eth0" and hit Return / Enter.
Once that has finished, type "ifup eth0" and hit Return / Enter.
To change the default password, start an SSH session (* Putty to IP nbr *), and login,
then type "sudo -i", hit Return / Enter,
then type "passwd pi" and hit Return / Enter.
Then you can type in your new password, it will ask you to confirm the password.
Step 4 Install Apache with PHP
Type in "sudo apt-get update"
Once this is complete, you may receive an error, just run the same command again to resolve this.
Then type "sudo apt-get install apache2 php5 libapache2-mod-php5"
It will say "Do you want to continue", just press "y" and hit Return / Enter.
Wait for this to finish (as it may take a while).
When it is finished, you may have noticed that there was an error, to solve this,
type "sudo groupadd www-data", then
"sudo usermod -g www-data www-data".
Now restart apache with
"sudo service apache2 restart". This time there should be no errors.
If you now start a web browser on your computer, and type your hostname into the address bar, you will get the apache installed page.
To enable htaccess files you must modify the config files, like so:
Type "sudo nano /etc/apache2/sites-enabled/000-default" and hit Return / Enter.
You'll see a line like the following:
"AllowOverride None" - change this to "AllowOverride ALL". (see image for more detail)
Then hold the Ctrl button and press the "x" key, then press "y" when prompted and hit Return / Enter.
Now restart apache with "sudo service apache2 restart".
Step 5 Install MySQL
Type in "sudo apt-get install mysql-server mysql-client php5-mysql" and hit Return / Enter.
You will be asked "Do you want to continue?", press the "y" key, then Return / Enter.
This will take a while to download and install, but a screen will appear asking you to set
"New password for the MySQL "root" user", enter a password, then confirm it. Password: root
Again, wait a while, then you're done.
Step 6 Install an FTP server
Type in "sudo chown -R pi /var/www" <-- IMPORTANT (otherwise you won't be able to upload anything)
Type in "sudo apt-get install vsftpd" and hit Return / Enter
Now type in "sudo nano /etc/vsftpd.conf" and hit Return / Enter
Search through the file and change the following lines:
anonymous_enable=YES Change To anonymous_enable=NO
#local_enable=YES Change To local_enable=YES
#write_enable=YES Change To write_enable=YES
#local_umask=022 Change to local_umask=022
Also, add a line to the bottom of the file:
force_dot_files=YES
Then hold the Ctrl key and press "x", then "y", then the Return / Enter key.
Now restart the FTP server with
"sudo service vsftpd restart"
At the moment you will need to change the directory every time you login by FTP, to solve this:
% THIS DID NOT WORK WELL, MAYBE BECAUSE PI WAS LOGGED IN THE MAIN (HDMI) SCREEN?
% Type:
% "sudo -i"
% "passwd root"
% Type in any password (this is only temporary)
% "exit"
% "exit"
%
% Start a new SSH session
% Username: root
% Password (the one you just set)
% "nano /etc/passwd"
% find the line "pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash" and change it to "#pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash".
% Then hold the Ctrl key and press "x", then release Ctrl and press "y" then hit Return / Enter.
% "usermod -d /var/www pi"
%
% Now close the SSH session, and start a new one with username: pi and your password, and type the following:
%
% "sudo -i"
% "usermod -L root"
% "exit"
Now you are able to connect to your Raspberry Pi with an FTP client, using the following information:
Host: (Hostname you set - I used raspberryPi)
Username: pi
Password: (Password you set previously)
Port: 21
Step 7 Installing phpMyAdmin
Installing phpMyAdmin is a simple task.
1. Go to http://www.phpmyadmin.net
2. Download the zip file
3. Extract it to a folder
4. Upload the extracted files to your server (you may need to set permissions)
Step 8 Tightvncserver
Log in to your Pi and install the Tight VNC Package
"sudo apt-get install tightvncserver"
Next Run TightVNC Server which will prompt you to enter a Password and an optional View Only Password
"tightvncserver"
Once that is done you can run it straight from the prompt I am using 1920x1080 which is my monitor maximum resolution.
"vncserver :1 -geometry 1920x1080 -depth 24"
Or you could create a script to save typing in the whole thing.
"nano svnc.sh" (call the file whatever you like)
Add the lines:
Code: Select all
#!/bin/sh
vncserver :1 -geometry 1920x1080 -depth 24
Set the file to Execute
"chmod +x svnc.sh"
then to run
" ./svnc.sh"
Run at boot:
Start a root session
"sudo bash" % I did sudo nano
Create a file in /etc/init.d with a suitable name such as vncboot with the following content.
Code: Select all
### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO
#! /bin/sh
# /etc/init.d/vncboot
USER=root
HOME=/root
export USER HOME
case "$1" in
start)
echo "Starting VNC Server"
#Insert your favoured settings for a VNC session
/usr/bin/vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565
;;
stop)
echo "Stopping VNC Server"
/usr/bin/vncserver -kill :1
;;
*)
echo "Usage: /etc/init.d/vncboot {start|stop}"
exit 1
;;
esac
exit 0
Modify the file permissions so it can be executed
"chmod 755 /etc/init.d/vncboot"
%Enable dependency based boot sequencing
%"update-rc.d /etc/init.d/vncboot defaults"
%
%If enabling dependency based boot sequencing was successful, it says
% update-rc.d: using dependency based boot sequencing
%
%But if it says
%update-rc.d: error: unable to read /etc/init.d//etc/init.d/vncboot
%
%then try the following command
update-rc.d vncboot defaults
Reboot your Raspberry PI and you should find a vncserver already started.
Here I start VNCServer up from commandline first, so that pw is set. VNC client can not set that.
Step 9 make apache be able to execute GPIO commands
Use visudo to modify sudoers to:
Code: Select all
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE DISPLAY PATH"
Defaults exempt_group = users
# Host alias specification
# User alias specification
User_Alias APACHE = www-data
# Cmnd alias specification
Cmnd_Alias GPIOSTUFF = /home/pi/tog1
# User privilege specification
root ALL=(ALL) ALL
suse ALL=(ALL) ALL
pi ALL=(ALL) ALL
APACHE ALL=(ALL) NOPASSWD: GPIOSTUFF
# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
%users ALL=(ALL) ALL
Step 10, Create a command to control a LED between pin 5 and 6 of GPIO port.
LED CONNECTION:
Use a led and a resistor of 270Ohm .
Cathode of led connects to pin 6,
Anode to resistor
other side of resistor to pin 5.
make a new file in /home/pi called tog1.c and copy this content in
Code: Select all
/*
* gpio_relay.c - example of driving a relay using the GPIO peripheral on a BCM2835 (Raspberry Pi)
*
* Copyright 2012 Kevin Sangeelee.
* Released as GPLv2, see <http://www.gnu.org/licenses/>
*
* Modified by Ton Augustin for very simple RPi setup: Use Bit 1 instead of Bit 17
* This is intended as an example of using Raspberry Pi hardware registers to drive a relay using GPIO. Use at your own
* risk or not at all. As far as possible, I've omitted anything that doesn't relate to the Raspi registers. There are more
* conventional ways of doing this using kernel drivers.
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#define IOBASE 0x20000000
#define GPIO_BASE (IOBASE + 0x200000)
#define GPFSEL0 *(gpio.addr + 0)
#define GPFSEL1 *(gpio.addr + 1)
#define GPFSEL2 *(gpio.addr + 2)
#define GPFSEL3 *(gpio.addr + 3)
#define GPFSEL4 *(gpio.addr + 4)
#define GPFSEL5 *(gpio.addr + 5)
// Reserved @ word offset 6
#define GPSET0 *(gpio.addr + 7)
#define GPSET1 *(gpio.addr + 8)
// Reserved @ word offset 9
#define GPCLR0 *(gpio.addr + 10)
#define GPCLR1 *(gpio.addr + 11)
// Reserved @ word offset 12
#define GPLEV0 *(gpio.addr + 13)
#define GPLEV1 *(gpio.addr + 14)
#define BIT_1 (1 << 1)
#define BIT_17 (1 << 17)
#define PAGESIZE 4096
#define BLOCK_SIZE 4096
struct bcm2835_peripheral {
unsigned long addr_p;
int mem_fd;
void *map;
volatile unsigned int *addr;
};
struct bcm2835_peripheral gpio = {GPIO_BASE};
// Some forward declarations...
int map_peripheral(struct bcm2835_peripheral *p);
void unmap_peripheral(struct bcm2835_peripheral *p);
int gpio_state = -1;
////////////////
// main()
////////////////
int main(int argc, char *argv[]) {
if(argc == 2) {
if(!strcmp(argv[1], "on"))
gpio_state = 1;
if(!strcmp(argv[1], "off"))
gpio_state = 0;
}
if(map_peripheral(&gpio) == -1) {
printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
return -1;
}
/* Set GPIO 17/1 as an output pin */
GPFSEL0 &= ~(7 << 3); // Mask out bits 5-3 of GPFSEL0 (i.e. force to zero)
GPFSEL0 |= (1 << 3); // Set bits 5-3 of GPFSEL0 to binary '001'
if(gpio_state == 0)
GPCLR0 = BIT_1;
else if(gpio_state == 1)
GPSET0 = BIT_1;
usleep(1); // Delay to allow any change in state to be reflected in the LEVn, register bit.
printf("GPIO 1 is %s\n", (GPLEV0 & BIT_1) ? "high" : "low");
unmap_peripheral(&gpio);
// Done!
}
// Exposes the physical address defined in the passed structure using mmap on /dev/mem
int map_peripheral(struct bcm2835_peripheral *p)
{
// Open /dev/mem
if ((p->mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
printf("Failed to open /dev/mem, try checking permissions.\n");
return -1;
}
p->map = mmap(
NULL,
BLOCK_SIZE,
PROT_READ|PROT_WRITE,
MAP_SHARED,
p->mem_fd, // File descriptor to physical memory virtual file '/dev/mem'
p->addr_p // Address in physical map that we want this memory block to expose
);
if (p->map == MAP_FAILED) {
perror("mmap");
return -1;
}
p->addr = (volatile unsigned int *)p->map;
return 0;
}
void unmap_peripheral(struct bcm2835_peripheral *p) {
munmap(p->map, BLOCK_SIZE);
close(p->mem_fd);
}
"cc tog1.c"
Test with
" ./a.out on"
" ./a.out off"
rename a.out to tog1
"mv ./a.out ./tog1"
Step 11, a php file
Create a php file
tog.php:
Code: Select all
<html>
<head>
</head>
<body>
<?php
if (array_key_exists('submit_check',$_POST) && ($_POST['submit_check'] != "0") ) {
if (array_key_exists('on',$_POST)) {
echo shell_exec("sudo /home/pi/tog1 on 2>&1");
}
if (array_key_exists('off',$_POST)) {
echo shell_exec("sudo /home/pi/tog1 off 2>&1");
}
}
?>
<form method="post">
<input type="hidden" name="submit_check" value="1"/>
<input type="submit" name="on" value="on" />
<input type="submit" name="off" value="off" />
</form>
</body>
</html>
Step 12 samba
"sudo apt-get install samba"
save org conf file:
"sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old"
"sudo nano /etc/samba/smb.conf"
Search for the section marked ##### Authentication #####
Change the text
# security = user
to
security = user
"sudo /etc/init.d/samba restart"
"sudo nano /etc/samba/smb.conf"
Search for the section starting [homes]
In the [homes] section, change from
read only = yes
to
read only = no
"sudo /etc/init.d/samba restart"
"sudo apt-get install samba-common-bin"
"sudo smbpasswd -a pi"
"sudo mkdir /home/shares"
"sudo mkdir /home/shares/public"
"sudo chown -R root:users /home/shares/public"
"sudo chmod -R ug=rwx,o=rx /home/shares/public"
"sudo nano /etc/samba/smb.conf"
In smb.conf change WORKGROUP to your workgroup
append at end of file:
[public]
comment = Public Storage
path = /home/shares/public
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
read only = no
[edit obarthel: fixed "./tog1"]