In this tutorial we will learn how to use Raspberry Pi 4 as a web server. In addition to that we will also see how to make web pages in HTML & style with CSS. So let’s get started.
Changing The TCP Port On The Apache Web Server. If you wish to give the rest of the world access to your Pi and you haven't any spare external IP addresses available, you will probably want to change the port number that the Pi's Apache webserver uses to listen and respond so that you can forward that port on your firewall or router. RASPBERRY PI PROTO-PIC ELINUX.ORG SHEEPWALK ELECTRONICS NOVEL DEVICES ARDUINO NOVEL DEVICES ESP8266. Changing The TCP Port On The Apache Web Server. If you wish to give the rest of the world access to your Pi and you haven't any spare external IP addresses available, you will probably want to change the port number that the Pi's Apache. The next step is to create a configuration file for Apache Web Server. This requires the default ‘pi” user to be added to the “www-data” user group of your Linux (Raspbian) system. To check the user’s groups, execute the command “ id pi ” in terminal. This displays the list of.
Components Required:
- Dual Fan Heat Sink aluminium Armor Case. (Optional)
Installing Apache:
Apache is web server application, it serve HTML files over HTTP.
Raspberry Pi Apache2
First, update the available packages. Open terminal and type command
type this command to install apache2
Installing PHP:
PHP is used for server-side programming which will interact with databases to retrieve information, storing, email sending, runs the logic and provides content to HTML pages to display on the screen.
Install PHP and the PHP module for Apache.
Testing The Web Server:
When you install apache by default it will put web page on web folder. You can access that web page within pi itself by opening your browser and typing http://localhost/ or raspberrypi.local (if your pi host name is raspberrypi). If you want to access that web page on another PC or computer, you can type http://192.168.1.102 (you have to type your pi IP address here). For finding pi IP address you can open terminal and type
If you see this page on your browser it means apache is working.
How to change default web page:
After installing apache and testing web page. You are thinking to change web page to your web page. But you can’t edit it right now. You need to change its ownership to your own username (by default it is pi, if you haven’t changed).
Navigate to this directory
Change ownership to your username
Now you are able to change, edit your web page and refresh the web page to see changes.
Enable SSH:
Raspberry Pi Web Server Apache Download
Go to Menu → Preferences → Raspberry Pi Configuration → Interfaces → enable SSH
WinSCP:
You can edit index html file in raspberry pi itself but if you are testing a lot, I would recommend to download WinSCP. WinSCP (Windows Secure Copy) is an open source SecureFTP client for Windows. It allows secure file transfers between the client’s local computer and the remote server. You can directly edit your html file inside the WinSCP.
Select File Protocol → SFTP
Host name Raspberry pi → IP address
port number → 22
user name → pi
password → raspberry
Download for mac os x 10.9. save & Click on login. Irig hd vs irig pro.
Now you will be able to see raspberry pi files on right side and Your PC’s file on the left side.
Make you own Website:
You can add HTML & CSS page to make your own website with raspberry pi.
HTML:
Title Tags:
The title goes between <title> and </title> tags. Title tag should go within <head> and </head> tags. This title will not be visible on webpage, it will be visible on web browser tab.
Heading Tags:
Heading tags start with h followed by a number that indicates the heading level.
h1 → Highest level
h6 → Least level
Heading tag should go between the <body> and </body> tags.
Paragraph Tags:
You have to write content of your website in between <p> and </p> tag. You can add many paragraphs as well as headings.
Adding Hyperlinks:
Add link by <a> tag. This should be in between <body> and </body> tags.
Adding Image:
for inserting image we use <img> tag. It doesn’t have closing brackets <>. File image you want to include must be in same folder where your index file is.
Adding Buttons:
We want to make button clickable so, inserting button tags between the <a> hyperlink tag.
CSS:
Embedding a Style Sheet:
Before going to CSS file, you need to embed the style sheet in the index.html file so that the HTML knows to reference an external CSS file. To do this add following lines between the <head> and </head> tags
Styling Headings, Paragraph and Links:
Define text size here. We are using rem unit. Rem is the computed value of font-size on the root element, we use one font size as a reference across the page. This means all font size are relative to each other.
Main section formats the main content of your page. We are setting maximum width of the content to 500px.
Hyperlinks are underlined by default. Set text-decoration to none to remove the underline.
Styling Button:
Set display to block ensures the button is displayed as a block element. We are also using padding property to add space around the content. For text color and background color we are using hexadecimal color code. Feel free to change that.
Start Testing Our Own Web Page:
Type pi IP address to any web browser, you will be able to your live website by using raspberry pi.
Video:
If you like this kind of content please subscribe to my YouTube channel for more updates. Till then Keep Learning Keep Making.
March 26, 2016 / Benchmark tests, Dedicated servers, GadgetsRaspberry has been one of the greatest revolutions of modern computing. It sold over 5 million units since 2015. Most of the people use it as a media centre, video games emulator console, music player, advertising outdoors… And now Copahost thought: why not using it as a cheap dedicated server?
First of all, the setup
We used one stock Raspberry Pi 3 B (49€), with 1GB of RAM and a 1.2GHz 64-bit quad-core ARM Cortex-A53 CPU. The storage is one 32GB Adata Class 10 MicroSD card (9€).
This Cortex-A53 is 10 times faster than the original Raspberry 1 CPU. That’s a huge improvement.
We installed Raspbian Jessie on it.
Let’s bring the Raspberry “junior” dedicated server into the data center and power it on
Expand the filesystem with raspi-config
By default, Raspbian will partition the SD card only using a small partition. We must enter raspi-config, in order to expand the filesystem to use all the available space in the SD card.
# raspi-config
And then simply select “Expand Filesystem” and hit enter.
Note: you have to reboot it so that changes take effect.
After the reboot, we can now see the whole space mounted in /
Installing LAMP – Apache MySQL and PHP
We prepared a standard and popular environment, similar to a dedicated server. Installed and configured Apache 2, PHP 5 and MySQL 5.6. Raspberry was set up to run a WordPress website as a test.
First of all, let’s install Apache web server
# sudo apt-get install apache2 -y
Now let’s install PHP5 with Libapache
# sudo apt-get install php5 libapache2-mod-php5 -y
Now we will install MySQL
# sudo apt-get install mysql-server php5-mysql -y
Let’s see it running
Benchmark – Dedicated server vs Raspberry Pi 3 B
We made a stress test in the web server, to check what was its limit. We performed 50 concurrent and sequential connections to it, using curl. The result was amazing. It was pretty stable with up to 35 connections, and still worked fine with 50 simultaneous connections!
We created a script called stress.sh, with this content:
Of course we know Raspberry have a simple CPU, compatible with its price. So we put an old dedicated server together and tested both of them with sysbench for linux.
In Sysbench we got a score of 40.23s in E2180 versus 954.90s in Raspberry Pi 3. The lower, the better. The performance of the Raspberry Pi 3 may be a bit disappointing if compared with a standard dedicated server.
In other words, this CPU is 23 times slower than a standard Pentium Dual Core.
Conclusion: is it possible to run Raspberry Pi as a dedicated server in production?
The Cortex-A5 CPU, present in Raspberry 3, is 10 times faster than Raspberry Pi 2 CPU. Using it to host a simple site with a simple MySQL database works perfectly. You can consider using a Raspberry dedicated server for simple operations. As you populate a MySQL database with many results or install some WordPress plugins, the performance may be suffering a bit.
The pros:
Very low power consumption
Can be used as a small and simple web and database server
External USB Hard disks can be connected to it
Very low price
Nice style
The cons:
Poor CPU performance
Poor IO performance, as it depends on an SD card
Lacks a reboot button (there are some mods for it)
For those who need a cheap but a powerful server, the best option is still a VPS Server.
In the next versions, Raspberry should be more competitive and able to handle more and more crowded websites. Copahost hope the “Junior server” will grow and be a competitive piece of hardware within a few years.