Ubuntu + Nginx + php + swpan-fcgi build php network service

WBOY
Release: 2016-08-08 09:32:49
Original
1094 people have browsed it

The environment of this article is Ubuntu 12. For other systems, you can check it yourself or communicate with me.

1. Install nginx

This step is relatively simple. Just sudo apt-get install nginx and you can install it. After installation, you need to set the nginx service port. Its default port is 80.

2. Set the nginx service port

The configuration file is in /etc/nginx/nginx.conf. The configuration file refers to sites-enabled/default. It can be configured as follows:

    listen 8081 default_server;
    listen [::]:8081 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;
Copy after login

where 8081 is the port I set, and the original one is 80. The directory corresponding to root is the directory corresponding to the website files, and can be set to a custom directory. index specifies the priority of the homepage.

In addition, configure the port of the php parser (php-cgi):

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #   # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:3344;
    #   # With php5-fpm:
    #   fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
Copy after login

In my configuration file, the service port of php-cgi is set to 3344. Please pay attention when starting spawn-fcgi below.

Then restart nginx,

service nginx restart

3, install spawn-fcgi,

apt-get install spawn-fcgi

4, install php

apt-get install php5 php5-dev php5-cgi

5, start php-cgi, bind port 3344

sudo spawn-fcgi -a 0.0.0.0 -p 3344 -C 10 -u root -f /usr/bin/php-cgi

I forgot to add sudo before, It keeps getting errors when starting up, which is weird.

6. Test the php environment

Add the test.php file in /usr/share/nginx/html/. If the website directory is not this, add test.php in the corresponding directory. The content is as follows:

<?php
phpinfo();
?>
Copy after login

Enter URL: localhost:8081/test.php to see the result.

The above introduces Ubuntu + Nginx + php + swpan-fcgi to build a PHP network service, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template