如何搭建一个lnmp环境

方案一(傻瓜式):

使用lnmp一键安装包

方案二(订制安装):

  1. 安装nginx1.10.2.
  2. 安装mysql5.7.
  3. 安装PHP5.6.
  4. 安装PHP扩展.

具体安装步骤

提前申明下服务器版本是centos6.*。

  1. 安装nginx.

查看yum源中的nginx二进制包。

[root@iZm5ebopxrlqc9apn3qm5mZ ~]# yum list | grep nginx 
nginx.x86_64                               1.10.2-1.el6                 @epel   
nginx-all-modules.noarch                   1.10.2-1.el6                 @epel   
nginx-filesystem.noarch                    1.10.2-1.el6                 @epel   
nginx-mod-http-geoip.x86_64                1.10.2-1.el6                 @epel   
nginx-mod-http-image-filter.x86_64         1.10.2-1.el6                 @epel   
nginx-mod-http-perl.x86_64                 1.10.2-1.el6                 @epel   
nginx-mod-http-xslt-filter.x86_64          1.10.2-1.el6                 @epel   
nginx-mod-mail.x86_64                      1.10.2-1.el6                 @epel   
nginx-mod-stream.x86_64                    1.10.2-1.el6                 @epel   
collectd-nginx.x86_64                      4.10.9-4.el6                 epel    
munin-nginx.noarch                         2.0.33-1.el6                 epel    
pcp-pmda-nginx.x86_64                      3.10.9-9.el6                 base    

根据列表中的nginx版本,进行安装。

yum install -y nginx.x86_64

2.安装mysql.

一、安装配置MySQL的yum源

# 安装MySQL的yum源,下面是RHEL6系列的下载地址
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
# 安装yum-config-manager
yum install yum-utils -y
# 禁用MySQL5.6的源
yum-config-manager --disable mysql56-community
# 启用MySQL5.7的源
yum-config-manager --enable mysql57-community-dmr
# 用下面的命令查看是否配置正确
yum repolist enabled | grep mysql

执行结果如下:

