Home >Backend Development >PHP Tutorial >Building a PHP+Mysql+Nginx environment on Ubuntu (apt-get method)_PHP tutorial

Building a PHP+Mysql+Nginx environment on Ubuntu (apt-get method)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:08:11753browse

Building a PHP+Mysql+Nginx environment on Ubuntu (apt-get method)

ubuntu version: Ubuntu 10.04 LTS

1. First use apt-get to download Nginx, php tutorial, mysql tutorial, phpmyadmin, spawn-fcgi.

sudo apt-get install nginx php5-cgi php5-cli mysql-server-5.1 phpmyadmin spawn-fcgi

You may have to enter your mysql password during this period, just follow the prompts to install it step by step.

After OK, you should be able to see the Nginx welcome interface when you visit http://127.0.0.1/ or http://localhost/ in Firefox.

2. Nginx cannot run PHP programs at this time. Some configuration files need to be modified.

$ cd /etc/nginx

$ sudo vim fastcgi_params, modify as follows (red part):

fastcgi_ignore_client_abort on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

Modify Nginx configuration file nginx.conf

sudo vim nginx.conf, the final result is as follows:

user codebean codebean; #User and user group
worker_processes 2;

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

events {
worker_connections 1024;
# multi_accept on;
}

http {
Include /etc/nginx/mime.types;

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

sendfile on;
​ #tcp_nopush ​ on;

#keepalive_timeout 0;
Keepalive_timeout 65;
tcp_nodelay on;

gzip on;
gzip_disable "MSIE [1-6].(?!.*SV1)";

include /etc/nginx/conf.d/*.conf;
Include /etc/nginx/sites-enabled/*;
}

3. Next we configure a default site:

cd /etc/nginx/sites-available

sudo vim default

The modification is as follows:

server {
Listen 80 default; #default means the default site
Server_name localhost; #Access name
Root /var/www/nginx-default; #Website root directory

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

location / {
index index.php index.html index.htm;
}

location ~ .php$ {
             include fastcgi_params; #This is very important
}

}

Next, create a new index.php in the directory /var/www/nginx-default and enter:

phpinfo(); Then restart the nginx service and enable fastcgi:

$ sudo /etc/init.d/nginx restart
$ /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 /usr/bin/php-cgi

Visit http://127.0.0.1/ or http://localhost/ to see

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629844.htmlTechArticleBuilding a PHP+Mysql+Nginx environment on Ubuntu (apt-get method) Ubuntu version: Ubuntu 10.04 LTS 1. First use apt -get download Nginx, php tutorial, mysql tutorial, phpmyadmin, spawn-fcgi. sudo apt...
Statement:
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