Tag Archives: raspberrypi server

How to Install PHP-APC On Your Raspberry PI to speed up your Apache Server


How to Install PHP-APC on your RPi to speed up your Apache Server

A Tutorial by D.M. Wiig

In a previous tutorial I discuss how to install a LAMP stack on your RPi and set it up as a web server. I have been hosting this WordPress site on my RPi now for serveral months. It has been running quietly and with low power drain 24/7 with virtually no down time. I have a fair amount of content on the site and it has been averaging around 50 or more visits per day since I got it up and running.

While the RPi is not going to have the speed of a professional grade server it does a credible job in applications where the load is reasonable and spread out evenly over the day. There are numerous tips and tricks to fine tune the Apache server that runs in the LAMP stack. One of the most effective and quickest tuneups is to install the program PHP-APC which is an alternative caching program for PHP files. WordPress serves up its content dynamically using PHP so having an efficient caching system for PHP will speed up serving content.

To install PHP-APC on an RPi running the Debian Wheezy Raspian OS open a terminal screen and issue the following command from the command prompt:

pi@raspberrypi / $ sudo apt-get install php-apc
The application will download and install. When the install is complete locate the file “20-apc.ini” The file should be installed in the /etc/php5/conf.d directory. Open the file in the nano editor with the commands:

 

pi@raspberrypi / $ cd /etc/php5/conf.d
pi@raspberrypi /etc/php5/conf.d $ sudo nano 20-apc.ini
The file will open in the editor and should see the following lines:
———————————————————————-
GNU nano 2.2.6 File: 20-apc.ini

extension=apc.so
apc.enabled=1
apc.shm_size=12M
apachectl restart
———————————————————————-

Change the setting apc.sh_size=12M to a larger size such as 20M or so to start. Depending on your needs the size of the cache can be expanded as needed. Press Ctrl-o to save the file and Ctrl-x to exit back to the command prompt. Restart the server with the command:

pi@raspberrypi / $ sudo  apachectl restart

Your Apache server should now be up and running with a larger and faster cache. I do not have any benchmarks to cite, but my WordPress application seems to respond noticeably faster with the apc cache installed. There are many other methods to fine tune your RPi as a web server including installing several alternatives to the Apache server. These are the subject of future tutorials.

 

How To: Install a fast efficient web server on your Raspberry Pi


How To: Install a fast efficient web server on your Raspberry Pi

A tutorial by D.M. Wiig

In a previous tutorial I discussed setting up your RPi as a web server using a standard LAMP stack configuration. I have been using my RPi with this installation self-hosting a WordPress web site and have had very good success. For situations where a heavy load or memory intensive applications are anticipated the standard LAMP stack may not be sufficient. The Apache server and MySql database used in the configuration work well but the RPi is memory limited and may not effectively handle heavy loads.

In these kinds of environments it may be worthwhile to set up your RPi with faster and more memory efficient software. The nginx server (pronounced ‘engine x’) is designed to be fast and memory efficient and is an easy installation on an RPi running a Debian Wheezy Raspian OS. The first part of this turorial will guide you throught the basic setup and initial configuration of nginx on your RPi.

To get started it is a good idea to make sure that all of your installed software is running the most current versions. Open a terminal program and issue the command:

$ sudo apt-get update

When the update is completed issue the following command to install the nginx server:

$ sudo apt-get install nginx

This command will download and install the nginx server and all dependencies needed for the server to run. By default the server is installed in the directory /etc/nginx, so issue the following commands to get to the directory:

$ cd /etc/nginx
$ dir

You should see the output shown below:

pi@raspberrypi /etc/nginx $ dir
conf.d koi-utf mime.types naxsi.rules proxy_params sites-available uwsgi_params
fastcgi_params koi-win naxsi_core.rules nginx.conf scgi_params sites-enabled win-utf
pi@raspberrypi /etc/nginx $

We have several options at this point, but we will stay with the default configuration found in the ‘sites-enables’directory. Issue the commands:

$ cd sites-enabled
$ dir

You should see the following:

pi@raspberrypi /etc/nginx $ cd sites-enabled
pi@raspberrypi /etc/nginx/sites-enabled $ dir
default
pi@raspberrypi /etc/nginx/sites-enabled $

We will make a couple of changes to the default configuration file using the nano editor. Make sure you give yourself ‘super user’ privileges by using:

$ sudo nano default

You will see the entire configuation file in the editor but we are only interested for now in the following section:

##

server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6

root /usr/share/nginx/www;
index index.html index.htm;

# Make site accessible from http://localhost/
server_name localhost;

