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

下面是“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文件中:

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

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:CentOS 6.6服务器编译安装lnmp(Nginx1.6.2+MySQL5.6.21+PHP5.6.3) - Python技术站

(0)
上一篇 2023年5月14日
下一篇 2023年5月14日

相关文章

  • [Linux] PHP程序员玩转Linux系列-备份还原MySQL

    1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 3.PHP程序员玩转Linux系列-搭建FTP代码开发环境 前几天有个新闻,说是gitlab的工程师把数据文件给误删了,搞了个大事件,很多人都去围观了.备份工作应该在最开始的时候就要做,否则就会失去最佳时机,为了保证我的数据是安全的,因此我要…

    Linux 2023年4月13日
    00
  • 在Ubuntu上面安装VMware Workstation教程

    关于在Ubuntu系统上安装VMware Workstation的教程攻略,我的建议如下: 1. 准备工作 在开始安装VMware Workstation之前,我们需要确保Ubuntu系统中已经安装好了必要的支持软件。具体包括以下内容: A. 更新软件包 在Ubuntu系统中打开终端,利用以下命令进行软件包更新: sudo apt update sudo a…

    Linux 2023年5月24日
    00
  • 嵌入式Linux开发环境搭建ping、nfs的解决方法

    嵌入式Linux开发环境搭建ping、nfs的解决方法如下: 环境搭建 下载并安装arm-linux-gcc工具链 工具链可以在交叉编译工具的官网上找到。下载完成后,需要将其解压并添加到环境变量中。 下载并编译内核源码 内核源码可以在官网上找到。下载完成后,使用make ARCH=arm CROSS_COMPILE=arm-linux-gcc menucon…

    Linux 2023年5月24日
    00
  • linux上安装Docker(非常简单的安装方法)

    下面是详细讲解在 Linux 上安装 Docker 的完整攻略: 准备工作 在安装 Docker 之前需要确保以下几点: 系统版本:Docker 要求使用 64 位版本的 Ubuntu 16.04 或更高版本、Debian 9 或更高版本、CentOS 7 或更高版本等系统。 内核版本:Docker 要求使用 3.10 或更高版本的内核。 安装 curl:使…

    Linux 2023年5月14日
    00
  • Linux下执行shell脚本出现-bash: ./stop.sh: /bin/bash^M: bad interpreter: No such file or directory问题

    问题描述:我在Windows下将shell脚本编写好上传至Linux服务器,chmod之后执行脚本出现如下问题 出现原因:Windows下编辑的shell脚本文件格式是dos,而Linux下需要unix格式的,可用vim编辑器查看文件格式按【ESC键>>按shift+冒号>>输入set  ff>>回车】 解决方案:将dos…

    Linux 2023年4月11日
    00
  • Linux C – UDP数据收发

      基于UDP的通信时不可靠地,面向无连接的,发送的数据无法确切知道对方收到没有,通常用于对可靠性要求不高的通信中,使用简单,UDP没有严格区分server端和client端,唯一的区别是绑不绑定(bind)端口。 1,接收程序(server) #include <sys/types.h> #include <sys/socket.h&gt…

    Linux 2023年4月13日
    00
  • CentOS 6.5上编译安装Apache服务器的方法(最小化安装)

    以下是“CentOS6.5上编译安装Apache服务器的方法(最小化安装)”的完整使用攻略,包含两个示例说明。 CentOS6.5上编译安装Apache服务器的方法(最小化安装) 以下是在CentOS6.5上编译安装Apache服务器的步骤: 1. 安装编译工具和依赖库 在编译安装Apache服务器之前,需要安装一些编译工具和依赖库。可以使用以下命令在Cen…

    Linux 2023年5月13日
    00
  • Linux 内存管理 pt.2

    哈喽大家好我是咸鱼,在《Linux 内存管理 pt.1》中我们学习了什么是物理内存、虚拟内存,了解了内存映射、缺页异常等内容 那么今天我们来接着学习 Linux 内存管理中的多级页表和大页 多级页表&大页 在《Linux 内存管理 pt.1》中我们知道了内核为每个进程都维护了一张页表,这张页表用来记录进程虚拟内存与物理内存的映射关系 页表实际上存储在…

    Linux 2023年5月5日
    00
合作推广
合作推广
分享本页
返回顶部