Setting up a web server



What is a web server?

A web server is just a computer that serves content by using standard internet protocols (HTTP, IP, TCP, ARP). If your device can join a local area network and has a web browser it can be a web server.

To set up the Pi as a web server, you need to install (Linux, Apache, MySQL, PHP).
  1. Open terminal and type the following line to install Apache, PHP and the library that connects them together:
        sudo apt-get install apache2 php5 libapache2-mod-php5
            



  2. After that process completes, you need to restart the Apache service or daemon:
        sudo service apache2 restart
            



  3. The next line will ensure that the default home page was created:
        cat /var/www/index.html
            



  4. Open the LXDE desktop


  5. Open the MIdori browser and navigate to http://localhost


  6. If you see a page that says "It works" everything went well.


  7. Now you must verify the PHP configuration. Navigate to /var/www


  8. Create a new text file named phpinformation.php:
        sudo nano phpinformation.php
            



  9. In nano add the following line:
       <?php phpinfo();?>
            



  10. Press CTRL+X and then Y and Enter to save file and exit nano.


  11. In the LXDE Open Midori and type: http://localhost/phpinformation.php
    You should see the phpinfo() function.


  12. Now you need to install the M in LAMP stack, MySQL.Type:
       sudo apt-get install mysql-server mysql-client php5-mysql
            
    When prompted, set a decent password and write it down somewhere.


  13. From terminal type:
      sudo /etc/init.d/mysql status
            

    You should be able to see a screen that indicates MySQL is installed.





Transfering Files

You can use SFTP to transfer content to the Pi.

Download FileZilla onto your computer as your SFTP client.

  1. Open the application


  2. Click File > Site Manager


  3. In the General tab fill out the relevant connection details:
    • Host:ip of your pi
    • Protocol: select SFTP-SSH File Transfer Protocol
    • Logon Type: set to normal
    • User: specify the user (pi)
    • Password: Specify the current password for the chosen account



  4. Click connect


  5. Navigate to /var/www


  6. Drag and drop any ontent into the target pi directory in FileZilla


  7. Click Disconnect on the toolbar to end the session