centos下编译安装lnmp

本文以centos为背景在其中编译安装nginx搭建lnmp环境。

编译安装nginx时,需要事先安装 开发包组"Development Tools"和"Server Platform Development",同时还需专门安装pcre-devel包。

安装命令

        yum -y groupinstall "Development Tools"
yum -y groupinstall "Development Tools"
yum -y groupinstall "Server Platform Development"

创建nginx运行的用户和用户组

        groupadd -r nginx
useradd -g nginx -r nginx

创建编译安装时需要的目录( --http-client-body-temp-path=)

        mkdir -pv /var/tmp/nginx/client

下载nginx源码 此处我下载的是nginx-1.4.7

        cd /usr/local/src
wget http://mirrors.sohu.com/nginx/nginx-1.4.7.tar.gz
tar xf nginx-1.4.7.tar.gz
cd nginx-1.4.7
./configure \--prefix=/usr/local/nginx \--sbin-path=/usr/local/nginx/sbin/nginx \--conf-path=/etc/nginx/nginx.conf \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--pid-path=/var/run/nginx/nginx.pid \--lock-path=/var/lock/nginx.lock \--user=nginx \--group=nginx \ --with-http_ssl_module \--with-http_flv_module \--with-http_stub_status_module \--with-http_gzip_static_module \--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 \--http-scgi-temp-path=/var/tmp/nginx/scgi \--with-pcre
make && make install

创建nginx SysVinit脚本

	#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
} start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
sleep 1
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
} force_reload() {
restart
} configtest() {
$nginx -t -c $NGINX_CONF_FILE
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null 2>&1
} case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac

为脚本添加可执行权限

chmod +x /etc/rc.d/init.d/nginx

添加nginx开机自启动

chkconfig --add nginx
chkconfig nginx on

编辑nginx配置文件

vi /etc/nginx/nginx.conf
location ~ \.php$ {
fastcgi_pass 10.170.2.90:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}

在server内添加网站的根目录 /var/www/html

启动nginx

/etc/init.d/nginx start

测试是否启动成功

	curl 127.0.0.1

应该看到 welcome to nginx

此时nginx告一段落

安装php切换到源码目录

	cd /usr/local/src
wget http://am1.php.net/distributions/php-5.6.28.tar.bz2
tar xf php-5.6.28.tar.bz2
cd php-5.6.28
./configure --prefix=/usr/local/php5 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2

如果有错误提示根据相应的提示安装

我这里提示了2个问题

  • xml2-config not found. Please check your libxml2 installation.

    按如下命令安装 yum install libxml2-devel -y

  • mcrypt.h not found. Please reinstall libmcrypt

    按照如下方法解决 源码安装libmcrypt

              cd /usr/local/src
    wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
    tar -zxvf libmcrypt-2.5.7.tar.gz
    cd libmcrypt-2.5.7
    ./configure --prefix=/usr/local
    make
    make install

继续切换到php源码目录

	cd /usr/local/src/php-5.6.28
make
make install

有可能在make过程中出现

make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

看网上文章解释 这是由于机器内存过小造成的 解决办法

在./configure加上选项:--disable-fileinfo

所以完整的命令为

	cd /usr/local/src/php-5.6.28
./configure --prefix=/usr/local/php5 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --disable-fileinfo

拷贝php.ini

cp php.ini-production /etc/php.ini

配置php-fpm

 cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf

编辑 /usr/local/php5/etc/php-fpm.conf

vi /usr/local/php5/etc/php-fpm.conf

修改以下值

	pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php5/var/run/php-fpm.pid

测试是否安装成功 写入php文件

	vi /var/www/html/index.php

输入如下

	<?php
phpinfo();
?>

启动php-fpm

	/etc/init.d/php-fpm start
curl 127.0.0.1

此时应该得到回应

安装mysql

	yum install -y mysql-server mysql mysql-deve

初始化

	service mysqld start

设置root密码

	/usr/bin/mysqladmin -u root password '123456'

重新启动mysql

	service mysqld restart

此时root密码为123456php应该可以连接了

参考 http://os.51cto.com/art/201410/454231.htm

