centos下推荐使用yum包管理器来安装软件

为yum设置软件源

  1. 备份

    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  2. 下载新的CentOS-Base.repo 到/etc/yum.repos.d/

    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
  3. 之后运行yum makecache生成缓存

安装企业级linux扩展源epel

yum install -y epel-release

安装webtatic源

对centos系统不太熟练的同学,这里推荐使用webtatic来安装php

rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

Nginx安装

  1. 安装命令

    yum install -y nginx
  2. 配置文件所在目录

    /etc/nginx
  3. 相关命令

    service nginx start|stop|status|restart

Mysql5.7安装

推荐使用Percona来安装mysql, 安装或使用过程中遇到的问题请查看本页面的FAQ

  1. 安装Percona的yum源

    yum install http://www.percona.com/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm
  2. 测试一下Percona的yum源

    yum list | grep percona

    你会看到如下:

    ...
    Percona-Server-57-debuginfo.x86_64      5.7.10-3.1.el7                 @percona-release-x86_64
    Percona-Server-client-57.x86_64         5.7.10-3.1.el7                 @percona-release-x86_64
    Percona-Server-devel-57.x86_64          5.7.10-3.1.el7                 @percona-release-x86_64
    Percona-Server-server-57.x86_64         5.7.10-3.1.el7                 @percona-release-x86_64
    Percona-Server-shared-57.x86_64         5.7.10-3.1.el7                 @percona-release-x86_64
    Percona-Server-shared-compat-57.x86_64  5.7.10-3.1.el7                 @percona-release-x86_64
    Percona-Server-test-57.x86_64           5.7.10-3.1.el7                 @percona-release-x86_64
    Percona-Server-tokudb-57.x86_64         5.7.10-3.1.el7                 @percona-release-x86_64
    ...
  3. 安装Percona Server

    yum install -y Percona-Server-server-57
  4. 停止mysql服务

    service mysql stop
  5. 取消mysql的严格模式和新增对ngram的支持 修改配置文件 /etc/my.cnf ,在 [mysqld] 段中添加

    sql_mode=NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER
    ngram_token_size=2
  6. 启动mysql

    service mysql start
  7. 获取mysql的root账号初始密码的两种方式:

    • 直接获取安装时生成的随机密码

      cat /var/log/mysqld.log  | grep "A temporary password" | awk -F " " '{print$11}'
    • 使用无密码登陆的方式,修改配置文件 /etc/my.cnf ,在 [mysqld] 中添加

      skip-grant-tables
  8. 测试连接并修改root密码

    • 登陆命令
      mysql -uroot -p
    • 修改root密码
      step 1: SET PASSWORD = PASSWORD('your new password');
      step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
      step 3: flush privileges;
  9. 相关命令

    service mysql start|stop|status|restart

Redis安装

  1. 安装命令

    yum install -y redis
  2. 修改配置文件

    vi /etc/redis.conf
    PS:简单的单机部署只需要把daemonize改为yes即可,更多的配置项请查阅/etc/redis.conf文件
  3. 启动redis

    service redis start
  4. 测试redis

    redis-cli
  5. 相关命令

    service redis start|stop|status|restart

