CentOS 7 安装 lnmp

  • 本地远程连接服务器
  1. 安装 ssh 服务
yum install ssh
  1. 启动 ssh
service sshd start  
chkconfig sshd on
  1. yum 换源
yum update
  1. 安装nginx
yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum repolist enabled | grep "nginx*" 

yum -y install nginx
  • 启动 nginx
service nginx start
  • 设置 nginx 开机自启动
systemctl enable nginx.service
  • 检查 nginx 自启动设置是否成功
systemctl list-dependencies | grep nginx
  • 浏览器输入你的 ip 检测是否安装成功,如出现欢迎页面,则 nginx 安装成功
  • nginx 配置如下

    server{
    listen  80;
    server_name youserver;
    index index.html index.php;
    root /home/public;  //你的项目路径
    #charset koi8-r;
    #access_log logs/host.access.log main;
    location / {
    index index.html index.htm index.php;
    try_files $uri $uri/ /index.php?$query_string;
    }
    error_page 404    /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ .php$ {
    # proxy_pass http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
    root   /home/public;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/public$fastcgi_script_name;
    include  fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /.ht {
    deny all;
    }
    }
    
  1. 安装 mysql

    yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
    
    yum repolist enabled | grep "mysql.*-community.*"
    
    yum -y install mysql-community-server install mysql-community-devel
    • 启动 mysql
    service mysqld start
    • 检查 mysql 是否启动成功
    service mysqld status 或者 ps -ef | grep mysql
    • 设置 mysql 开机自启动
    systemctl enable mysqld.service
    • 检查 mysql 开机自启动是否设置成功
    systemctl list-dependencies | grep mysqld
    • 更换 mysql root 用户密码
    mysql5.7 以后的争强了安全机制,所以使用yum安装,系统会自动生成一个随机的密码,并且不能设置简单密码。所以需要修改 mysql 全局参数
    
    先用日志密码登录 mysql 
    
    grep 'temporary password' /var/log/mysqld.log
    
    会输出结果: A temporary password is generated for root@localhost: ******
    
    使用此密码登录后 执行 SHOW VARIABLES LIKE 'validate_password%‘;  查看 mysql 密码策略
    
    +--------------------------------------+--------+
    | Variable_name                        | Value  |
    +--------------------------------------+--------+
    | validate_password_check_user_name    | OFF    | 
    | validate_password_dictionary_file    |        |
    | validate_password_length             | 8      |
    | validate_password_mixed_case_count   | 1      |
    | validate_password_number_count       | 1      |
    | validate_password_policy             | MEDIUM | 
    | validate_password_special_char_count | 1      |
    +--------------------------------------+--------+
    
    执行 set global validate_password_policy=LOW;  修改密码策略
    
    执行 set global validate_password_length=6; 修改验证密码长度
    
    切换 user 库
    
    update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';
    
    重启 mysqld 服务,再用新密码登录即可
    
    如果无法登录,提示Access denied for user 'root'@'localhost'
    
    重新更新 root 用户的 plugin 字段
    
    update user set plugin='mysql_native_password' where user = 'root';
    
    更新成功后.重新执行更新密码操作
    
    刷新权限  flush privileges;
  • 安装 php7

    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    
    yum -y install php71w php71w-fpm
    
    yum -y install php71w-mbstring php71w-common php71w-gd php71w-mcrypt
    
    yum -y install php71w-mysql php71w-xml php71w-cli php71w-devel
    
    yum -y install php71w-pecl-memcached php71w-pecl-redis php71w-opcache
    • 验证 PHP 是否安装成功 php -v
    • 验证 PHP 拓展是否安装成功 php -m
    • 启动 PHP-fpm
    service php-fpm start
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 3
ThinkQ

安装mysql后修改密码:
step 1: SET PASSWORD = PASSWORD('your new password');

step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

step 3: flush privileges;

5年前 评论
幽弥狂

怎么不是 72 呢?

5年前 评论

service php-fpm star 少写了一个t,我这几天突然发现了 :joy:

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!