How to Create a Web Server on Raspberry Pi

Table of contents:

How to Create a Web Server on Raspberry Pi
How to Create a Web Server on Raspberry Pi
Anonim

If you are looking for a way to create a functional and affordable web server that you can use as a test environment or as a place to store your files, then the little Raspberry Pi is the ideal solution. Are you wondering what a Raspberry Pi is? This is a very inexpensive mini computer, perfect for performing all the basic functions required of a server. This article explains how to turn a Raspberry Pi into a web server. A Windows computer was used to perform all the procedures described in this guide.

Steps

Part 1 of 7: Boot into the Raspberry Pi Operating System

2254547 1
2254547 1

Step 1. Get a copy of the Raspberry Pi OS from the link in the "References" section of the article

There are several distributions of this operating system available, but the "Raspbian" version was used for this guide.

2254547 2
2254547 2

Step 2. Extract the operating system image to an SD card

To perform this step, you will need to use a program called "Win32 Disc Imager". You can download it using the appropriate link in the "References" section of the article. Launch the program, access the SD card using the corresponding drive letter, select the Raspberry Pi OS operating system image, then click the "Write" button. Wait for the data transfer process to complete.

2254547 3
2254547 3

Step 3. Access the SD card using the Windows "File Explorer" system window

Create a new file which you will name ssh. This is a security feature introduced after the release of the "Raspbian Jessie" version of the operating system.

2254547 4
2254547 4

Step 4. Eject the SD card from the computer and insert it into the Raspberry Pi slot, then wire all the cables necessary for the mini computer to operate

Make sure you connect the power USB cable last.

2254547 5
2254547 5

Step 5. When the operating system has booted successfully, log into the mini computer

The default username is "pi" and the default password is "raspberry". New versions of the Raspbian operating system, by default, use an automatic login feature.

2254547 6
2254547 6

Step 6. The first step is to change the login password

Run the following command from the command line:

    sudo passwd pi.

Step 7. You can also change the password by running the "sudo raspi-config" command, choosing the "Change User Password" option or using the "System Configuration" dialog

2254547 7
2254547 7

Step 8. Enter the new security password twice to confirm it is correct

Remember that, for security reasons, the text cursor will not move when you enter passwords, but what you type will still be entered into your computer.

Part 2 of 7: Run the Software Update

2254547 8
2254547 8

Step 1. Start by installing all available updates

Since you are using a new version of Debian, you will need to perform some maintenance and software updates. The first step is to set the system clock, update the package sources and install any package updates already present. Follow these instructions by pressing the "Enter" key after entering each command indicated:

    sudo dpkg-reconfigure tzdata sudo apt-get update sudo apt-get upgrade

2254547 9
2254547 9

Step 2. Set the correct date and time

Type the following command from the command line to change the date and time according to your need:

    sudo date --set = "30 December 2013 10:00:00"

Part 3 of 7: Update the Firmware

2254547 10
2254547 10

Step 1. Install the Hexxeh "RPI Update" program to ensure that the Raspberry Pi firmware is always up to date

Follow these instructions by pressing the "Enter" key after entering each command indicated:

    sudo apt-get install ca-certificates sudo apt-get install git-core sudo wget https://raw.github.com/Hexxeh/rpi-update/master/rpi-update -O / usr / bin / rpi-update && sudo chmod + x / usr / bin / rpi-update sudo rpi-update sudo shutdown -r now

Part 4 of 7: Configure the SSH Protocol

Hostnamei
Hostnamei

Step 1. Configure the SSH connection protocol so that you can connect to the server from any other computer

First, make a note of the Raspberry Pi's IP address using the following command:

    hostname -I

  • A result similar to this should appear on the screen:
  • 192.168.1.17

  • The number that appears represents the IP address of the Raspberry Pi.
2254547 12
2254547 12

Step 2. Enable the SSH connection protocol and restart the device (again, press the "Enter" key after entering each command):

    After taking note of the mini computer's IP address run this command: sudo /etc/init.d/ssh start You will need to run it every time you turn on the Raspberry Pi. Tip: If you get any error messages, try running the following command before running the one above. sudo apt-get install ssh After executing this last command restart the Raspberry Pi: sudo shutdown -r now

2254547 13
2254547 13

Step 3. Disconnect the USB keyboard and external monitor cables from the Raspberry Pi

These two devices are no longer needed. At this point, you can connect to the server remotely via SSH connection.

2254547 14
2254547 14

Step 4. Download an SSH client like PuTTy (from the official website www.putty.org)

You can download it for free and use it to connect to the Raspberry Pi using its IP address. Log in using the username "pi" and the security password you set earlier.

Part 5 of 7: Install the Web Server

2254547 15
2254547 15

Step 1. Install the Apache server and PHP platform

To complete this step, run these commands:

    sudo apt-get install apache2 php5 libapache2-mod-php5

2254547 16
2254547 16

Step 2. Restart the web server service using one of the following commands:

    sudo service apache2 restart

    or

    sudo /etc/init.d/apache2 restart

2254547 17
2254547 17

Step 3. Enter the IP address of the Raspberry Pi into the address bar of the internet browser

A simple web page should appear that reads "It Works!".

Part 6 of 7: Install MySQL

2254547 18
2254547 18

Step 1. Install MySQL

To complete this step, you need to install some packages by running these commands:

    sudo apt-get install mysql-server mysql-client php5-mysql

Part 7 of 7: Install the FTP Server

2254547 19
2254547 19

Step 1. Install the FTP server to be able to transfer any type of file to the Raspberry Pi, or download from the server

2254547 20
2254547 20

Step 2. Set your account as the owner of the web server home folder by running this command:

    sudo chown -R pi / var / www

2254547 21
2254547 21

Step 3. Install the FTP service (vsftpd) using this command:

    sudo apt-get install vsftpd

2254547 22
2254547 22

Step 4. Access the "vsftpd.conf" file using this command:

    sudo nano /etc/vsftpd.conf

2254547 23
2254547 23

Step 5. Make the following changes:

  • Change the value of the "anonymous_enable" parameter from YES to NO
  • Activate the parameter line local_enable = YES And write_enable = YES deleting the symbol # that you find at the beginning of each line of text.
  • Now move to the end of the file and add the line force_dot_files = YES.
2254547 24
2254547 24

Step 6. Save the file and close it by pressing the "CTRL-O" and "CTRL-X" key combination in succession

2254547 25
2254547 25

Step 7. Restart the vsftpd service using this command:

    sudo service vsftpd restart

2254547 26
2254547 26

Step 8. Create a shortcut to the "/ var / www" folder inside the "home" folder of the Raspberry Pi user account using this command:

    ln -s / var / www / ~ / www

2254547 27
2254547 27

Step 9. At this point, you can transfer the data to the "/ var / www" folder via FTP using the Raspberry Pi's Pi account and the link that appears on the login screen

Advice

  • There is no need to install an FTP server if you have already installed an SSH server. In this case, you can use an application like WinSCP to connect to the Raspberry Pi server via SCP protocol, which is more secure and doesn't force you to open an extra communication port in the system.
  • If an error message similar to "wget: command not found" appears, run the command "sudo apt-get install wget".

Recommended: