安装LNMP环境

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

准备安装

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

下载 pcre-8.35.tar.gz到/usr/local/src

[root@centos ~]#wget 

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz

下载jemalloc-3.6.0.tar.bz2到/usr/local/src

[root@centos ~]#  wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
install_jemalloc() {
     echo  - "\n==========jemalloc install==========\n"
 
     cd ${current_dir} / src / base
     tar  - jxvf ${ltnmp_jemalloc}.tar.bz2
     cd ${ltnmp_jemalloc}
     . / configure
     make && make install
 
     echo  "/usr/local/lib"  / etc / ld.so.conf.d / jemalloc.conf
 
     ldconfig
     cd ${current_dir}
}

cetnos下安装以下软件

1
yum  - y install make cmake automake gcc gcc - c + +  gcc - g77 flex bison  file  libtool libtool - libs autoconf kernel - devel patch wget libjpeg libjpeg - devel libpng libpng - devel libpng10 libpng10 - devel gd gd - devel libxml2 libxml2 - devel zlib zlib - devel glib2 glib2 - devel unzip tar bzip2 bzip2 - devel libevent libevent - devel ncurses ncurses - devel curl curl - devel e2fsprogs e2fsprogs - devel krb5 krb5 - devel libidn libidn - devel openssl openssl - devel readline - devel re2c vim gettext gettext - devel gmp - devel pspell - devel libcap diffutils net - tools libc - client - devel psmisc libXpm - devel git - core c - ares - devel tcl

下载tengine

http://tengine.taobao.org/download/tengine-2.2.1.tar.gz

useradd -s /sbin/nologin php-fpm

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-http_sysguard_module --with-http_concat_module --with-jemalloc --without-dso
make && make install

vim  /etc/init.d/nginx   //写入如下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'
 
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO
 
# Author:   licess
# website:  http://lnmp.org
 
PATH= /usr/local/sbin : /usr/local/bin : /sbin : /bin : /usr/sbin : /usr/bin
NAME=nginx
NGINX_BIN= /usr/local/nginx/sbin/ $NAME
CONFIGFILE= /usr/local/nginx/conf/ $NAME.conf
PIDFILE= /usr/local/nginx/logs/ $NAME.pid
 
case  "$1"  in
     start)
         echo  -n  "Starting $NAME... "
 
         if  netstat  -tnpl |  grep  -q nginx; then
             echo  "$NAME (pid `pidof $NAME`) already running."
             exit  1
         fi
 
         $NGINX_BIN -c $CONFIGFILE
 
         if  "$?"  != 0 ] ;  then
             echo  " failed"
             exit  1
         else
             echo  " done"
         fi
         ;;
 
     stop)
         echo  -n  "Stoping $NAME... "
 
         if  netstat  -tnpl |  grep  -q nginx;  then
             echo  "$NAME is not running."
             exit  1
         fi
 
         $NGINX_BIN -s stop
 
         if  "$?"  != 0 ] ;  then
             echo  " failed. Use force-quit"
             exit  1
         else
             echo  " done"
         fi
         ;;
 
     status)
         if  netstat  -tnpl |  grep  -q nginx;  then
             PID=`pidof nginx`
             echo  "$NAME (pid $PID) is running..."
         else
             echo  "$NAME is stopped"
             exit  0
         fi
         ;;
 
     force-quit)
         echo  -n  "Terminating $NAME... "
 
         if  netstat  -tnpl |  grep  -q nginx;  then
             echo  "$NAME is not running."
             exit  1
         fi
 
         kill  `pidof $NAME`
 
         if  "$?"  != 0 ] ;  then
             echo  " failed"
             exit  1
         else
             echo  " done"
         fi
         ;;
 
     restart)
         $0 stop
         sleep  1
         $0 start
         ;;
 
     reload)
         echo  -n  "Reload service $NAME... "
 
         if  netstat  -tnpl |  grep  -q nginx;  then
             $NGINX_BIN -s reload
             echo  " done"
         else
             echo  "$NAME is not running, can't reload."
             exit  1
         fi
         ;;
 
     configtest)
         echo  -n  "Test $NAME configure files... "
 
         $NGINX_BIN -t
         ;;
 
     *)
         echo  "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
         exit  1
         ;;
 
esac


1
2
3
//修改权限
chmod  755  /etc/init.d/nginx
chkconfig --add nginx

如果想开机启动,请执行:

chkconfig nginx on


配置文件调整

1
mv /usr/ local /nginx/conf/nginx.conf /usr/ local /nginx/conf/nginx.conf.bak

vim /usr/local/nginx/conf/nginx.conf

1
<br data - filtered = "filtered" >

/usr/local/nginx/sbin/nginx -t

1
2
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

service nginx start


安装php

wget    http://php.net/distributions/php-7.1.13.tar.gz

1
. / configure  - - prefix = / usr / local / php  - - with - config - file - path = / usr / local / php / etc  - - enable - fpm  - - with - fpm - user = www  - - with - fpm - group = www  - - with - mysqli = mysqlnd  - - with - pdo - mysql = mysqlnd  - - with - iconv - dir  - - with - freetype - dir = / usr / local / freetype  - - with - jpeg - dir  - - with - png - dir  - - with - zlib  - - with - libxml - dir = / usr  - - enable - xml  - - disable - rpath  - - enable - bcmath  - - enable - shmop  - - enable - sysvsem  - - enable - inline - optimization  - - with - curl  - - enable - mbregex  - - enable - mbstring  - - with - mcrypt  - - enable - ftp  - - with - gd  - - enable - gd - native - ttf  - - with - openssl  - - with - mhash  - - enable - pcntl  - - enable - sockets  - - with - xmlrpc  - - enable - zip  - - enable - soap  - - with - gettext  - - enable - opcache

