Constructing typecho notes using raspberry pi (I) nginx PHP server quick start

Source: Internet
Author: User
Tags apc php server nginx server

Preface

Because I have been very interested in linux, I started an experiment with Raspberry Pi and set up a simple php server to run typecho.

However, the process is extraordinary, and almost every step is stuck. in addition, compared with WordPress, typecho has less data, which makes the process of solving the problem a little difficult.

 

The first is the Raspberry Pi system. Although there are many official systems, the startup speed is slow, and the support for peripherals such as mobile hard disks is not good. after all, no one really treats Raspberry Pi as a pure blog such as VPS, but still needs to consider its practicality. So here we recommend RaspNAS to you, it provides good support for various mobile peripherals and has the following advantages:

1. Lightweight. The image size of RaspNAS is less than 2 GB, and the memory occupied after startup is very small.

2. Fast. the startup speed is much faster than its raspbian.

3. the background is based on nginx and php. It not only provides an intuitive web Background for monitoring the running status of raspberry pi, but also reduces the difficulty of configuring webpages, in fact, he has a configured webpage environment. In his original version, offline download is not supported. I directly clone yaaw to/var/www to access it directly.

 

Environment Configuration

To configure the Basic Environment for typecho running, we need the following things: database, nginx server, php environment and some plug-ins. in line with the lightweight principle, we do not use too large mysql, but use lightweight sqlite.

Nginx Configuration

First install nginx

For more information, see <How to setup a web server with Nginx/PHP on Raspberry Pi> In the Ducky Pond blog.

Run

  apt-get  nginx

You can perform a test after the installation is complete.

  service nginx start

You can see the service start prompt and access it with the Raspberry Pi Intranet IP address. If you see the page, nginx is successfully installed.

The default static web site path of nginx is usr/share/nginx/www, which does not conform to the linux convention and is usually var/www.

We can modify this by creating the directory first.

   /var/www

Obviously, it is not enough to have such a directory. We also need to tell nginx that we have stored the webpage in this directory. In this case, we need to change the nginx configuration file.

However, before that, we need to know how the nginx configuration file works.

Let's take a look at the nginx directory structure.

 cd /etc/nginx/  

The result is as follows:

conf.d          koi-  win--utf         naxsi.rules  proxy_params      

Nginx can create multiple virtual hosts to allow one server to load multiple webpages. Each virtual host corresponds to a configuration file.

The two folders marked in red are used to store and enable these configuration files.

In the sites-enabled folder, It is the folder where the configuration file is loaded when nginx is started. The folder stores something similar to a shortcut, they point to the corresponding configuration file (symlink) in the sites-available folder ). that is to say, sites-available is the folder that stores all configuration files. To enable these configuration files, you only need to mark them in sites-enabled.

First, we disable the default configuration file named default to prevent nginx from using/usr/share/nginx/www as the website directory.

    /etc/nginx/sites-enabled/default

Next, create a configuration file in the sites-available Directory. (if you are not familiar with vim or haven't installed vim, you can also use nano or other alternatives, or refer to my previous blog post and use the sftp plug-in of sublime text to edit the configuration file)

  vim /etc/nginx/sites-available/mysite

Write the following configuration

/var/

The significance of this configuration file is to create a new server to listen to requests on port 80. The root directory of this server is/var/www, And the indexfile name is index.html#index.htm. If you want more detailed configuration, you can access this page and provide the complete nginx configuration document.

Save and exit, and then enable this configuration file.

 cd /etc/nginx/sites-   -s ../sites-available/  service nginx start

In this way, we can add html for testing to/var/www to view the effect.

Configure the PHP Environment

Nginx is only used as a reverse proxy and static Web Page Server. Dynamic Web Pages like PHP cannot be executed, so we also need the PHP server to process the code in the PHP Web page, return the result to nginx and return it to the visitor. there are several communication technologies between Web server and php server, in addition to Apache, FastCGI, here, we choose to use FastCGI for communication program PHP-FPM, and a PHP plug-in apc to optimize PHP performance. (In fact, to make typecho work properly, we still need to install the PHP and sqlite communication program. To make this article more organized, this part will be described in the Database Configuration section .)

First install

  apt-get  php5-fpm php-apc

If you need to install sqlite to configure typecho, You can execute

  apt-get  php5-fpm php5-sqlite sqllite

After the installation is complete, fpm should start to run automatically. However, to make the apc plug-in operational, we need to restart it.

  service php5-fpm restart

Then we are changing the original nginx configuration file to let nginx know where to process the PHP request. open the configured/etc/nginx/sites-available/mysite file and add the sample code for PHP processing.

/var/~/var/run/php5-

Such a simple PHP server has been configured. We can create a simple PHP file to test the server.

Create a new php file in the/var/www/directory, such as myweb. php.

Write the following content

<??>

Restart the nginx service to load the configuration file.

 service nginx restart

Test the web page 192.168.1.00/myweb. in php, 192.168.1.100 is the Intranet IP address of your Raspberry Pi. If you can see the page, the configuration is complete. however, it should be noted that because typecho involves rewrite, pathinfo must be supported, so its configuration file cannot be written as the simplest

location ~ .*\.php$

Instead, it needs to be changed

location ~ .*\.php(\/.*)*$

This completes the nginx environment configuration for typecho installation.

Related Article

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.