Uncomment the ‘listen 80’ line if it is commented (with a #) out. Do the same for the ‘server_name’ line if it is commented out.
Exit the editor by using Ctrl-O to write the file, and then Ctrl-X to exit the file. We can create a test file to test the server by editing the default index page. To access the page issue the command:

$ cd /usr/share/nginx/www
$ dir

You will see:

pi@raspberrypi /etc/nginx/sites-enabled $ cd /usr/share/nginx/www
pi@raspberrypi /usr/share/nginx/www $ dir
50x.html index.html

To edit the index.html file invoke the editor with:

$ sudo nano index.html

You should see:

GNU nano 2.2.6 File: index.html

<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor=”white” text=”black”>
<center><h1>Welcome to nginx!</h1></center>

</body>
</html>

[ Read 9 lines ]
^G Get Help ^O WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos
^X Exit ^J Justify ^W Where Is ^V Next Page ^U UnCut Text ^T To Spell
Let’s modify the file by inserting the line ‘This is some basic HTML markup to serve!’. After the </head> tag insert the following line:

<br><center><h2>This is some basic HTML to serve!</h2></center>

Your file should look like this:

GNU nano 2.2.6 File: index.html

<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor=”white” text=”black”>
<center><h1>Welcome to nginx!</h1></center>
<br><center><h2>This is some basic HTML to serve!</h2></center>
</body>
</html>

[ Read 9 lines ]
^G Get Help ^O WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos
^X Exit

Exit the editor with the Ctrl-O, Ctrl-X commands.

At this point we can start the server service and check to make sure that nginx is up and running properly. Start the server with:

pi@raspberrypi /usr/share/nginx/www $ sudo service nginx start
Starting nginx: nginx.

To check the server open a web browser and enter the URL http://localhost. You should see index page message displayed. If you have access to another computer on the same network as your RPi you can check the server by entering the local URL in the browser. You should see the default index page greeting. At this point your RPi can serve basic HTML markup to any server on the local network. In the next tutorial I will discuss how to set up and configure PHP and MySql for use with your nginx server setup.

 

Book Review: Raspberry Pi Super Cluster


 

Book Review: Piotr J. Kula. Raspberry Pi Server Essentials. Birmingham, UK: Packt Publishing, 2014.

 A book review by D.M. Wiig

Raspberry Pi Server Essentials is an informative, step by step discussion of how this amazing little computer can be set up as a fully functioning web server. The book begins with a discussion of the basics of setting up a Raspberry Pi and walks the reader through the process of obtaining necessary hardware, installation of the Raspian operating system and initial system configuration. There is also a brief discussion of the design of the Raspberry Pi for readers who are more technically inclined.

I might point out that if the reader is not comfortable working at the command line level and performing system operations such as disk formatting and writing or directory tasks that this section may be a little daunting. Less technically inclined readers may want to purchase an SD card that is preloaded with the Raspberry Pi operating system software. These cards are available from a number of sources at a reasonable price and provide plug-and-play convenience.

After discussing the Raspberry Pi hardware setup the author moves to a consideration of network configuration from Local Area Networks to wireless and Ethernet connections. Once again there is a concise presentation of some of the basics for readers who have some experience working with routers and home networks. After a discussion of performing Raspberry Pi system updates and some basic system monitoring functions the author turns to the task of installing a web server on the Raspberry Pi.

There are several good open source web servers available for Linux operating systems such as Apache software, but the author points out that while these servers contain a number of useful features and are very powerful they are also cumbersome when used on a computer with limited RAM and a relatively slow processor such as the Raspberry Pi. The use of a fast PHP based web server called nginx (pronounced ‘engine x’) is one solution to this problem. Nginx is a fast lightweight server that is designed to deliver the maximum content with a minimum load on system resources. The author first walks the reader through a discussion of downloading and installing nginx. There is also a discussion of downloading and setting up a lightweight SQL database server called SQLite3 to run on the server.

The remaining chapters of the book discuss how to set up and use a number of useful applications on your now functioning Raspberry Pi web server. These applications include setting up and managing a file server, using the Raspberry Pi as a game server for popular open source games such as OpenTTD, using the official HD camera module designed by the Raspberry Pi Foundation for streaming live HD video, and setting up the Raspberry Pi to control a home media center.

There is also an interesting discussion of setting up software on the Raspberry Pi for use with the Bitcoin cryptocurrency implementation. Readers are walked through the installation of Bitcoin software bitcoind on the Raspberry Pi and the use of Bitcoin wallets and Bitcoin web addresses. The chapter concludes with a brief section on Bitcoin mining with CGMiner software.

Raspberry Pi Server Essentials is a concise yet informative look at how the Raspberry Pi can be used in a variety of web server applications. Some technical knowledge of basic hardware and command level interaction with the operating system software is helpful in reading this book but not essential. For those readers who desire more information the author provides a number of links to additional resources pertaining to the material covered in each chapter. The world of open source technology is an amazing one. This book is a good read for those who want to venture into managing their own open source based web server.

————————————————————-