缺失libmcrypt时安装

yum install libmcrypt libmcrypt-devel mcrypt mhash

make ZEND_EXTRA_LIBS='-liconv'
make install

http://www.apelearn.com/study_v2/chapter18.html

1
2
3
4
5
ln  - sf  / usr / local / php / bin / php  / usr / bin / php
ln  - sf  / usr / local / php / bin / phpize  / usr / bin / phpize
ln  - sf  / usr / local / php / bin / pear  / usr / bin / pear
ln  - sf  / usr / local / php / bin / pecl  / usr / bin / pecl
ln  - sf  / usr / local / php / sbin / php - fpm  / usr / bin / php - fpm
1
cp php.ini-production /usr/local/php/etc/php.ini

修改php.ini中的一些参数

1
2
3
4
5
6
7
8
9
sed  - 's/post_max_size = 8M/post_max_size = 50M/g'  / usr / local / php / etc / php.ini
sed  - 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g'  / usr / local / php / etc / php.ini
sed  - 's/;date.timezone =/date.timezone = PRC/g'  / usr / local / php / etc / php.ini
sed  - 's/short_open_tag = Off/short_open_tag = On/g'  / usr / local / php / etc / php.ini
sed  - 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g'  / usr / local / php / etc / php.ini
sed  - 's/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g'  / usr / local / php / etc / php.ini
sed  - 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g'  / usr / local / php / etc / php.ini
sed  - 's/max_execution_time = 30/max_execution_time = 300/g'  / usr / local / php / etc / php.ini
sed  - 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g'  / usr / local / php / etc / php.ini
1
2
pear config - set  php_ini  / usr / local / php / etc / php.ini
pecl config - set  php_ini  / usr / local / php / etc / php.ini

修改/usr/local/php/etc/php-fpm.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[ global ]
pid  =  / usr / local / php / var / run / php - fpm.pid
error_log  =  / usr / local / php / var / log / php - fpm.log
log_level  =  notice
 
[www]
listen  =  / dev / shm / php - cgi.sock
listen.backlog  =  - 1
listen.allowed_clients  =  127.0 . 0.1
listen.owner  =  php - fpm
listen.group  =  php - fpm
listen.mode  =  0666
user  =  php - fpm
group  =  php - fpm
pm  =  dynamic
pm.max_children  =  10
pm.start_servers  =  2
pm.min_spare_servers  =  1
pm.max_spare_servers  =  6
request_terminate_timeout  =  100
request_slowlog_timeout  =  0
slowlog  =  var / log / slow.log
1
cp /usr/local/src/php-7.1.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

测试是否能重启成功

1
/ usr / local / php / sbin / php - fpm  - t

把php与nginx添加到系统环境变量中去

export PATH=$PATH:/usr/local/php/bin

export PATH=$PATH:/usr/local/nginx/sbin



本文转自 a928154159 51CTO博客,原文链接:http://blog.51cto.com/zhibeiwang/2044163


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
7月前
|
关系型数据库 MySQL 应用服务中间件
手动部署LNMP环境(Alibaba Cloud Linux 2)
本场景带您体验如何在Alibaba Cloud Linux 2.1903 LTS 64位操作系统的云服务器上搭建LNMP环境。
203 0
|
4月前
|
关系型数据库 应用服务中间件 nginx
基于Docker的LNMP环境微服务搭建
基于Docker的LNMP环境微服务搭建
基于Docker的LNMP环境微服务搭建
|
7月前
|
应用服务中间件 PHP nginx
基于Anolis OS 3快速搭建LNMP环境制作KodBox
本教程介绍如何搭建LNMP环境,其中本实验的LNMP分别代表Anolis OS 3、Nginx、Mariadb和PHP。
135 0
|
7月前
|
关系型数据库 MySQL 应用服务中间件
快速搭建LNMP环境
Nginx是一款小巧而高效的Web服务器软件,可帮您在Linux系统下快速方便地搭建出LNMP Web服务环境。本教程介绍如何搭建LNMP环境,其中LNMP分别代表Linux、Nginx、MySQL和PHP。
287 2
|
3月前
|
API PHP 数据库
Docker六脉神剑(四) 使用Docker-Compose进行服务编排搭建lnmp环境
Docker六脉神剑(四) 使用Docker-Compose进行服务编排搭建lnmp环境
33 0
|
6月前
|
运维 Linux 数据安全/隐私保护
宝塔手把手教学-Linux面板安装LNMP & worldpress个人博客
宝塔手把手教学-Linux面板安装LNMP & worldpress个人博客
110 1
|
6月前
|
关系型数据库 MySQL Linux
Linux环境下LNMP架构实战案例
Linux环境下LNMP架构实战案例
|
7月前
|
弹性计算 关系型数据库 MySQL
基于ROS快速部署LNMP环境(CentOS 7)
本教程提供在阿里云云服务器ECS上基于CentOS 7.9操作系统搭建LNMP环境的指引。LNMP是应用广泛的网站服务系统,由四种免费的开源软件Linux、Nginx、MySQL和PHP组成。搭建好LNMP环境后,您可以在该ECS实例上搭建网站、访问网站
406 0
|
7月前
|
关系型数据库 MySQL 应用服务中间件
手动部署LNMP环境(Ubuntu 20)
本教程介绍如何在Ubuntu 20.04操作系统的ECS实例上搭建一套Nginx、MySQL和PHP应用的开发环境。
301 0
|
7月前
|
关系型数据库 MySQL 应用服务中间件
基于Ubuntu搭建LNMP环境
本教程介绍如何在Ubuntu 18.04操作系统的ECS实例上搭建一套Nginx、MySQL和PHP应用的开发环境。
103 0