Raspberry Pi Web server (nginx, Apache)

Source: Internet
Author: User

The first thing we think of about Linux Web servers is:

Apache + MySql + Php.

Apache: is the world's first Web server software to use.

Can run on almost all widely used computer platforms, and is the most popular Web server-side software because of its widespread use across platforms and security.

MySQL: is a relational database management system developed by the Swedish MySQL AB company. is the most popular relational database management system, MySQL is one of the best RDBMS (relational database management System) application software in Web application.

PHP:(Foreign name: Hypertext Preprocessor, Chinese name: "Hypertext Preprocessor") is a common open source scripting language. Grammar absorbs the features of C, Java and Perl, is easy to learn and widely used, and is mainly applicable to web development.


Raspberry Pi can install this lamp series, but Apache and MySQL for Raspberry Pi This small machine, is too heavy, mainly consumes more memory \ Slow disk (about 200M), you can choose to install a lightweight Web server:

Nginx + php + SQLite

Nginx: is a lightweight Web server, is a lightweight Web server/reverse proxy server and e-mail (IMAP/POP3) proxy server, the concurrency capability of Nginx is indeed in the same type of Web server performance better.

SQLite: is a lightweight database, is to adhere to the Acid relational database management system, its design goals are embedded, and has been used in many embedded products, it occupies very low resources, in embedded devices, may only need hundreds of K of memory is enough.

Apache + MySql + Php.

1. Installing Apache

Apache can use the following command to install
sudo apt-get install apache2

Apache Default path is/var/www/

Its configuration file path is:/etc/apache2/

You can modify the listening port number by: sudo vi/etc/apache2/ports.conf

Restart Service effective: sudo service apache2 restart

2. Install MySQL
sudo apt-get install Mysql-server
During the installation, a prompt will appear to let you enter a password.
This password is the password of the MySQL root user.

3. Install PHP
Enter the following command to install PHP 5 and the libraries that PHP needs to access the MySQL database.

sudo apt-get install php5

sudo apt-get install Php5-mysql

4. Testing

Once the installation is complete, you can enter your router's IP or domain name in the browser to access your website.

You should be able to see a page that shows "It works", but no other content.

Create a/var/www/index.php


  1. <?php
  2. Print <<< EOT
  3. <!doctype html>
  4. "en" >
  5. <meta charset="UTF-8" >
  6. <title>test successful</title>
  7. <body>
  8. <p>Congratulations.</p>
  9. <p>your webserver and PHP are working.</p>
  10. </body>
  11. EOT;
  12. ?>



Second, Nginx + php + SQLite

1, install the Nginx Web server (about 6MB)
sudo apt-get install Nginx

2. Start Nginx

Sudo/etc/init.d/nginx start

Nginx www root directory default in/usr/share/nginx/www

3, modify the Nginx configuration file
sudo vi/etc/nginx/sites-available/default

1) Note the following options:

Listen 8080; # # Listen for IPv4; This is default and implied

The port number of the listener, if it conflicts with other software, you can change it here

root/usr/share/nginx/www;

Nginx Default Path HTML location

Index index.html index.htm index.php;

Nginx default look for the type of page, we can add a index.php

2) PHP script support (do not set these PHP scripts are not recognized)

Find the definition section of PHP, remove the comments from these lines, and modify the contents as follows

Location ~. php$ {
Fastcgi_pass Unix:/var/run/php5-fpm.sock;
Fastcgi_index index.php;
Include Fastcgi_params;
}

There are some other definitions in the PHP section, do not move it, for example:
# Fastcgi_split_path_info ...
# Fastcgi_pass 127.0.0.1:9000

4) Install PHP and SQLite (about 3MB)
sudo apt-get install php5-fpm php5-sqlite

5) Reload the Nginx configuration
Sudo/etc/init.d/nginx Reload


6) Test HTML

From the host's IE access to the Raspberry Pi, you can see the home page (indicates that the Web server has started properly)


7) Test PHP

Generate a PHP file in the Raspberry Pi

sudo vi/usr/share/nginx/www/index.php

Enter the following in the file

[PHP]View Plaincopy
  1. <?php
  2. Print <<< EOT
  3. <!doctype html>
  4. "en" >
  5. <meta charset="UTF-8" >
  6. <title>test successful</title>
  7. <body>
  8. <p>Congratulations.</p>
  9. <p>your webserver and PHP are working.</p>
  10. </body>
  11. EOT;
  12. ?>


Save to exit

IE visit this page, that PHP is OK

Raspberry Pi Web server (nginx, Apache)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.