# 安装MySQL的yum源,下面是RHEL6系列的下载地址
[root@iZm5ebopxrlqc9apn3qm5mZ ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
Preparing...                ########################################### [100%]
   1:mysql-community-release########################################### [100%]

#安装yum-config-manager
[root@iZm5ebopxrlqc9apn3qm5mZ ~]# yum install yum-utils -y
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * webtatic: us-east.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.30-40.el6 will be installed
--> Processing Dependency: libxml2-python for package: yum-utils-1.1.30-40.el6.noarch
--> Running transaction check
---> Package libxml2-python.x86_64 0:2.7.6-21.el6_8.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================================================
 Package                                             Arch                                        Version                                                Repository                                 Size
========================================================================================================================================================================================================
Installing:
 yum-utils                                           noarch                                      1.1.30-40.el6                                          base                                      113 k
Installing for dependencies:
 libxml2-python                                      x86_64                                      2.7.6-21.el6_8.1                                       base                                      325 k

Transaction Summary
========================================================================================================================================================================================================
Install       2 Package(s)

Total download size: 437 k
Installed size: 2.2 M
Downloading Packages:
(1/2): libxml2-python-2.7.6-21.el6_8.1.x86_64.rpm                                                                                                                                | 325 kB     00:00     
(2/2): yum-utils-1.1.30-40.el6.noarch.rpm                                                                                                                                        | 113 kB     00:00     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                   2.2 MB/s | 437 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : libxml2-python-2.7.6-21.el6_8.1.x86_64                                                                                                                                               1/2 
  Installing : yum-utils-1.1.30-40.el6.noarch                                                                                                                                                       2/2 
  Verifying  : yum-utils-1.1.30-40.el6.noarch                                                                                                                                                       1/2 
  Verifying  : libxml2-python-2.7.6-21.el6_8.1.x86_64                                                                                                                                               2/2 

Installed:
  yum-utils.noarch 0:1.1.30-40.el6                                                                                                                                                                      

Dependency Installed:
  libxml2-python.x86_64 0:2.7.6-21.el6_8.1                                                                                                                                                              

Complete!

#禁用MySQL5.6的源
[root@iZm5ebopxrlqc9apn3qm5mZ ~]# yum-config-manager --disable mysql56-community
Loaded plugins: fastestmirror
======================================================================================= repo: mysql56-community ========================================================================================
[mysql56-community]
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/6
baseurl = http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/6/mysql56-community
cost = 1000
enabled = 0
enablegroups = True
exclude = 
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/6/mysql56-community/gpgcadir
gpgcakey = 
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/6/mysql56-community/gpgdir
gpgkey = file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/6/mysql56-community/headers
http_caching = all
includepkgs = 
keepalive = True
mdpolicy = group:primary
mediaid = 
metadata_expire = 21600
metalink = 
mirrorlist = 
mirrorlist_expire = 86400
name = MySQL 5.6 Community Server
old_base_cache_dir = 
password = 
persistdir = /var/lib/yum/repos/x86_64/6/mysql56-community
pkgdir = /var/cache/yum/x86_64/6/mysql56-community/packages
proxy = False
proxy_dict = 
proxy_password = 
proxy_username = 
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert = 
sslclientcert = 
sslclientkey = 
sslverify = True
throttle = 0
timeout = 30.0
username = 

#启用MySQL5.7的源
[root@iZm5ebopxrlqc9apn3qm5mZ ~]# yum-config-manager --enable mysql57-community-dmr
Loaded plugins: fastestmirror
===================================================================================== repo: mysql57-community-dmr ======================================================================================
[mysql57-community-dmr]
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/6
baseurl = http://repo.mysql.com/yum/mysql-5.7-community/el/6/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/6/mysql57-community-dmr
cost = 1000
enabled = 1
enablegroups = True
exclude = 
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/6/mysql57-community-dmr/gpgcadir
gpgcakey = 
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/6/mysql57-community-dmr/gpgdir
gpgkey = file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/6/mysql57-community-dmr/headers
http_caching = all
includepkgs = 
keepalive = True
mdpolicy = group:primary
mediaid = 
metadata_expire = 21600
metalink = 
mirrorlist = 
mirrorlist_expire = 86400
name = MySQL 5.7 Community Server Development Milestone Release
old_base_cache_dir = 
password = 
persistdir = /var/lib/yum/repos/x86_64/6/mysql57-community-dmr
pkgdir = /var/cache/yum/x86_64/6/mysql57-community-dmr/packages
proxy = False
proxy_dict = 
proxy_password = 
proxy_username = 
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert = 
sslclientcert = 
sslclientkey = 
sslverify = True
throttle = 0
timeout = 30.0
username = 

#用下面的命令查看是否配置正确,检查是否有mysql57-community-dmr这个源,如果有则配置正确(如下面显示的第三个)
[root@iZm5ebopxrlqc9apn3qm5mZ ~]# yum repolist enabled | grep mysql
mysql-connectors-community MySQL Connectors Community                         42
mysql-tools-community      MySQL Tools Community                              53
mysql57-community-dmr      MySQL 5.7 Community Server Development Milesto    219

二、yum安装MySQL5.7

# 安装MySQL5.7
yum install mysql-community-server

安装结果如下:

[root@iZm5ebopxrlqc9apn3qm5mZ ~]# yum install mysql-community-server
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * webtatic: uk.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.20-1.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.20-1.el6 for package: mysql-community-server-5.7.20-1.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.20-1.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.20-1.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.20-1.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.7.20-1.el6 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.20-1.el6 will be obsoleting
---> Package mysql-libs.x86_64 0:5.1.73-8.el6_8 will be obsoleted
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================================================
 Package                                                Arch                                   Version                                      Repository                                             Size
========================================================================================================================================================================================================
Installing:
 mysql-community-libs                                   x86_64                                 5.7.20-1.el6                                 mysql57-community-dmr                                 2.1 M
     replacing  mysql-libs.x86_64 5.1.73-8.el6_8
 mysql-community-server                                 x86_64                                 5.7.20-1.el6                                 mysql57-community-dmr                                 152 M
Installing for dependencies:
 mysql-community-client                                 x86_64                                 5.7.20-1.el6                                 mysql57-community-dmr                                  23 M
 mysql-community-common                                 x86_64                                 5.7.20-1.el6                                 mysql57-community-dmr                                 329 k

Transaction Summary
========================================================================================================================================================================================================
Install       4 Package(s)

Total download size: 177 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): mysql-community-client-5.7.20-1.el6.x86_64.rpm                                                                                                                            |  23 MB     00:02     
(2/4): mysql-community-common-5.7.20-1.el6.x86_64.rpm                                                                                                                            | 329 kB     00:00     
(3/4): mysql-community-libs-5.7.20-1.el6.x86_64.rpm                                                                                                                              | 2.1 MB     00:00     
(4/4): mysql-community-server-5.7.20-1.el6.x86_64.rpm                                                                                                                            | 152 MB     00:13     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                    11 MB/s | 177 MB     00:16     
warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid : MySQL Release Engineering <mysql-build@oss.oracle.com>
 Package: mysql-community-release-el6-5.noarch (installed)
 From   : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-community-common-5.7.20-1.el6.x86_64                                                                                                                                           1/5 
  Installing : mysql-community-libs-5.7.20-1.el6.x86_64                                                                                                                                             2/5 
  Installing : mysql-community-client-5.7.20-1.el6.x86_64                                                                                                                                           3/5 
  Installing : mysql-community-server-5.7.20-1.el6.x86_64                                                                                                                                           4/5 
  Erasing    : mysql-libs-5.1.73-8.el6_8.x86_64                                                                                                                                                     5/5 
  Verifying  : mysql-community-common-5.7.20-1.el6.x86_64                                                                                                                                           1/5 
  Verifying  : mysql-community-libs-5.7.20-1.el6.x86_64                                                                                                                                             2/5 
  Verifying  : mysql-community-client-5.7.20-1.el6.x86_64                                                                                                                                           3/5 
  Verifying  : mysql-community-server-5.7.20-1.el6.x86_64                                                                                                                                           4/5 
  Verifying  : mysql-libs-5.1.73-8.el6_8.x86_64                                                                                                                                                     5/5 

