当前位置 : 主页 > 操作系统 > centos >

CentOS 6.6服务器编译安装lnmp(Nginx1.6.2+MySQL5.6.21+PHP5.6.3)

来源:互联网 收集:自由互联 发布时间:2023-07-29
下面是“CentOS6.6服务器编译安装lnmp(Nginx1.6.2+MySQL5.6.21+PHP5.6.3)”的完整攻略,过程中包含两条示例说明。 环境配置 系统: CentOS 6.6 x86_64 MySQL: 5.6.21 PHP: 5.6.3 Nginx: 1.6.2 安装依赖包 执行以下

下面是“CentOS6.6服务器编译安装lnmp(Nginx1.6.2+MySQL5.6.21+PHP5.6.3)”的完整攻略,过程中包含两条示例说明。

环境配置
  • 系统: CentOS 6.6 x86_64
  • MySQL: 5.6.21
  • PHP: 5.6.3
  • Nginx: 1.6.2
安装依赖包

执行以下命令来安装编译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
安装MySQL
  1. 添加MySQL的yum源
wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
rpm -ivh mysql-community-release-el6-5.noarch.rpm
  1. 安装MySQL
yum install -y mysql-community-server
  1. 启动MySQL
service mysqld start
  1. 设置MySQL开机启动
chkconfig mysqld on
安装PHP
  1. 下载并解压PHP源码
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
  1. 配置编译参数
./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
  1. 编译安装PHP
make && make install
安装Nginx
  1. 下载并解压Nginx源码
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
  1. 配置编译参数
./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
  1. 编译安装Nginx
make && make install
配置Nginx和PHP
  1. 创建Nginx的运行用户和用户组
groupadd nginx
useradd -g nginx nginx
  1. 配置Nginx

复制以下内容到/usr/local/nginx/conf/nginx.conf文件中:

自由互联热门推荐:PDF电子发票识别软件,一键识别电子发票并导入到Excel中!10大顶级数据挖掘软件!人工智能的十大作用!

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;
        }
    }
}
  1. 配置PHP

复制以下内容到/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
  1. 启动Nginx和PHP
/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
上一篇:Centos7安装PHP及Nginx的教程详解
下一篇:没有了
网友评论