linux 安装lnmp环境,centos下配置LNMP环境(源码安装)

准备工作,安装依赖库//检查并安装组件

yum -y install gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel pcre pcre-devel libmcrypt libmcrypt-devel cmake

查看linux版本:

97447384_1几点说明:

pcre、openssl、zlib是安装nginx时需要的

cmake是安装MySQL时需要的

二、编译安装nginx1、下载nginx(stable版本)

P指定下载文件目录

wget -P /tmp http://nginx.org/download/nginx-1.8.1.tar.gz

或者默认下载到当前目录下

[root@centos /]# cd /usr/local/src

[root@centos src]# wget http://nginx.org/download/nginx-1.8.1.tar.gz

2、解压nginx

[root@centos src]# tar xf nginx-1.8.1.tar.gz

[root@centos src]# cd nginx-1.8.1

[root@centos nginx-1.8.1]# ./configure --help(查看参数)3、编译nginx

./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_modulemake && make install

//启动nginx

**第一种方式 指定--sbin-path=/usr/sbin/nginx**

nginx //启动

nginx -s stop// 停止

nginx -s reload // 重新加载

**第二种方式 不指定--sbin-path**

cd /usr/local/nginx

./sbin/nginx

重启nginx /usr/local/nginx/sbin/nginx -s reload

**第三种方式**

配置开机启动

首先写一个shell脚本,脚本名称:nginx

vi /etc/rc.d/init.d/nginx

#! /bin/bash

# chkconfig: 35 85 15

# description: Nginx is an HTTP(S) server, HTTP(S) reverse

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="nginx daemon"

NAME=nginx

DAEMON=/usr/local/nginx/sbin/$NAME (这里是nginx安装是 --sbin-path指定的路径)

SCRIPTNAME=/etc/init.d/$NAME

test -x $DAEMON || exit 0

d_start(){

$DAEMON || echo -n " already running"

}

d_stop() {

$DAEMON -s quit || echo -n " not running"

}

d_reload() {

$DAEMON -s reload || echo -n " counld not reload"

}

case "$1" in

start)

echo -n "Starting $DESC:$NAME"

d_start

echo "."

;;

stop)

echo -n "Stopping $DESC:$NAME"

d_stop

echo "."

;;

reload)

echo -n "Reloading $DESC configuration..."

d_reload

echo "reloaded."

;;

restart)

echo -n "Restarting $DESC: $NAME"

d_stop

sleep 2

d_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2

exit 3

;;

esac

exit 0

//将shell脚本放入到 /etc/rc.d/init.d/中,并执行下列命令

chmod +x /etc/rc.d/init.d/nginx (设置可执行权限)

chkconfig --add nginx (添加系统服务)

service nginx start

service nginx stop

service nginx restart

service nginx reload

浏览器访问:http://localhost如能出现nginx页面则表示成功

// 查看nginx进程

ps -ef | grep nginx

// 查看进程个数 去掉首位的

ps -ef | grep nginx | wc -l

// 查看80端口

netstat -anpt4、安装PHP

//php下载

cd /usr/local/src/

//如果下载文件的文件是mirror,直接解压mirror即可

wget http://cn2.php.net/get/php-5.6.13.tar.gz/from/this/mirror

tar zxvf php-5.6.13.tar.gz

cd php-5.6.13

首先查看安装帮助

# ./configure   --help

# ./configure --prefix=/usr/local/php \

--with-curl \

--with-freetype-dir \

--with-gd \

--with-gettext \

--with-iconv-dir \

--with-kerberos \

--with-libdir=lib64 \

--with-libxml-dir \

--with-mysqli \

--with-openssl \

--with-pcre-regex \

--with-pdo-mysql \

--with-pdo-sqlite \

--with-pear \

--with-png-dir \

--with-xmlrpc \

--with-xsl \

--with-zlib \

--enable-fpm \

--enable-bcmath \

--enable-libxml \

--enable-inline-optimization \

--enable-gd-native-ttf \

--enable-mbregex \

--enable-mbstring \

--enable-opcache \

--enable-pcntl \

--enable-shmop \

--enable-soap \

--enable-sockets \

--enable-sysvsem \

--enable-xml \

--enable-zip

97447384_2

如果配置错误,需要安装需要的模块,直接yum一并安装依赖库

# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel

注意:安装php7beta3的时候有几处配置不过去,需要yum一下,现在php-7.0.2已经不用这样了。

# yum -y install curl-devel

# yum -y install libxslt-devel

编译安装

# make &&  make install

97447384_3

配置文件

# cp php.ini-development /usr/local/php/lib/php.ini

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

# cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm

需要注意的是php7中www.conf这个配置文件配置phpfpm的端口号等信息,如果你修改默认的9000端口号需在这里改,再改nginx的配置

启动

#  /etc/init.d/php-fpm

查看phpinfo()

97447384_4

97447384_5

php7和php5性能分析比较

//time /usr/local/php5/bin/php search_by_key.php

$a=array();

for($i=0;$i<600000;$i++){

$a[$i] =$i;

}

foreach($aas$i)

{

array_key_exists($i,$a);

}

?>生成一个 60 万元素的数组,通过查找key 的方式,来确定key是否存在。

PHP 5.4.44 版

[root@localhost www5.4.44]# time /usr/local/php5.4.44/bin/php search_by_key.php

real    0m0.351s

user    0m0.300s

sys     0m0.050s

PHP 5.5.28 版

[root@localhost www]# time /usr/local/php/bin/php search_by_key.php

real    0m0.361s

user    0m0.304s

sys     0m0.057s

PHP 7.0.0 版

[root@localhost www7]# time /usr/local/php7/bin/php search_by_key.php

real    0m0.114s

user    0m0.097s

sys     0m0.017s

很明显php7的性能是php5的3倍!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值