美文网首页
如何搭建一个lnmp环境

如何搭建一个lnmp环境

作者: lookphp | 来源:发表于2018-01-05 18:19 被阅读17次

    方案一(傻瓜式):

    使用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

    相关文章

      网友评论

          本文标题:如何搭建一个lnmp环境

          本文链接:https://www.haomeiwen.com/subject/skpsnxtx.html