Configure nginx + php + mysql server in Ubuntu

Source: Internet
Author: User
Tags fpm install php

1. Install php5

The code is as follows: Copy code

Apt-get install php-pear php5-cli php5-common php5-cgi php5-mysql php5-gd php5-dev

2. Install mysql5

The code is as follows: Copy code
Apt-get install mysql-server mysql-client libipc-sharedcache-perl

3. Install nginx

The code is as follows: Copy code
Apt-get install nginx

Configure nginx as follows

The code is as follows: Copy code
Sudo vi/etc/nginx/sites-available/default

The modification points are as follows:

The code is as follows: Copy code
# In this line, index. php is added as the default file.
Index. php index.html index.htm;

Enable fastcgi to process php scripts

The code is as follows: Copy code

Location ~ . Php $ {
Fastcgi_split_path_info ^ (. +. php) (/. +) $;
# NOTE: You shoshould have "cgi. fix_pathinfo = 0;" in php. ini
# With php5-cgi alone:
Fastcgi_pass 127.0.0.1: 9000;
# With php5-fpm:
# Fastcgi_pass unix:/var/run/php5-fpm.sock;
Fastcgi_index index. php;
Include fastcgi_params;
}

4. Create a fastcgi control script

The code is as follows: Copy code
Sudo vi/etc/init. d/php-cgi

The content is as follows:

The code is as follows: Copy code
#! /Bin/bash
BIND = 127.0.0.1: 9000
USER = www-data
PHP_FCGI_CHILDREN = 15
PHP_FCGI_MAX_REQUESTS = 1000
PHP_CGI =/usr/bin/php-cgi
PHP_CGI_NAME = 'basename $ PHP_CGI'
PHP_CGI_ARGS = "-USER = $ user path =/usr/bin PHP_FCGI_CHILDREN = $ PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS = $ PHP_FCGI_MAX_REQUESTS $ PHP_CGI-B $ BIND"
RETVAL = 0
Start (){
Echo-n "Starting PHP FastCGI :"
Start-stop-daemon-quiet-start-background-chuid "$ USER"-exec/usr/bin/env-$ PHP_CGI_ARGS
RETVAL =$?
Echo "$ PHP_CGI_NAME ."
}
Stop (){
Echo-n "Stopping PHP FastCGI :"
Killall-q-w-u $ USER $ PHP_CGI
RETVAL =$?
Echo "$ PHP_CGI_NAME ."
}
Case "$1 & Prime; in
Start)
Start
;;
Stop)
Stop
;;
Restart)
Stop
Start
;;
*)
Echo "Usage: php-fastcgi {start | stop | restart }"
Exit 1
;;
Esac
Exit $ RETVAL

Add the execution permission to/etc/init. d/php-cgi.

The code is as follows: Copy code
Sudo chmod + x/etc/init. d/php-cgi

Start the php-cgi process

The code is as follows: Copy code
Sudo/etc/init. d/php-cgi start

To enable php-cgi to start with the system, run the following command:

The code is as follows: Copy code

Sudo update-rc.d php-cgi defaults 25

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.