This is my first Instructable so all criticisms and comments are welcome.
This will show you how to set up a simple wired web server on your Raspberry Pi, with PHP and MySql.
The Raspberry Pi is a good choice for a webserver that will not recieve too much traffic, such as a testing server, or small intranet, as it doesn;t get too hot (so is nice and quiet), and only uses around 5 Watts of power (costing £3.50 a year where I am if it's running 24/7)
In the future I might add how to set up a wireless server.
If you have any problems, post them in the comments, or PM me - I'm happy to help.
Remove these ads by
Signing UpStep 1: You will Need
1. A power supply (Micro USB)
2. A network cable
3. A HDMI cable (or Component cable) as well as a screen and USB keyboard
3. A Raspberry Pi
4. An SD card (2GB or more)
5. An SD card reader for your computer
6. Win32DiskImager (For Windows) or dd (for Unix)
7. The Raspberry Pi Debian Image
8. PuTTY (For Windows) or any other SSH client
9. Around an hour of free time
You can download the software from the following locations:
http://www.softpedia.com/get/CD-DVD-Tools/Data-CD-DVD-Burning/Win32-Disk-Imager.shtml (for Win32DiskImager)
http://downloads.raspberrypi.org/download.php?file=/images/debian/6/debian6-19-04-2012/debian6-19-04-2012.zip (Debian Image)
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html (for PuTTY)













































Visit Our Store »
Go Pro Today »




1. Grant access to your remote machine using: GRANT ALL ON *.* TO 'root'@'192.168.1.%' IDENTIFIED BY 'your_password_here'; (I used 192.168.1.% so that any computer on my network can connect to it)
2. Go into the my.cnf file (sudo nano /etc/mysql/my.cnf) file and look for "bind-address" and comment this out (put a # in front of the line)
3. Reload MySQL config (service mysql reload)
4. Restart MySQL server (service mysql restart)
Hope this helps, and thank you for the great Instructable :)
Thanks for posting this to help others :)
Daniel
I do have 1 question. Why wouldn't you use the SFTP supplied with the SSH protocol as opposed to installing an additional ftp server (vsftp)?
Glad it was useful.
Honestly, I wasn't aware of the program (SFTP) until you mentioned it, I'll have a look into that.
Many thanks, Dan.
all in all a very good Tutorial
This is usually a router issue, which OS do you use at the moment?
Can you try a "ping" command (or equivalent) with the host name?
What's the output?
Many thanks, Dan.
#send host-name "xxxxxxxx"
send host-name = gethostname()
I commented out the second one and changed the host name in quotes to raspberryPi then set it in the command line but I cannot connect to it via Putty (I still have to use the IP address)
Also in step 9, my vsftpd file is blank. Not sure what I'm doing wrong.
I get as far as adding the # in the /etc/passwd file. However when I try to add pi as a mod it throws up the error that the user pi does not exist. Assuming this was the desired outcome, I try the last few steps and try to login as pi however it says access denied no matter how many passwords I try to enter for pi (the password for root, my chosen pi password and the default one - neither work).
This only seems logical, as I had just commented out the user pi in the previous file, surely?
Ignoring this set back, since it appears to be an optional step, I successfully connect to the FTP server but my FTP directory looks much different to the one in your screenshot despite being the same directory (/home/pi).
Any ideas? Thanks.
I think the distribution has changed since I wrote this.
Try leaving the user "pi" in as normal (Leave out the #).
Many thanks, Dan.
You say:"At the moment you will need to change the directory every time you login by FTP", then some magic, concluded by:
usermod -d /var/www pi
I'm a Linux n00b, so please correct me if I'm wrong. The usermode -d changes the default home path for user Pi, right? That is, not only when logging in via FTP, but also when logging in via SSH, or anything else, right?
With Filezilla (and probaby many others) this is not necessary. But more importantly, I wonder whether or not the usermod is a good idea at all. I had the webserver up & running, no problem. But then I installed some more stuff, which then of course, landed in /var/www. Which looks a bit messy to me. It may be prone to hacking, I don't know.
Any learned comments?
Thanks for the comments.
As I understand it vsftp is a "thin" server, as in it doesn't use that much in the way of resources.
The better approach for vsftp is to use a dedicated FTP user and set that user's home directory to var/www.
Other than that, a server like FileZilla would be a good idea, I was just trying to use as little of the raspberry pi's few resources as possible.
As far as security, I don't believe that there would be any issues due to the user's home directory, however it is a good question.
Many thanks, Dan.
sudo apt-get install phpmyadmin
WAIT FOR IT TO INSTALL
nano /etc/apache2/apache2.conf
AT THE END OF THAT FILE TYPE
#Include phpmyadmin
Include /etc/phpmyadmin/apache.conf
SAVE THE FILE THEN
service apache2 restart
then navigate to:
http://HOSTNAME HERE/phpmyadmin
Let me know how it goes, Dan.
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* forms frameset
*
* or common.inc.php
* @package PhpMyAdmin
*/
/**
* Gets core libraries and defines some variables
*/
require_once './libraries/common.inc.php';
// free the session file, for the other frames to be loaded
session_write_close();
// Gets the host name
if (empty($HTTP_HOST)) {
if (PMA_getenv('HTTP_HOST')) {
$HTTP_HOST = PMA_getenv('HTTP_HOST');
} else {
$HTTP_HOST = '';
}
}
// purge querywindow history
$cfgRelation = PMA_getRelationsParam();
if ($GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork']) {
PMA_purgeHistory($GLOBALS['cfg']['Server']['user']);
}
unset($cfgRelation);
/**
* pass variables to child pages
*/
$drops = array('lang', 'server', 'collation_connection',
'db', 'table');
foreach ($drops as $each_drop) {
if (array_key_exists($each_drop, $_GET)) {
unset($_GET[$each_drop]);
}
}
unset($drops, $each_drop);
if (! strlen($GLOBALS['db'])) {
$main_target = $GLOBALS['cfg']['DefaultTabServer'];
} elseif (! strlen($GLOBALS['table'])) {
$_GET['db'] = $GLOBALS['db'];
$main_target = $GLOBALS['cfg']['DefaultTabDatabase'];
} else {
$_GET['db'] = $GLOBALS['db'];
$_GET['table'] = $GLOBALS['table'];
$main_target = ! empty($GLOBALS['goto']) ? $GLOBALS['goto'] : $GLOBALS['cfg']['DefaultTabTable'];
}
$url_query = PMA_generate_common_url($_GET);
if (isset($GLOBALS['target']) && is_string($GLOBALS['target']) && !empty($GLOBALS['target']) && in_array($GLOBALS['target'], $goto_whitelist)) {
$main_target = $GLOBALS['target'];
}
$main_target .= $url_query;
$lang_iso_code = $GLOBALS['available_languages'][$GLOBALS['lang']][1];
// start output
require './libraries/header_http.inc.php';
?>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
xml:lang=""
lang=""
dir="">
phpMyAdmin <?php echo PMA_VERSION; ?> - <br /> <?php echo htmlspecialchars($HTTP_HOST); ?>
echo PMA_includeJS('jquery/jquery-1.6.2.js');
echo PMA_includeJS('update-location.js');
echo PMA_includeJS('common.js');
?>
Can you add the following to the top of the page:
echo "test";
die();
and try that - you should see "test" on screen when you go to the page.
Thanks, Dan.
do not see a admin.php?
Thanks
What are the permissions of the page?
What is the URL you are typing in? (including page)
What is the content of admin.php?
Many thanks, Dan.
Now restart the FTP server with "sudo servce vsftpd restart"
but i think it must be:
Now restart the FTP server with "sudo serivce vsftpd restart"
Thanks for that, yeah it should be "service".
Many thanks, Dan.
@Dan thanks for your answer.
I just reainstalled Everything and now it works (must have missed something after all)...
Now is my next problem that i can't portforward port 1433 and 3306 for MySql and MSSQL... but that's Thomsons fault NEVER buy a TG789VN...
i get below error
Forbidden
You don't have permission to access /admin/phpMyAdmin on this server.
Does any one have any idea about what can be wrong?
What have you set the permissions for the files as?
Can you access any other page you've got on the pi?
Many thanks, Dan.
'usermod -d /var/www pi' changes the user's home directory from the default (/home/pi) to the directory /var/www. This will alter the line in the /etc/passwd file. Copying the original line and commenting it out essentially keeps a "backup" of what the line used to say.
That's what I'm assuming anyway, and is what I did. When you FTP using your username and password, you are directed to /var/www immediately. Hope that all makes sense.
Anyway, i do not think that this is a popper solution. Please correct this manual :) Thanks!
After commenting out the /etc/passwd line, the above command doesn't find the username pi. I also can't create a new ssh session as pi. Did I miss something?
The answer to my problem is here: http://forums.debian.net/viewtopic.php?f=30&t=50502
You need to change the ownership of the folder to "www-data". I have no idea what means, I´m still new to to linux, but that solves it.
In case you still need help (looks like you beat me to it :) ) to change the owner of a directory the command is "chown".
For example "chown www-data /home/pi/apache".
Hope this helps, if not then let me know :)
Thanks, Dan.
After successfully setting up apache in the default configuration, I wanted to change the root directory to "/home/pi/apache". Changing the respective configurations in the 000-default file I get a "403 - Permission denied" error.
I have tried everything I could find on google - I changed both the "DocumentRoot = PATH" and "", the later once with quotation marks and once without. I have also done "chmod -R 755 PATH" for the directory itself and all it´s parents.
Here is a good summery of what I tried: http://www.cyberciti.biz/faq/apache-403-forbidden-error-and-solution/
However none of this had any effect. I have also read that something called "selinux" might interfere, but from what I understand it is not installed on raspbian.
Does anyone have successfully changed their DocumentRoot? Any ideas on what is causing the issue?
"http://RASBERRYPI IP/phpmyadmin"
Many thanks, Dan
had a go at running the above line as I couldn't get the phpadmin to run in a web browse.
Doing the above I still can't get it to run, when I look on the ftp it appears to be in
/var/lib/phpmyadmin
where as I was expecting to see it in /var/www/admin
where am I going wrong?
My thinking is that Raspberry Pi is targeting students/beginners who will benefit from understanding WHY they are running apt-get update, what the mySQL server is used for, etc.
It's just personal preference. I Prefer to have all of the web files accessible in the var/www directory as it saves time when editing a lot of different files.
However "apt-get install phpmyadmin" may have been easier for some people to understand.
So like I said, just personal preference.
Many thanks, Dan.
Now navigate to where you installed phpMyAdmin (for me it's http://raspberryPi/admin)
All the step previous to this went ok but how can you navigate to http://raspberryPi/admin remotely ?
Am i missing something?
I can ssh into my pi remotely and have copied over all the phpadmin stuff using an FTP client but from here on i am stuck.
What I meant was to use a web browser on another computer on the same LAN to connect to the raspberry pi.
Hope thIs helps, if not then let me know.
Many thanks, Dan.
Things to note: If I try opening my external IP through my browser, I get the router's configuration page. Apparently that only works from inside my network, since I asked a friend to open the page and he just saw an error page.
Another thing: If I try using WINSCP with the external IP, I get a "computer actively denied the connection"...
I'm lost, right now... My router is a Huawey b260a (http://www.manualowl.com/m/Huawei/B260a/Manual/257649)
I tried changing ports to no avail...
Any help is deeply appreciated
Thanks
What is the URL that you're being redirected to?
Have you tried changing the database login details?
Dan
What are the permissions settings for the web page?
They should be 755.
Thanks, Dan.
Cheers,
Matt
Could not open (for me): http://192.168.1.91/admin?
I can connect using putty but have to give the IP address (192.168.0.98) to connect. Once connected and logged in, I can type "hostname" and the reply is "raspberrypi" but I can't connect as raspberrypi, only 192.168.0.98 - What am I being dumb and missing, please? :(
If you're using windows, open cmd and type in:
"ping raspberrypi".
Mac:
Go to Applications > Utilities > Network Utility.
Click on the Ping tab and type "raspberrypi" as the host name. Then click ping.
Linux (desktop):
Open terminal and type "ping raspberrypi".
Let me know what the output is. Dan.
ping raspberrypi returns "Ping request could not find host raspberrypi. Please check the name and try again."
My PuTTY session looks like the screenshot (prompt is pi@raspberrypi:~$) although I connect as 192.168.0.98 (i.e. top of screen says
login as: pi
pi@192.168.0.98's password:
typing hostname returns raspberrypi
the line in /etc/dhcp/dhclient.conf is:
send host-name "raspberryPi";
(capital P, same as yours...)
Really scratching my head because I've done everything twice and it's still off :(
The IP number is assigned by the router (i.e. reserved address of 192.168.0.98), if that's what causing the problem?
Any help greatly appreciated :)
What router are you using as it may be set to not allow host name connection?
http://helpforum.sky.com/t5/Sky-Broadband-Setup-Cabling/New-Sagem-Router-host-name-problems/td-p/365775
Looks like it's a known issue with the router.
Thanks for pointing me in the right direction :)
121009 7:46:38 [Note] Plugin 'FEDERATED' is disabled.
121009 7:46:38 InnoDB: The InnoDB memory heap is disabled
121009 7:46:38 InnoDB: Mutexes and rw_locks use GCC atomic builtins
121009 7:46:38 InnoDB: Compressed tables use zlib 1.2.7
121009 7:46:39 InnoDB: Using Linux native AIO
121009 7:46:39 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(135987200 bytes) failed; errno 12
121009 7:46:39 InnoDB: Completed initialization of buffer pool
121009 7:46:39 InnoDB: Fatal error: cannot allocate memory for the buffer pool
121009 7:46:39 [ERROR] Plugin 'InnoDB' init function returned error.
121009 7:46:39 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
121009 7:46:39 [ERROR] Unknown/unsupported storage engine: InnoDB
121009 7:46:39 [ERROR] Aborting
121009 7:46:39 [Note] /usr/sbin/mysqld: Shutdown complete
[FAIL] Starting MySQL database server: mysqld . . . . . . . . . . . . . . failed!
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing mysql-server-5.5 (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up php5-mysql (5.4.4-7) ...
Setting up mysql-client (5.5.24+dfsg-9) ...
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.5; however:
Package mysql-server-5.5 is not configured yet.
dpkg: error processing mysql-server (--configure):
dependency problems - leaving unconfigured
Processing triggers for libapache2-mod-php5 ...
[ ok ] Reloading web server config: apache2.
Errors were encountered while processing:
mysql-server-5.5
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
pi@raspberrypi ~ $ dpkg -l | grep php5-mysql
pi@raspberrypi ~ $ dpkg -l | grep mysql-server
iF mysql-server-5.5 5.5.24+dfsg-9 armhf MySQL database server binaries and system database setup
ii mysql-server-core-5.5 5.5.24+dfsg-9 armhf MySQL database server binaries
pi@raspberrypi ~ $ dpkg -l | grep mysql-client
ii mysql-client-5.5 5.5.24+dfsg-9 armhf MySQL database client binaries
**the main problem should be that it fails to start the mysql database server....any suggestions how to fix it? thanks!
solution::
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=19277&p=191839#p191839
I'd like to leave a suggestion: to use nginx instead of Apache. nginx is very light and has a simpler configuration. I think it fits better in Raspi's limited configuration. Also, the more you avoid unneccessary CPU usage with heavy applications, less heat is produced by the processor, so, the more your Raspi will last!
Regards,
I believe the command is "ifconfig" to view the iP address on the pi, although I'm not sure as I'm away at the moment with no access to a pi.
Daniel.
by the way, one more thing, I am still unable to use the "hostname", instead I am using the PI internal IP.
Thank you for the great work.
The host name issue is possibly caused by your router setup, so well deal with that in a bit.
With regards to accessing the pi over the Internet, please note that you should setup a firewall on the pi first.
What type of router do you have?
You need to setup port forwarding of ports:
80 - apache web server
443 - apache https server
21 - FTP
They need to be forwarded to the raspberry pi's internal up address.
If you don't know how to do this, let me knOw what type of router you have, and I'll try to help. Daniel.
Thanks for the quick reply, my router is a sagecom 2504FA@STn my ISP is sky.
I remember opening a port for an IP camera, I guess this should be similar with the difference that more services have to be created and different ports assigned. Does the internal IP for the three different services, (Apache, FTP, MySql), change or it remains the IP for the raspberry Pi?
Here is the error...
FTP folder Error
An error occured copying a file to the FTP Server. Make sure you have permission to put files on the server.
Details:
200 Switching to Binary Mode.
227 Entering Passive Mode (192.168,0,197,138).
553 Could not create file.
Very thorough directions. Wonderful instructable.
I have the same error (553 Could not create file) but I cannot find what I skipped during the FTP setup.
Could you help me what was the reason for you to receive this error?
Thank you.
"sudo chown -R pi /var/www"
Let us know how you get On. Daniel.
Let us know how you get on. Daniel.
Yes, that was the problem! Although I remembered issuing this command, I had to do it again. Im not sure what i did wrong... Great tutorial anyways!
Are you trying to connect via hostname or ip?
Could you please post a copy of the connection info (excepting the password) that you are trying to connect with?
Many thanks, Daniel.
Daniel.
Have you tried restarting the Raspberry Pi, unplugging it, starting it, plugging it back in then restarting it?
That may help, if not - let me know.
Daniel.
Yes - replace "andre.fugue.com" with anything you want - No spaces allowed, and only some special characters will work :D
Daniel
I'm having trouble setting up the FTP part from:
At the moment you will need to change the directory every time you login by FTP, to solve this:
I do get to set the password for root, but do you mean "exit", "exit" to use as a password?
Then I don't get the part:
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".
In my "/etc/passwd" file it has this line uncommented. So I comment is as you say, but then I won't be able to connect to the device again? Because after commenting, this command:
"usermod -d /var/www pi"
Say the user "pi" doesn't exist. And root is only temporary.
So my question is where did I go wrong? Even if I still have the "pi" user active, I can't connect to the FTP using FileZilla.
Exit is to log out of the Pi, you can type anything you want as a password - just make sure to remember it :D
Now close the SSH session, and start a new one - this time logging in as the root user, with the password you just set.
Now type "nano /etc/passwd" then hold the CTRL key and press W.
Type "pi" and hit return. It should show you 2 entries.
One of those entries must be commented out to work.
Save the file, then type "usermod -d /var/www pi" then Return/Enter.
then "passwd pi" and set a password.
Finally try connecting via FTP again.
Hope this helps, if not - ask again and I'll try and help :D
Daniel.
But now I have another problem, I get the following error when creating a new folder or file:
No space left on device
Now I get what is causing this, my partition doesn't have enough space:
Filesystem Size Used Avail Use% Mounted on
rootfs 1.8G 1.7G 0 100% /
/dev/root 1.8G 1.7G 0 100% /
tmpfs 19M 212K 19M 2% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 37M 0 37M 0% /tmp
tmpfs 10M 0 10M 0% /dev
tmpfs 37M 0 37M 0% /run/shm
/dev/mmcblk0p1 56M 34M 23M 61% /boot
Above is my usage, and it shows I've used all the 100% of the rootfs and /dev/root, but I don't know what this is.
I'm trying to add folders to my /var/www/ folder, is that also in there?
And I'm using a 16Gb SD card, so how can it be full already with these sizes. Does it have to do something with the formatting of the SD?
I formatted it on Windows with FAT32, don't know what cluster size, maybe I have to change that?
I hope you can clear this up for me.
Thanks in advance.
The issue is easily solved by the following instructable:
http://www.instructables.com/id/Raspberry-Pi-Resize-Partitons-Use-all-free-space/
It's because the image is set to, I believe, 1 or 2 GB. The above instructable will walk you through the process to resolve this.
Hope this helps, Daniel.
I only have a problem with transfering phpMyAdmin files over ftp. There is no problem with connecting to Raspberry Pi, but I cannot copy any files on it. It writes that operation failed. I think that it is problem with permissions, but I am not sure and I can`t solve this problem.
Does anybody know what should I do?
Thanks for help!
Thanks
What exactly are you trying to do - copy the PHPMyAdmin files from where to where? I'd be happy to help.
Daniel.
Thanks again,
Paul-Adrien
What is the error you are getting with filezilla?
Daniel.
Already running at: http://langeder.no-ip.org/cms/index.php?p=raspberry-pi-server
Might save some time or at least typing.
sudo tasksel install lampserver
sudo apt-get install phpmyadmin
In my experience, if you set the port forwarding to the Raspberry Pi, and install a firewall on the Raspberry Pi with correct rules, then the network should be safe.
Also a firewall and antivirus is usually a good idea for all of the computers on the network anyway.
As far as firewalls go, I'd say that UFW is a pretty easy one to understand, or there's iptables which is a lot harder to understand, but gives you much more flexibility and control.
To conclude, with a firewall installed, your netowkr should be perfectly safe. (as well as choosing strong passwords for stuff like SSH, FTP, etc)
Hope this helps, Daniel.
but where can i change the Http file it loads?
After step 9 - Install an FTP server, you will be able to connect to your Raspberry Pi via FTP.
You can use a client such as Filezilla (freeware) to do this.
The details will be:
Hostname: hostname you set
Username: pi
Password: password you set.
Once you've connected via FTP you'll be able to view, update and delete files on the server.
Assuming you've covered all of step 9, the directory you connect to should be /var/www and you'll see an index.html file.
Change these to what you want and it'll work fine.
Hope this helps, Daniel.
Restarting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName .
My dhcp-hostname is 'goddyserver'
Any advices ?
This isn't an issue - it won't stop it working. It's due to it looking for a name it cannot find.
There's no need to worry about this, as your Apache 2 installation should still work okay.
Hope this helps, Daniel.
i have been running a raspberry pi server for a week or so, very stable, although its ethernet.
i tried setting up wireless but it was't reliable enough for a server
for real world pi speed test follow the link below, its served in the UK on a standard adsl line.
mmmmm pi ! :-)
http://adream.homeunix.com/
Thanks
I used a laser cutter to make the case - I'll put the CAD files up soon.
The case actually has a fan that can easily be slotted on top in case you want to overclock it.
Thanks. I'll be picking up a Pi when I get a chance.