Don’t pay for web hosting. Configure your Raspberry Pi to act as a web server and host modest website
What you’ll need
Latest Raspbian image
raspberrypi.org/downloads
Internet connection
External hard drive (optional)
USB flash (optional)
Ethernet cable for reliability
Need a lightweight, low-cost web server? Your RaspberryPi is all you need! Whether you’re planning on hosting a static homepage (or one with minimal database use) or need an easy home for development websites, setting up your Raspberry Pi as awebserverissurprisinglyeasy. Ideal as an always-on device thanks to its low-power requirements, the Raspberry Pi can sit beside your router and serve a basic website to visitors, allowing you to put hosting fees to better use. You might wish to serve pages for some of your Pi projects,orevenapersonalpagetohostphotosoryourCV. If you’re planning on using it as a web-facing device, your Pi will need to be set up with a static IP address. You’ll also need to ensure your internet provider offers static IP addresses for their users.OftenapriceischargedforleasingastaticIP,butthereare servicesyoucanuse(suchasnoip.com).ability
Connect your Ethernet cable
For this project it makes more sense to use an Ethernet
cable. You may need your existing USB ports to attach flash drives or an external HDD to serve your web page. With Ethernet
you will need to rule out any wireless issues that are causing interruptionsforyourvisitors.
Get Raspbian updates and Apache
Asever,begin by checking for Raspbian updates: sudo apt-get update You’ll then need to install Apache and PHP: sudo apt-get install apache2 php5 libapache2-mod-php5 Finally, restart Apache: sudo service apache2 restart
Your RaspberryPi is now ready to
be used as a webserver.
You can upload files to /vav/www
Check your Pi web server
With Apache installed, open the browser on another computer on youra network and enter your Pi’s IP address to view the Apache confirmation page. As things stand right now, all you will be able to view is the Apache index.php page. To add your own HTML and PHP pages, you will need FTP.
Install FTP for uploading files
Create a www folder, then install the following vsftpd FTP server software:
sudo chown -R pi /var/www
sudo apt-get install vsftpd
You’ll need to make some changes to Very Secure FTP Daemon, so open it in nano. First, switch:
anonymous_enable=YES
…to…
anonymous_enable=No
Next, uncomment the following by removing the # symbols:
#local_enable=YES
#write_enable=YES
Restart the FTP Server
Complete configuration of the FTP software by adding a command to the end of the file which will display server files starting with “.” such as .htaccess:
force_dot_files=YES
Save and exit nano (Ctrl+X) and restart FTP:
sudo service vsftpd restart
Using the default Raspbian credentials you can upload files to /var/www.
Make Pi a LAMP server
By adding MySQL into the mix you can use the Pi to host a database-driven website or even WordPress (although this is
bestlimitedtousingthedeviceasadevelopmentserver).
sudo apt-get install mysql-server mysql-client
php5-mysql
TheLAMPbundleisusefulofcourse,butforthebestresultsyour siteshouldremainstreamlined.
Get your site online
Can’t afford a static IP for your router? A great solution is available with the free service from www.noip.com. This enables you to point a hostname at your computer by using a client application that will remain in contact with the No-IP servers.
Install No-IP
Make a new directory and switch it to:
mkdir /home/pi/noip
cd /home/pi/noip
Download No-IP on your Pi with:
wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
Extract:
tar vzxf noip-duc-linux.tar.gz
Next, navigate to the directory and use sudo make and sudo make install, following any instructions. Finish by running: sudo /usr/local/bin/noip2
Change your password for security
Before using your Pi as a live web server, it’s a good idea to change the default password to something more imaginative than ‘raspberry’.
In the command line, enter passwd and then follow the prompts to add your new, secure password. You’re doing this step because you obviously would not want your Pi web server to get hacked!
No comments:
Post a Comment