How to Install A PHP and MySQL Supporting Light Web server On Raspberry Pi

1

Raspberry Pi – How to Install A PHP and MySQL Supporting Light Web server On Raspberry Pi:

The most widely used server is Apache, but in Raspberry Pi there are limited resources and it is recommended to opt for a system that utilizes limited resources.

We have chosen nginx as our web server as there are other alternatives for apache also.

nginx is written by lgor sysoev and as a HTTP and reverse proxy server and also acts as a mail proxy server. It is being a long while that nginx is being running on ample of heavily loaded Russian sites that included Yandex mail, Ru, VK and Rampler.

Initially you will require updating the packages with:

sudo apt-get update

sudo apt-get upgrade

Step 1:

Raspberry Pi – Nginx:

Install nginx

sudo apt-get install nginx

Create the folder

sudo mkdir /var/www

Raspberry Pi – File Configuration should be edited:

sudo nano /etc/nginx/sites-available/default

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

##

server {

#listen   80; ## listen for ipv4; this line is default and implied

#listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

listen 80;

server_name $domain_name;

root /var/www;

index index.html index.htm;

access_log /var/log/nginx/access.log;

error_log /var/log/nginx/error.log;

# Make site accessible from http://localhost/

server_name localhost;

location /

Creating A File:

sudo nano /var/www/index.html

With this content

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML+RDFa 1.1//EN”>

<html>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>

<title>Raspberry Web Server</title>

</head>

<body>

<p><h1 align=”center”>Welcome,<br />… your Raspberry Web Server is ready!! </h1>

<p align=”center”><img alt=”” src=”http://www.emmeshop.eu/blog/sites/files/image/u1/raspberry-pi.png” style=”height:300px; width:250px”></p>

</p>

<p align=”center”><img src=”http://www.emmeshop.eu/blog/themes/bartik/Logo-Emmeshop.png” alt=”Home”></p>

<p align=”center”>Emmeshop Electronics — www.emmeshop.eu </p>

<p align=”center”> </p>

</body>

</html>

Nginx to Be Restarted:

sudo service nginx restart

You browser should be opened with Raspberry Pi address http://192.168.0.166, in case of and then you will be seeing home page of nginx

Step 2:

Raspberry Pi – PHP:

Raspberry Pi – PHP

PHP is especially suited to web development and is a general – purpose scripting language. PHP is fast and flexible and is no nonsense language that powers almost everything from your blog to the most popular websites in the entire world.

nginx uses php-fpm to implement PHP programs.

The subsequent step is to install php-fpm as well as php-apc. To accelerate the performance of PHP, the final is a PHP extension.

sudo apt-get install php5-fpm php-apc

nginx config file is being edited:

sudo nano /etc/nginx/sites-available/default

server {

#listen   80; ## listen for ipv4; this line is default and implied

#listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

listen 80;

server_name $domain_name;

root /var/www;

index index.html index.htm;

access_log /var/log/nginx/access.log;

error_log /var/log/nginx/error.log;

location ~\.php$ {

fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_split_path_info ^(.+\.php)(/.*)$;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param HTTPS off;

try_files $uri =404;

include fastcgi_params;

}

# Make site accessible from  http://localhost/

server_name localhost;

location /

To Test PHP a file is created:

sudo nano /var/www/info.php

with this content

<? php

phpinfo();

?>

The Server to Be Restarted:

sudo service nginx restart

and test in your browser

Step 3:

Raspberry Pi – MySQL:

Raspberry Pi – MySQL

MySQL, php MyAdmin

The most popular open source database is MySQL. MySQL can cost effectively help you in providing high presentation, scalable database application. When you are a fast growing web property, technology ISV or if you are a large enterprise.

Now, we will explain to you to install MySQL as a database server and phpMyAdmin for manipulating database as the management interface.

MySQL, phpMyAdmin, and php5-mysql are to be installed:

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

For root user of MySQL you will be asked to configure the password, during process of MySQL server installation.

Now, you will be asked to opt the web server that is installed in the system (Apache2 or Lighttpd). The web server selection field can be left empty.

At the time of installing phpMyAdmin, it will be asking you to configure database for phpMyAdmin.  You have to answer “yes”. You will have to give the password when you are asked to enter the password of the administrative user.

After that you will have to generate a link:

phpMyAdmin from /usr/share/phpmyadmin to /var/www/phpmyadmin.

sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin

From your browser, after you open phpMyAdmin, by going to http://<raspberrypi-ip-address>/phpmyadmin/index.php and log in as “root” using the administrative password that has been set by you earlier.

Step 4:

Raspberry Pi – How Do We Use Our Web Server?

Web Server is Running

Now, our web server is running on our Raspberry Pi.

How to use this?

It can be used to store the values of some sensors or turn outputs by web interface.

The image that is shown above is the execution of a script that reads the information for PhidgetInterfaceKit.

Share.

About Author

1 Comment

  1. Very nice post. I just stumbled upon your blog and wished to say that I’ve really enjoyed browsing your blog posts. After all I’ll be subinrsbicg to your rss feed and I hope you write again very soon!

Leave A Reply