PHP安装

  1. 安装命令

    yum install -y mod_php71w php71w-bcmath php71w-cli php71w-common php71w-dba php71w-devel php71w-embedded php71w-enchant
    yum install -y php71w-fpm php71w-gd php71w-imap  php71w-lda php71w-interbase php71w-intl php71w-ldap php71w-mbstring php71w-mcrypt
    yum install -y php71w-mysqlnd php71w-odbc php71w-opcache php71w-pdo php71w-pear php71w-pecl-apcu php71w-pecl-imagick
    yum install -y php71w-pecl-memcached php71w-pecl-mongodb php71w-pecl-redis php71w-pecl-xdebug php71w-pgsql php71w-phpdbg
    yum install -y php71w-process php71w-pspell php71w-recode php71w-snmp php71w-soap php71w-tidy php71w-xml php71w-xmlrpc
  2. 启动php-fpm

    service php-fpm start
  3. php的配置文件

    /etc/php.ini
    /etc/php.d/*
    /etc/php-fpm.ini
    /etc/php-fpm.d/*
  4. 相关命令

    service php-fpm start|stop|status|restart

测试lnmpr

  1. 新建nginx虚拟目录配置文件:vi /etc/nginx/conf.d/test-lnmpr.conf

    server {
     listen       8080;
     server_name  localhost;
     charset UTF-8;
     location / {
         root   /var/webroot;
         index  index.php index.html index.htm;
     }
    
     location ~ \.php$ {
         root           /var/webroot;
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  /var/webroot/$fastcgi_script_name;
         include        fastcgi_params;
     }
    }
  2. 新建php测试文件: vi /var/webroot/index.php

    <?php
    phpinfo();
  3. 访问http://ip:8080

FAQ

  1. 想在测试环境的mysql设置简单密码

    • 报错如下:
      ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    • 解决方法: 修改配置文件 /etc/my.cnf ,在 [mysqld] 中添加
      default_password_lifetime=0
      validate_password_length=4
      validate_password_policy=LOW
  2. rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm 的问题

    • 若出现如下错误
      14: problem making ssl connection
      Error: Cannot find a valid baseurl for repo: webtatic
    • 解决方法: 修改文件 /etc/yum.repos.d/epel.repo
      [epel]
      name=Extra Packages for Enterprise Linux 6 - $basearch
      #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
      mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
      failovermethod=priority
      enabled=1
      gpgcheck=1
      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

      将enabled=1先改为enabled=0 yum install ca-certificates,安装成功后,将enabled重新改为1,保存后再执行命令

  3. 在访问nginx的时候出现超时

    • 原因:防火墙阻止访问
    • 解决:设置防火墙或关闭防火墙 service iptables stop
  4. 在访问nginx时出现 403 Forbidden

    • 权限问题: 查看nginx.conf的运行用户,把对应项目代码目录的权限要与nginx运行用户的权限一致

    • 看一下selinux是否关闭了

        //如果SELinux status参数为enabled即为开启状态
        /usr/sbin/sestatus -v
      
        //临时关闭selinux
        setenforce 0
      
        //永久关闭selinux
        step1: 修改/etc/selinux/config 文件
        step2: 将SELINUX=enforcing改为SELINUX=disabled
        step3: 重启机器即可
Masterlab - 404
404
您所访问的页面不存在或出错了
help->pageIndex no found;
debug
Sql:
Array
(
)
TRACE:
Array
(
)
GET:
Array
(
    [md] => setup_centos6
    [_target] => Array
        (
            [0] => help
        )

)
POST:
Array
(
)
FILES:
Array
(
)
Include: 118
Array
(
    [0] => /data/www/masterlab_site/public/index.php
    [1] => /data/www/masterlab_site/app/globals.php
    [2] => /data/www/masterlab_site/vendor/autoload.php
    [3] => /data/www/masterlab_site/vendor/composer/autoload_real.php
    [4] => /data/www/masterlab_site/vendor/composer/platform_check.php
    [5] => /data/www/masterlab_site/vendor/composer/ClassLoader.php
    [6] => /data/www/masterlab_site/vendor/composer/autoload_static.php
    [7] => /data/www/masterlab_site/vendor/symfony/polyfill-php72/bootstrap.php
    [8] => /data/www/masterlab_site/vendor/symfony/polyfill-intl-normalizer/bootstrap.php
    [9] => /data/www/masterlab_site/vendor/ralouphie/getallheaders/src/getallheaders.php
    [10] => /data/www/masterlab_site/vendor/symfony/polyfill-ctype/bootstrap.php
    [11] => /data/www/masterlab_site/vendor/symfony/polyfill-intl-idn/bootstrap.php
    [12] => /data/www/masterlab_site/vendor/guzzlehttp/psr7/src/functions_include.php
    [13] => /data/www/masterlab_site/vendor/guzzlehttp/psr7/src/functions.php
    [14] => /data/www/masterlab_site/vendor/guzzlehttp/promises/src/functions_include.php
    [15] => /data/www/masterlab_site/vendor/guzzlehttp/promises/src/functions.php
    [16] => /data/www/masterlab_site/vendor/symfony/polyfill-mbstring/bootstrap.php
    [17] => /data/www/masterlab_site/vendor/guzzlehttp/guzzle/src/functions_include.php
    [18] => /data/www/masterlab_site/vendor/guzzlehttp/guzzle/src/functions.php
    [19] => /data/www/masterlab_site/vendor/hornet/framework/src/framework/bootstrap.php
    [20] => /data/www/masterlab_site/vendor/hornet/framework/src/framework/function.php
    [21] => /data/www/masterlab_site/vendor/hornet/framework/src/framework/FilterSqlInject.php
    [22] => /data/www/masterlab_site/vendor/hornet/framework/src/framework/HornetCoreException.php
    [23] => /data/www/masterlab_site/vendor/hornet/framework/src/framework/HornetLogicException.php
    [24] => /data/www/masterlab_site/vendor/hornet/framework/src/framework/ErrorHandler.php
    [25] => /data/www/masterlab_site/vendor/hornet/framework/src/framework/HornetEngine.php
    [26] => /data/www/masterlab_site/vendor/hornet/framework/src/framework/protocol/Iprotocol.php
    [27] => /data/www/masterlab_site/vendor/hornet/framework/src/framework/protocol/Api.php
    [28] => /data/www/masterlab_site/vendor/hornet/framework/src/framework/protocol/Ajax.php
    [29] => /data/www/masterlab_site/vendor/lcobucci/jwt/compat/class-aliases.php
    [30] => /data/www/masterlab_site/vendor/lcobucci/jwt/src/Token/Plain.php
    [31] => /data/www/masterlab_site/vendor/lcobucci/jwt/src/Token.php
    [32] => /data/www/masterlab_site/vendor/lcobucci/jwt/src/Token/Signature.php
    [33] => /data/www/masterlab_site/vendor/lcobucci/jwt/src/Signature.php
    [34] => /data/www/masterlab_site/vendor/lcobucci/jwt/compat/json-exception-polyfill.php
    [35] => /data/www/masterlab_site/vendor/lcobucci/jwt/compat/lcobucci-clock-polyfill.php
    [36] => /data/www/masterlab_site/app/function/autoload.php
    [37] => /data/www/masterlab_site/app/function/array.php
    [38] => /data/www/masterlab_site/app/function/common.php
    [39] => /data/www/masterlab_site/app/function/cryptojs-aes.php
    [40] => /data/www/masterlab_site/app/function/sql.php
    [41] => /data/www/masterlab_site/app/function/string.php
    [42] => /data/www/masterlab_site/app/function/system.php
    [43] => /data/www/masterlab_site/app/function/time.php
    [44] => /data/www/masterlab_site/app/function/upload_image.php
    [45] => /data/www/masterlab_site/app/function/web.php
    [46] => /data/www/masterlab_site/app/function/response_error.php
    [47] => /data/www/masterlab_site/app/function/excel.php
    [48] => /data/www/masterlab_site/vendor/symfony/yaml/Yaml.php
    [49] => /data/www/masterlab_site/vendor/symfony/yaml/Parser.php
    [50] => /data/www/masterlab_site/vendor/symfony/yaml/Inline.php
    [51] => /data/www/masterlab_site/vendor/symfony/yaml/Unescaper.php
    [52] => /data/www/masterlab_site/app/config/app.cfg.php
    [53] => /data/www/masterlab_site/app/constants.php
    [54] => /data/www/masterlab_site/app/config/common.cfg.php
    [55] => /data/www/masterlab_site/app/config/session.cfg.php
    [56] => /data/www/masterlab_site/app/ctrl/Help.php
    [57] => /data/www/masterlab_site/app/ctrl/BaseCtrl.php
    [58] => /data/www/masterlab_site/vendor/symfony/event-dispatcher/EventDispatcher.php
    [59] => /data/www/masterlab_site/vendor/symfony/event-dispatcher/EventDispatcherInterface.php
    [60] => /data/www/masterlab_site/vendor/symfony/event-dispatcher-contracts/EventDispatcherInterface.php
    [61] => /data/www/masterlab_site/app/model/SettingModel.php
    [62] => /data/www/masterlab_site/app/model/BaseDictionaryModel.php
    [63] => /data/www/masterlab_site/app/model/CacheModel.php
    [64] => /data/www/masterlab_site/app/model/DbModel.php
    [65] => /data/www/masterlab_site/app/model/BaseModel.php
    [66] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php
    [67] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Configuration.php
    [68] => /data/www/masterlab_site/vendor/doctrine/event-manager/lib/Doctrine/Common/EventManager.php
    [69] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/MySQL/Driver.php
    [70] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
    [71] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
    [72] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver.php
    [73] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php
    [74] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php
    [75] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php
    [76] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Connection.php
    [77] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/TransactionIsolationLevel.php
    [78] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/ParameterType.php
    [79] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/FetchMode.php
    [80] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
    [81] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Connection.php
    [82] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php
    [83] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php
    [84] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOQueryImplementation.php
    [85] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Statement.php
    [86] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php
    [87] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Statement.php
    [88] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/ResultStatement.php
    [89] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Result.php
    [90] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatementImplementations.php
    [91] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/Events.php
    [92] => /data/www/masterlab_site/lib/MyRedis.php
    [93] => /data/www/masterlab_site/vendor/doctrine/dbal/lib/Doctrine/DBAL/SQLParserUtils.php
    [94] => /data/www/masterlab_site/app/classes/UserAuth.php
    [95] => /data/www/masterlab_site/app/ctrl/Resource.php
    [96] => /data/www/masterlab_site/lib/parsedown/Parsedown.php
    [97] => /data/www/masterlab_site/app/view/help.php
    [98] => /data/www/masterlab_site/app/view/common/header-meta.php
    [99] => /data/www/masterlab_site/app/view/common/header-style.php
    [100] => /data/www/masterlab_site/app/view/common/header-script.php
    [101] => /data/www/masterlab_site/app/view/common/body-header.php
    [102] => /data/www/masterlab_site/app/view/common/common-footer.php
    [103] => /data/www/masterlab_site/app/view/common/siteFooter.php
    [104] => /data/www/masterlab_site/app/view/modal/login.php
    [105] => /data/www/masterlab_site/app/view/modal/signup.php
    [106] => /data/www/masterlab_site/app/view/modal/get-started.php
    [107] => /data/www/masterlab_site/app/view/modal/try.php
    [108] => /data/www/masterlab_site/app/view/modal/trial.php
    [109] => /data/www/masterlab_site/app/view/modal/buy-premium.php
    [110] => /data/www/masterlab_site/app/view/modal/loading.php
    [111] => /data/www/masterlab_site/app/view/modal/signup-failed.php
    [112] => /data/www/masterlab_site/app/view/modal/existing-account.php
    [113] => /data/www/masterlab_site/app/view/modal/unsupported-browser.php
    [114] => /data/www/masterlab_site/app/view/modal/calculate.php
    [115] => /data/www/masterlab_site/app/view/modal/sso-signup.php
    [116] => /data/www/masterlab_site/app/view/modal/i18n.php
    [117] => /data/www/masterlab_site/app/view/exception.php
)