安装LNMP环境

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

准备安装

[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


相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3天前
|
关系型数据库 MySQL 应用服务中间件
Linux 手动安装快速部署 LNMP 环境实战
本文详细记录了在阿里云ECS上手动搭建LNMP环境的过程,系统选用Ubuntu 24.04。主要内容包括:1) 使用`apt`安装Nginx和MySQL,并更新软件源;2) 编译安装PHP 8.4.5,配置PHP-FPM及环境路径;3) 配置MySQL root用户密码;4) 调整Nginx支持PHP解析并测试整体环境。通过此过程,重现手动配置服务器的细节,帮助熟悉各组件的安装与协同工作。
|
21天前
|
关系型数据库 应用服务中间件 Linux
Linux云服务器如何搭建LNMP环境
LNMP环境是Linux系统中常用的Web服务架构,由Linux、Nginx、MySQL/MariaDB和PHP组成,适用于高效托管动态网站。本文以CentOS 7为例,详细介绍了LNMP环境的搭建步骤,包括Nginx、MariaDB和PHP的安装与配置,以及最终通过创建`index.php`文件验证环境是否成功部署。具体操作涵盖配置YUM仓库、安装服务、编辑配置文件、启动服务等关键步骤,确保用户能够顺利搭建并运行LNMP环境。
44 1
Linux云服务器如何搭建LNMP环境
|
5月前
|
NoSQL 应用服务中间件 PHP
LNMP一键安装
LNMP一键安装
|
10月前
|
关系型数据库 应用服务中间件 nginx
基于Docker的LNMP环境微服务搭建
基于Docker的LNMP环境微服务搭建
基于Docker的LNMP环境微服务搭建
|
7月前
|
关系型数据库 Linux 应用服务中间件
linux服务器下LNMP安装与配置方法
通过遵循上述步骤,你已经在Linux服务器上成功配置了LNMP环境。这只是初步设置,根据你的实际需求,可能需要进一步的调整与优化。记得经常检查每个组件的默认配置文件,并根据需要进行调整以优化性能和安全性。
152 0
|
10月前
|
关系型数据库 应用服务中间件 Linux
linux 下安装 LNMP 最简单的安装方法
linux 下安装 LNMP 最简单的安装方法
99 0
|
10月前
|
API PHP 数据库
Docker六脉神剑(四) 使用Docker-Compose进行服务编排搭建lnmp环境
Docker六脉神剑(四) 使用Docker-Compose进行服务编排搭建lnmp环境
83 0
|
运维 Linux 数据安全/隐私保护
宝塔手把手教学-Linux面板安装LNMP & worldpress个人博客
宝塔手把手教学-Linux面板安装LNMP & worldpress个人博客
231 1
|
关系型数据库 MySQL Linux
Linux环境下LNMP架构实战案例
Linux环境下LNMP架构实战案例
140 0
|
关系型数据库 MySQL 应用服务中间件
手动部署LNMP环境(Alibaba Cloud Linux 2)
本场景带您体验如何在Alibaba Cloud Linux 2.1903 LTS 64位操作系统的云服务器上搭建LNMP环境。