此处的lnmp分别指:centos7.2,nginx1.14,mysql5.7,php7.2

修改yum源

  1. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
  2. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

安装nginx

  • 1 新建文件/etc/yum.repos.d/nginx.repo,内容如下:
  1. [nginx]
  2. name=nginx repo
  3. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  4. gpgcheck=0
  5. enabled=1
  • 使用remi源
  1. // 追加CentOS 6.5的epel及remi源
  2. rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
  3. rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
  4. // CentOS 7.0的源。
  5. yum install epel-release -y
  6. rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
  • 3 安装nginx
  1. yum install -y nginx
  2. // 启动
  3. nginx

安装mysql

  • 1 安装数据库
  1. // 查看系统版本
  2. cat /etc/redhat-release
  3. CentOS Linux release 7.2.1511 (Core)
  4. //下载YUM库
  5. wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
  6. //安装YUM库
  7. yum localinstall -y mysql57-community-release-el7-7.noarch.rpm
  8. //安装数据库
  9. yum install -y mysql-community-server
  10. //启动MySQL服务
  11. systemctl enable mysqld.service
  12. systemctl start mysqld.service
  • 2 配置数据库
  1. //安装完毕后,会在/var/log/mysqld.log 中能看到默认的密码
  2. cat /var/log/mysqld.log |grep "A temporary password is generated"
  3. (=zftZwCO9ys
  4. //登陆
  5. mysql -uroot -p
  6. //修改密码
  7. ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
  8. //可选:允许root远程访问
  9. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
  10. // 更新
  11. flush privileges;
  12. //有时会因为系统默认安装的防火墙导致无法访问
  13. 可关闭防火墙
  14. systemctl stop firewalld.service #停止firewall
  15. systemctl disable firewalld.service #禁止firewall开机启动

安装php

  1. // 可选卸载原PHP版本
  2. yum -y remove php*
  3. // 更新rpm
  4. rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  5. rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  6. // 可选,查看可安装版本列表,可以发现从4-7.2的版本都有,7.2版本名为72w
  7. yum list php*
  8. // 安装php72w 并安装php常用扩展
  9. yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-imap php72w-ldap php72w-odbc php72w-pear php72w-xmlrpc
  10. // 开机启动Php-fpm
  11. systemctl enable php-fpm.service
  12. systemctl start php-fpm.service
  13. // 查看开机启动列表
  14. systemctl list-units --type=service

配置nginx

编辑文件 /etc/nginx/conf.d/default.conf,内容如下

  1. location / {
  2. root /usr/share/nginx/html;
  3. index index.php index.html index.htm;
  4. }
  5. location ~ \.php$ {
  6. root /usr/share/nginx/html;
  7. fastcgi_pass 127.0.0.1:9000;
  8. fastcgi_index index.php;
  9. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  10. include fastcgi_params;
  11. }
  1. // 检查nginx语法
  2. nginx -t
  3. // 平滑重启
  4. nginx -s reload
分类: 未分类

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注