下面是“CentOS6.6服务器编译安装lnmp(Nginx1.6.2+MySQL5.6.21+PHP5.6.3)”的完整攻略,过程中包含两条示例说明。
执行以下命令来安装编译Nginx和PHP的依赖包:
yum install -y gcc-c++ make zlib-devel openssl-devel pcre pcre-devel libmcrypt-devel libxml2-devel libcurl-devel curl-devel bison bison-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt-devel libxslt libjpeg libpng freetype
wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
rpm -ivh mysql-community-release-el6-5.noarch.rpm
yum install -y mysql-community-server
service mysqld start
chkconfig mysqld on
cd /usr/src
wget http://cn2.php.net/distributions/php-5.6.3.tar.gz
tar zxvf php-5.6.3.tar.gz
cd php-5.6.3
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-config-file-scan-dir=/usr/local/php/etc/php.d \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-mysql \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--with-zlib \
--with-gettext \
--enable-bcmath \
--enable-ftp \
--with-curl \
--with-openssl \
--with-mcrypt \
--enable-opcache \
--enable-sockets \
--with-libxml-dir \
--with-gd
make && make install
cd /usr/src
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_stub_status_module \
--with-pcre \
--with-zlib \
--with-openssl \
--with-http_gzip_static_module \
--user=nginx \
--group=nginx \
--with-http_realip_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_geoip_module \
--with-http_sub_module \
--with-http_addition_module \
--with-http_image_filter_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_xslt_module \
--with-ipv6
make && make install
groupadd nginx
useradd -g nginx nginx
复制以下内容到/usr/local/nginx/conf/nginx.conf
文件中:
user nginx;
worker_processes 4;
worker_rlimit_nofile 10240;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 120;
gzip on;
server {
listen 80;
server_name localhost;
root /usr/local/nginx/html;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
}
}
复制以下内容到/usr/local/php/etc/php.ini
文件中:
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226"
zend_extension = opcache.so
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
date.timezone = Asia/Shanghai
/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm
示例1:创建PHP测试文件
在/usr/local/nginx/html
目录下创建index.php
文件,内容如下:
<?php
phpinfo();
?>
示例2:重启Nginx和PHP
/usr/local/nginx/sbin/nginx -s reload
/usr/local/php/sbin/php-fpm -s reload
本文链接:http://task.lmcjl.com/news/13848.html