centos下编译安装lnmp的更多相关文章

  1. CentOS下编译安装LNMP环境

    一.卸载系统预安装的LAMP软件 rpm -qa|grep httpd rpm -e httpd httpd-tools rpm -qa|grep mysql rpm -e mysql mysql-l ...

  2. 转:在CentOS下编译安装GCC

    转:https://teddysun.com/432.html 在CentOS下编译安装GCC 技术  秋水逸冰  发布于: 2015-09-02  更新于: 2015-09-02  6519 次围观 ...

  3. CentOS 下编译安装Apache

    CentOS 下编译安装Apache 卸载原有的apache 首先从 http://httpd.apache.or 下载apache源码包httpd-2.4.4.tar.gz然后从 http://ap ...

  4. centos下编译安装mysql5.6

    CentOS 6.4下编译安装MySQL 5.6.14 参考:http://www.cnblogs.com/xiongpq/p/3384681.html 概述: CentOS 6.4下通过yum安装的 ...

  5. CentOS下编译安装MySQL 5.6.21

    一.编译安装MySQL前的准备工作 安装编译源码所需的工具和库 yum install gcc gcc-c++ ncurses-devel perl 安装cmake:http://www.cnblog ...

  6. centos6.7下编译安装lnmp

    很多步骤不说明了,请参照本人的centos6.7下编译安装lamp,这次的架构是nginx+php-fpm一台服务器,mysql一台服务器 (1)首先编译安装nginx: 操作命令: yum -y g ...

  7. CentOS 下编译安装MySQL

    CnetOS 下编译安装 MySql 查看是否存在旧版本: rpm -qa | grep mysql 卸载旧版本: rpm -e mysql   #普通删除模式 rpm -e --nodeps mys ...

  8. CentOS 7 下编译安装lnmp之PHP篇详解

    一.安装环境 宿主机=> win7,虚拟机 centos => 系统版本:centos-release-7-5.1804.el7.centos.x86_64 二.PHP下载 官网 http ...

  9. CentOS 7 下编译安装lnmp之nginx篇详解

    一.安装环境 宿主机=> win7,虚拟机 centos => 系统版本:CentOS Linux release 7.5.1804 (Core),ip地址 192.168.1.168   ...

随机推荐

  1. MySQL收藏

    MySQL手册:5.5手册 .5.6手册 cd /usr/local/mysql/bin mysql -uroot -p show processlist;   // 显示系统中正在运行的所有进程 M ...

  2. Spring配置文件集成Hibernate配置文件

      Spring对hibernate配置文件hibernate.cfg.xml的集成,来取代hibernate.cfg.xml的配置.  spring对hibernate配置文件hibernate.c ...

  3. Linux 双网卡绑定

    Linux 双网卡绑定 Linux 双网卡绑定双网卡绑定的常用模式:mode1:active-backup 模式,即主备模式.mode0:round-broin 模式,即负载均衡模式(需要交换机配置聚 ...

  4. textarea元素只设置高可变,宽固定

    网上查了一下多数只告诉怎么禁止拖动,好在编辑器提示了所有的属性,在此记录一下 textarea{ resize: vertical; } 还有其它的属性

  5. Unity MonoDevelop一打开未响应

    在学习Untiy的时候,使用内置的MonoDevelop开发工具.本来就不好用,经常出现未响应的情况,然后重启解决.终于有一次莫名其妙的崩溃了,在Unity打开该IDE就未响应,但直接打开MonoDe ...

  6. touch命令

    [touch]      改变文件的时间戳 命令格式: touch [OPTION]... FILE... 命令功能: 更新每个文件的访问和修改时间到当前时间或建立一个不存在的文件 命令参数: -a  ...

  7. typeScence

  8. java性能调优及问题追踪--Btrace的使用

    在生产环境中经常遇到格式各样的问题,如OOM或者莫名其妙的进程死掉.一般情况下是通过修改程序,添加打印日志:然后重新发布程序来完成.然而,这不仅麻烦,而且带来很多不可控的因素.有没有一种方式,在不修改 ...

  9. VC++ 设置软件开机自启动的方法

    0  概述 软件开机自启动是比较常用的做法,设置方法也有好几种. 1  使用者模式 在"开始菜单"的所有程序中有个"启动"文件夹,可以将需要设置为开机启动的应用 ...

  10. Best code水题之路

    BestCoder 2nd Anniversary: 1001.Oracle There is once a king and queen, rulers of an unnamed city, wh ...