1024programmer Nginx centos6.1 installation configuration nginx and php

centos6.1 installation configuration nginx and php

Deploy nginx, php (including fastcgi), virtual host configuration in CentOS 6.1 environment, friends who need it can refer to the following

Deployment time: 2012-07-24
OS environment: CentOS 6.1
nginx: nginx-1.2.2
PHP: PHP5.3.14
0. Install dependent packages

yum install openssl-devel pcre-devel zlib-devel libjpeg-devel
libpng-devel freetype-devel gcc make

1. Add www user to execute nginx

useradd -M -r -s /sbin/nologin -d /opt/web/www

2. Create a temporary directory mkdir -p /var/tmp/nginx/client/
mkdir -p /var/tmp/nginx/proxy/
mkdir -p /var/tmp/nginx/fcgi/
3. Download the latest stable source code of nginx cd /usr/local/src/
wget http://nginx.org/download/nginx-1.2.2.tar.gz
4. Unzip, compile, and install tar vxzf nginx-1.2.2.tar.gz
cd nginx-1.2.2/
./configure \
–prefix=/opt/web/nginx \
–error-log-path=/var/log/nginx/error.log \
–pid-path=/var/run/nginx/nginx.pid \
–lock-path=/var/lock/nginx.lock \
–user=www \
–group=www \
–with-http_ssl_module \
–with-http_stub_status_module \
–with-http_gzip_static_module \
–http-log-path=/var/log/nginx/access.log \
–http-client-body-temp-path=/var/tmp/nginx/client/ \
–http-proxy-temp-path=/var/tmp/nginx/proxy/ \
–http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi/
make
make install
5. Configure nginx vim /opt/web/nginx/conf/nginx.conf
# Specify the starting user:
user www www;
# The number of processes, the author of nginx thinks that one is enough, modify it according to your own visits
worker_processes 1;
# Set error log:
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log /var/log/nginx/error.default.log;
pid /opt/web/nginx/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
charset utf-8;
include mime.types;
default_type application/octet-stream;
#log_format main ‘$remote_addr – $remote_user [$time_local]
“$request”‘
# ‘$status $body_bytes_sent “$http_referer” ‘
# ‘”$http_user_agent” “$http_x_forwarded_for”‘;
#access_log logs/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml
application/x-Javascript application/xml
application/atom+xml text/Javascript;
server {
listen 80;
server_name localhost;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on
127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#include fastcgi_params;
include fastcgi.conf;
}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
location ~ /\.ht {
deny all;
}
}
# another virtual host using mix of IP-, name-, and port-based
configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
proxy_read_timeout 200;
# Only retry if there was a communication error, not a timeout
# on the Tornado server (to avoid propagating “queries of
death”
# to all frontends)
proxy_next_upstream error;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# import virtual host file
include /opt/web/nginx/conf/sites/*.conf;
}
6. Create a directory for storing virtual machine configuration files

mkdir /opt/web/nginx/conf/sites

After this configuration�If you need to add a new virtual host, just add the configuration file directly in the nginx/conf/sites/ directory
For example: now there is www.server110.com domain name
Create: /opt/web/nginx/conf/sites/www.server110.com.conf file
The content is as follows: server {
listen 80;
client_max_body_size 10M;
#Multiple domain names are separated by spaces, the first one is the default
server_name www.server110.com server110.com;
charset UTF-8;
index index.html index.htm index.php;
# Define the root directory
set $root /var/webroot/www.server110.com/;
# Set the site path
root $root;
# prevent directory browsing
autoindex off;
if ($host != ‘www.server110.com’) {
rewrite ^/(.*)$ http://www.server110.com/$1 permanent;
}
# Prevent .htaccess files from being requested
location ~ /\.ht {
deny all;
}
error_page 404 /404.html;
index index.html index.htm;
location /uploads/ {
alias /data/webroot/www.server110.com/uploads/;
}
try_files $uri @uwsgi;
location @uwsgi{
# Forward other requests to uwsgi
include uwsgi_params;
uwsgi_pass unix:/tmp/360ito_uwsgi.sock;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_pass http://localhost:5000;
}
# Transfer php type requests to fastcgi
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
# Access log:
access_log /var/log/nginx/access.www.server110.com.log;
# Load the .htaccess rewrite file, note that variable paths are not supported here
# Cannot be written as include $root/www.server110.com/.htaccess;
# include /var/webroot/www.server110.com/.htaccess;
# Enable domain name redirection, when access errors occur, other domain names will automatically redirect to www.server110.com
# Note, what I am talking about here is that it will only jump when there is an error in the access, so 301 redirection cannot be realized here!
server_name_in_redirect on;
}
7. Install the latest version of PHP (PHP5.3.14) cd /usr/local/src/
wget http://cn.php.net/get/php-5.3.14.tar.bz2/from/this/mirror
tar xjvf php-5.3.14.tar.bz2
cd php-5.3.14
implement:

./buildconf –force

If an error is reported, it may be that your autoconf is not version 2.13. There are bugs in the PHP5.3. series. You need to install autoconf version 2.13:
CentOS: # yum install autoconf213
Debian: # apt-get install autoconf2.13
Set environment variable # CentOS:
export PHP_AUTOCOnF=”/usr/bin/autoconf-2.13″
# Debian:
export PHP_AUTOCOnF=”/usr/bin/autoconf2.13″
Run again: ./buildconf –force , buildconf: autoconf version 2.13 appears
(ok)
, indicating success.
Compile and install PHP ./configure \
–prefix=/opt/web/php \
–with-config-file-path=/opt/web/php/etc \
–with-config-file-scan-dir=/opt/web/php/etc/conf.d \
–enable-fpm \
–with-fpm-user=www \
–with-fpm-group=www \
–with-mysql=/opt/db/Percona-Server-5.5.14-rel20.5 \
–with-mysqli=/opt/db/Percona-Server-5.5.14-rel20.5/bin/mysql_config
\
–with-iconv-dir \
–with-freetype-dir \
–with-jpeg-dir \
–with-png-dir \
–with-zlib \
–with-libxml-dir \
–enable-xml \
–enable-mbstring \
–with-gd \
–enable-gd-native-ttf \
–with-openssl \
–enable-inline-optimization
make && make install
cp php.ini-production /opt/web/php/etc/php.ini
cd /opt/web/php/etc
cp php-fpm.conf.default php-fpm.conf
Modify php-fpm.conf to enable the following lines, that is, remove the preceding semicolon (;) pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
8. Start php-fpm

/opt/web/php/sbin/php-fpm

start nginx

/opt/web/nginx/sbin/nginx

9. Test it

vim /var/webroot/www.server110.com/tz.php

Type and save <?PHP
phpinfo();
?>
10. Enter in the browser address bar: http://www.server110.com/tz.php
If successful, you can see the information output by phpinfo()

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/centos6-1-installation-configuration-nginx-and-php/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索