Installed:
  mysql-community-libs.x86_64 0:5.7.20-1.el6                                                        mysql-community-server.x86_64 0:5.7.20-1.el6                                                       

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.20-1.el6                                                       mysql-community-common.x86_64 0:5.7.20-1.el6                                                      

Replaced:
  mysql-libs.x86_64 0:5.1.73-8.el6_8                                                                                                                                                                    

Complete!

参考地址如下:https://www.cnblogs.com/sweet521/p/6196732.html

3.安装PHP
默认的版本太低了,手动安装有一些麻烦,想采用Yum安装的可以使用下面的方案:
首先卸载默认安装好的PHP

#查看已安装好的PHP版本及扩展
rpm -qa | grep php
#卸载rpm包
rpm -e php***

或使用如下方法:
1.检查当前安装的PHP包

yum list installed | grep php

如果有安装的PHP包,先删除他们

yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64

修改yum源地址:

  Centos 5.X
  rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
  CentOs 6.x
  rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
  CentOs 7.X
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

如果想删除上面安装的包,重新安装
rpm -qa | grep webstatic
rpm -e 上面搜索到的包即可

3.运行yum install
安装php55*

  yum install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php55w-gd.x86_64 php55w-ldap.x86_64 php55w-mbstring.x86_64 php55w-mcrypt.x86_64 php55w-mysql.x86_64 php55w-pdo.x86_64

安装php56*

yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64

安装php7*

yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64

4.安装PHP FPM

yum install php55w-fpm 
yum install php56w-fpm 
yum install php70w-fpm

注:如果想升级到5.6把上面的55w换成56w就可以了。

参考地址:
PHP 5.3.0以上推荐使用mysqlnd驱动
centOS怎样强制卸载PHP以及自定义安装PHP

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,602评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,442评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,878评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,306评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,330评论 5 373
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,071评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,382评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,006评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,512评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,965评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,094评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,732评论 4 323
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,283评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,286评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,512评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,536评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,828评论 2 345

推荐阅读更多精彩内容