LAMP is an acronym that stands for LinuxApacheMySQLPHP and are components required to run a Dynamic HTML webpage.

This instructable will demonstrate how you can turn your Raspberry Pi into a personal web server. The steps to install all of the components are relatively straight forward. After your personal web server is complete, you can use it to host a custom HTML or PHP resume, or a personal landing page which is what I chose to do. 

Step 1: Materials

- Raspberry Pi

- SD memory card (4GB or larger)

- Power adapter compatible with the MicroB connector on the Raspberry pi

- Ethernet patch cable

- HDMI compatible monitor and HDMI cable

- USB Keyboard (no mouse is necessary, you can navigate the entire interface via keyboard. Arrow keys,  Enter, ESC, etc.)
<p>My Pi runs one website but how do I get it to run others? I put similar Apache 2 code in separate files then in the same file and it won't take the other websites like my old WAMP server did running on a WinXP. Will running LAMP instead of Apache 2 fix this? Thanks.</p>
<p>In the &quot;/var/www&quot; folder, simply create another directory.</p><p> ' sudo mkdir /var/www/yoursitename '</p><p>Now, if your your pi's ip address was (example), open</p><p> ' <a href="" rel="nofollow"> </a> ' in your web browser.</p><p>if you get a http 403 forbidden error, run the following in SSH</p><p> ' sudo chown -R pi /var/www/yoursitename ' </p><p>that should now run two sites. No site limit. </p><p>I have two sites set up on my pi.</p><p><a href="" rel="nofollow"> </a> and</p><p>LAMP stands for Linux, Apache, Mysql, PHP</p>
<p>I made it</p>
<p>The default VSFTP mask should be uncommented and 002 or something like it. I spent an hour trying to figure out why my php pages weren't being displayed.</p>
<p>I am a beginner on Raspberry Pi. When I tried to install apache2, its shown that, &quot; Its the newest version. When I tried <a href="http://localhost/" rel="nofollow"> http://localhost/ </a> on raspberry pi browser it works well. But I cannot connect to Rasppi from another PC using the IP address of the Raspbpi.</p><p>Can you please help? Is there anything error?</p>
<p>I am not very experienced, but these are common errors you could check:</p><p>Is the Pi connected to your network?</p><p>Are you using the Ipv4 address? i.e. will be different)</p><p>Did you update/upgrade before you installed Apache?</p><p>Thanks,</p><p>BlueRobot</p>
<p>That's because http://localhost points to the. well local host. So it resolves to whatever machine its accessed on. You'll need to find out the IP of the RPi and put that into your browser, and that should get you one it (of course you need to first have the RPi connected to a network as well as the computer you'll access it from)</p>
<p>Can you SSH into your pi from another pc?</p>
<p>I was wondering, can you add a domain to this, more specifically one from Godaddy? This may be an obvious no, but i don't know anything being 13 xD</p>
Yes but you would have transfer the domain to your home IP address and then portforward.
<p>yes, whoever you get your domain with will come will do,e with some kind of domain name server that will Atleast allow you to do basics. You will need to set your Pi as a static ip on your local network, make sure your public ip is static, and allow a connection to your Pi through your router on external port 80. Ask or Google if you need any assistance. </p>
<p>This probably sounds like a really simple and stupid question but, where do I put a file to upload to the internet?</p>
In the www folder
<p>Can anybody comment on how it holds with a bit of traffic?</p>
<p>For Future Reference. This code allows one to Chroot or &quot;jail&quot; a person to their home directory keeping them from browsing the whole system.<br>----------------------------------------------------------------------------------------------<br>Create Group for sftp users:</p><p>sudo groupadd sftponly</p><p>----------------------------------------------</p><p>Add the following to the end of the /etc/ssh/sshd_config file (sudo nano):</p><p>Subsystem sftp internal-sftp</p><p># This section must be placed at the very end of sshd_config</p><p>Match Group sftponly</p><p> ChrootDirectory %h</p><p> ForceCommand internal-sftp</p><p> AllowTcpForwarding no</p><p>-------------------------------------------------------</p><p>-------------Commands to create a new user-------------</p><p>----------------------(ex john.)-----------------------</p><p>---(replace 'john' with the user you want to create)---</p><p>-------------------------------------------------------</p><p>sudo mkdir /home/john</p><p>sudo useradd -d /home/john -M -N -g users john</p><p>sudo passwd john</p><p>[enter password]</p><p>sudo chown root:root /home/john</p><p>cd /home/john</p><p>sudo mkdir files</p><p>sudo chown john:users /home/john/files</p><p>sudo usermod john -g sftponly</p><p>sudo usermod john -s /bin/false</p><p>sudo service ssh restart</p>
<p>Brilliant. I couldn't figure out why my SFTP connection wasn't working for my custom user, this solved my problem! And helped me lock them into their own directory!</p>
<p>BONUS: To mount a device such as a USB stick to your home directory,<br>sudo mount -t ext4 /dev/sda1 /home/john/files</p><p>This assumes you have an ext4 formatted USB drive.</p><p>You can do this by:<br>sudo mkfs.ext4 /dev/sda1</p><p>Assuming the USB drive you want to format is sda1<br>It will also erase all files off the device<br>Ext4 will allow you to chown the drive to your user instead of root</p><p>(this also is my workaround for the whole kitkat SDcard issue)</p>
<p>I'm using this tutorial to set up a server for my senior design project. I got all of the apache installs done and functioning. I can pull up the ip on my computer which i am using to share my wifi connection with the pi. When I attempt to pull up the same page on my phone, it times out.</p><p>Is there something I am missing? Do i need to set a static ip?</p><p>both my phone and computer are logged into the same wifi network at school</p>
<p>To upload an html file, you will need to use an ftp client. I like to use the FileZilla client on my Windows machine. You will then be able to use your pi credentials (not root) to login by ftp. Note that when you connect by ftp you will land on your home directory (/home/pi). To get the files that you transferred via tp published to your web server, you need to ssh into your raspi and then move or copy them over to your webserver root which is /var/www</p>
<p>Great Tutorial, thank you! :-)</p>I've installed Wordpress to manage an online blog using Raspberry PI.<p>You can download WordPress from <a href="http://wordpress.org/" rel="nofollow">wordpress.org</a> using the <code>wget</code> command. Helpfully, a copy of the latest version of WordPress is always available at <a href="https://wordpress.org/latest.tar.gz" rel="nofollow">wordpress.org/latest.tar.gz</a> and <a href="https://wordpress.org/latest.zip" rel="nofollow">wordpress.org/latest.zip</a>, so you can grab the latest version without having to look it up on the website.</p><p>Navigate to <code>/var/www/</code>, and download WordPress to this <br>location. You'll need to empty the folder first (be sure to check you're <br> not deleting files you need before running <code>rm</code>); change the ownership of this folder to the <code>pi</code> user too.</p> <br><pre><code>cd /var/www <br>sudo chown pi: . <br>sudo rm * <br>wget <a href="http://wordpress.org/latest.tar.gz" rel="nofollow"> http://wordpress.org/latest.tar.gz</a></code></pre><p>Now extract the tarball, move the contents of the folder it extracted (<code>wordpress</code>) to the current directory and remove the (now empty) folder and the tarball to tidy up:</p> <br><pre><code>tar xzf latest.tar.gz <br>mv wordpress/* . <br>rm -rf wordpress latest.tar.gz</code></pre><p>To get your WordPress site set up, you need a database. Run the <code>mysql</code> command in the terminal and provide your login credentials (e.g. username <code>root</code>, password <code>password</code>):</p> <br><pre><code>mysql -uroot -ppassword</code></pre><p>Here I have provided my password (the word <code>password</code>) on the command line; there is no space between <code>-p</code> and your password.</p><p>Alternatively you can simply supply an empty <code>-p</code> flag and wait to be asked for a password:</p> <br><pre><code>mysql -uroot -p</code></pre><p>Now you will be prompted to enter the root user password you created earlier.</p><p>Once you're connected to MySQL, you can create the database your WordPress installation will use:</p> <br><pre><code>mysql&gt; create database wordpress;</code></pre><p>Note the semi-colon ending the statement. On success you should see the following message:</p> <br><pre><code>Query OK, 1 row affected (0.00 sec)</code></pre><p>Exit out of the MySQL prompt with <code>Ctrl + D</code>.</p><p>You need to find out your Pi's IP address to access it in the browser, so in a terminal type the command <code>hostname -I</code>.</p><p>Navigate to <code><a href="http://YOUR-IP-ADDRESS" rel="nofollow">http://YOUR-IP-ADDRESS</a></code> e.g. <code><a href="" rel="nofollow"></a></code> in the web browser on your Pi.</p><p>You should see a WordPress error page; this is good! Click the big button marked <code>Create a Configuration File</code> followed by the <code>Let's go!</code> button on the next page.</p><p>Now fill out the basic site information as follows:</p> <br><pre><code>Database Name: wordpress <br>User Name: root <br>Password: &lt;YOUR PASSWORD&gt; <br>Database Host: localhost <br>Table Prefix: wp_</code></pre><p>Upon successful database connection, you will be given the contents of your <code>wp-config.php</code> file:</p><p><img alt="" src="http://www.raspberrypi.org/learning/web-server-wordpress/images/wp-config.png"></p><p>Copy this text, return to the terminal on the Pi and edit the file with <code>nano wp-config.php</code>. Paste the text into this file, and save and exit with <code>Ctrl + X</code>, then <code>Y</code> for yes and <code>Enter</code>.</p><p>Now hit the <code>Run the install</code> button.</p><h3>Welcome screen</h3><p>Now you're getting close.</p><p><img alt="" src="http://www.raspberrypi.org/learning/web-server-wordpress/images/wp-info.png"></p><p>Fill out the information: give your site a title, create a username <br>and password, put in your email address and untick the search engines <br>box. Hit the <code>Install WordPress</code> button, then log in using the account you just created.</p><p>Now you're logged in and have your site set up, you can see the <br>website by visiting your IP address in the browser on the Pi or another <br>computer on the network. To log in again (or on another computer), go to <br> <code><a href="http://YOUR-IP-ADDRESS/wp-admin" rel="nofollow">http://YOUR-IP-ADDRESS/wp-admin</a></code>.</p><p>WordPress is very customisable. By clicking your site name in the <br>WordPress banner along the top of the page (when logged in), you'll be <br>taken to the Dashboard. From here you can change the theme, add pages <br>and posts, edit the menu, add plugins and lots more. This is just a <br>taster for getting something interesting set up on the Raspberry Pi's <br>web server.</p><p>From: http://www.raspberrypi.org/learning/web-server-wordpress/worksheet.md</p><br>
<p>Hi I've completed all of the steps and everything has worked out perfectly. If there is any way I can get more information on how to upload a HTML document to the server that would be great! </p>
<p>Nice! but its been one year since you made this but still no html.</p>
<p>Hi Mark,</p><p>I've had my Raspberry for a year or so but never got around to using it! Just trying your tutorial and run across a problem, I wonder if you (or anyone else!) can help!</p><p>I've downloaded the SD card image, it's &quot;2014-12-24-wheezy-raspbian&quot; and takes up 3.05Gb on my computer. But when I write it to the SD Card (with Disk Imager), it only takes up 55Mb of space - in fact the SD card's total size shows as 79Mb or something silly like that (it should be 4Gb).</p><p>Putting the SD into the Raspberry and booting gives a few lines of text which pass too quickly to read, then a four-colour screen pops up for a second or so. This repeats until I switch it off. </p><p>What have I done wrong? Any help greatly appreciated!</p><p>Abdullah Eyles,</p><p>Ankara, Turkey</p>
<p>OK - Found the answer, sharing for anyone interested:</p><p>&quot;Under Windows, all you will be able to see is the /boot partition, which is in the MS-DOS VFAT format. Raspbian uses a different file system format for its system files.&quot;</p><p><a href="http://raspberrypi.stackexchange.com/questions/4321/how-to-prevent-sd-card-capacity-loss" rel="nofollow">http://raspberrypi.stackexchange.com/questions/432...</a></p>
<p>Me again: I've discovered the REAL reason for repeated re-booting, the cable between my USB power supply and the Raspberry was too thin - I learned that from the <a href="http://www.raspberrypi.org/forums/viewforum.php?f=28" rel="nofollow">Raspberry Troubleshooting forum</a>.</p><p>In short, some micro-USB data cables use thin wires which aren't thick enough to transmit the power the Pi requires; it starts up then the voltage is not enough so it switches off and tries again, ad infinitum. Using a dedicated micro-USB power supply solved this (as most mobile phone chargers are these days).</p><p>So far I've got to the stage of installing SQL - thanks again Mark!</p>
<p>Great tutorial! thank you</p>
<p>This is great thanks. How can I now create a database and set up WordPress? Thanks, Shane</p>
<p>Excellent tutorial, thank you.</p>
<p>Really inspiring and interesting article! I used it for researching different possibilities before i made my own webserver using the Raspberry Pi, Model B. </p><p>Check out the site the Raspberry is hosting at the moment -<a href="http://www.kimnyegaardandreasen.dk/" rel="nofollow">http://www.kimnyegaardandrease</a>n.dk </p>
<p>Thanks for the great tutorial! Got me setup quickly and correctly!</p>
<p>hi great tutorial! I am wondering how do you get to the part in step seven where you changes things from yes to no? I've already gotten to the black window with the options at the bottom</p>
<p>HI, thank you so much for this tutorial. Could you add the adding the html resume part soon. I am only 13 and just got the server working right and I have a html page i coded i want to put on there. (my eventual goal is to have my raspberry pi gpio's controlled online with a live video stream. i am good with the video stream but need to add the html.)</p>
<p>i just got it all figured out! i am going to use no-ip.com to get a subdomain for free because i have a dynamic ip and need a dns</p>
<p>Glad to hear you figured out your own issue! Only 13? Good on you starting young! I wish I was that ambitious when I was that age haha.</p>
<p>Thanks! </p>
Awesome work! I'm going to build this in the coming weeks.
Thanks man, keep me posted on what you choose to do with it!
Is it possible to use this sever with an address that does not show up as the sever's IP?
If you know your pi's public IP address you can use an Internet domain registrar to forward and mask the IP with a personal domain name. GoDaddy is an obvious example, but I know there are others that are cheaper (I'll look into it and report back). Just a heads up as well, you also may run I to issues if your modem/router does not have a static IP. If it's dynamic, your public IP will change and you won't be forwarding your domain to the right address. I'm pretty sure if you call your ISP you can have them set your modem to a static IP.
<p>Normally a static ip costs more. A possibility is no-ip.com. it is a dns so you install the extra software and every time you ip changes it tells changes the ip in the registrar. Not only that but you get like 3 free sub domains when you sign up. Hope this helps</p>
Well done thanks <br>I wish to host multiple websites all with a different domain name but not the ip address (e.g example@random.com
Is it possible to make a private steam game server out of this or would I need some more or different programs? By the way good work!
I have not personally attempted this, but in checking around, I have seen that this can be done. Thanks for the compliment too, by the way!
i have a question, when i see the black terminal page and it says rasberrypi on the top it looks like a windows 7 page. are you running the commands from another computer into the rasberrypi or the rasberrypi directly? This is for a school project so any help is appreciated.
I'm remotely running the commands from another computer by using SSH. Hop over to step #4, it explains a bit more about the process there. If you still have questions after skimming the instructions, just write back and I'd be more than happy to offer more assistance!
Sorry to bother you again so shortly, but I get a 403 for every file I upload (using FTP) to the raspberry pi, how can I fix the permissions so everything I upload is accessible from the web (octal 644)
Can you explain how to install Node.js on a Pi with the server running like you explained here?
I've never installed it before, but I'd be more than happy to look into it for you. Give me about week and I'll create a full instructable for that :)
hay love the how to do you think you could make a how to on adding HTML :)

About This Instructable


178 favorites


More by GraziCNU: Motion Activated LEDs Sound Reactive LED Strip Turning your Raspberry Pi into a personal web server
Add instructable to: