lnmp配置

时间:2019-11-18
本文章向大家介绍lnmp配置,主要包括lnmp配置使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

yum源切换

下载wegt工具

yum install -y wget

备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

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

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum缓存生成

yum clean all
yum makecache
yum -y update

安装nginx

yum install nginx

配置nginx服务器

vim /etc/nginx/nginx.conf
server {
    listen 80;
    server_name wordpress.tpthink.top;   # 此为必修改项,请替换为服务器公网 IP 或域名
    root /project/wordpress; # 此为必修改项,请注意指向站点根目录的 public 子目录

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
        try_files $uri = 400;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

常用的nginx管理服务命令

systemctl start nginx     #启动 nginx
systemctl stop nginx      #停止 nginx
systemctl restart nginx   #重启 nginx
systemctl enable nginx    #开机自启 nginx
systemctl disable nginx   #禁用自启 nginx

安装mysql5.7

mysql官方yum源

rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

查看5.7版本是否已经启用

yum repolist all | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community         启用:    24  #启用
mysql-connectors-community-source MySQL Connectors Community - Sourc 禁用
mysql-tools-community/x86_64      MySQL Tools Community              启用:    38  #启用
mysql-tools-community-source      MySQL Tools Community - Source     禁用
mysql-tools-preview/x86_64        MySQL Tools Preview                禁用
mysql-tools-preview-source        MySQL Tools Preview - Source       禁用
mysql55-community/x86_64          MySQL 5.5 Community Server         禁用
mysql55-community-source          MySQL 5.5 Community Server - Sourc 禁用
mysql56-community/x86_64          MySQL 5.6 Community Server         禁用
mysql56-community-source          MySQL 5.6 Community Server - Sourc 禁用
mysql57-community/x86_64          MySQL 5.7 Community Server         启用:   146  #这里是已经启用了
mysql57-community-source          MySQL 5.7 Community Server - Sourc 禁用
mysql80-community/x86_64          MySQL 8.0 Community Server         禁用
mysql80-community-source          MySQL 8.0 Community Server - Sourc 禁用

如果没有启用的话,我们可以修改源文件

vim /etc/yum.repos.d/mysql-community.repo

把5.7版本的enabled改为1就可以了,其他的版本改为0

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

修改完成之后查看可用的版本 如下面所示,表示已启用

yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                  24
mysql-tools-community/x86_64      MySQL Tools Community                       38
mysql57-community/x86_64          MySQL 5.7 Community Server                 146

看到5.7版本启用了之后就可以安装mysql了

yum -y install mysql-community-server

常用的mysql管理服务命令

systemctl start mysqld     #启动 mysql
systemctl stop mysqld      #停止 mysql
systemctl restart mysqld   #重启 mysql
systemctl enable mysqld    #开机自启 mysql
systemctl disable mysqld   #禁用自启 mysql

查看默认生成的密码

grep 'temporary password' /var/log/mysqld.log

进入mysql并修改root密码

mysql -uroot -p
ALTER  USER  'root'@'localhost'  IDENTIFIED  BY  '你的新密码';  #密码要符合定义好的密码策略

修改密码策略

vim /etc/my.cnf
# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
validate_password_policy=0

修改默认编码

vim /etc/my.cnf
character_set_server=utf8
init_connect='SET NAMES utf8'

安装php7.2和php-fpm

配置yum源

yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum搜索源

yum search php72

安装php7.2和一些扩展

yum install -y php72w php72w-cli php72w-fpm

安装一些需要的php扩展,以gd库 mysql为例(https://webtatic.com/packages/php72/)

yum install -y php72w-gd php72w-mysql............

常用的php-fpm管理服务命令

systemctl start php-fpm      #启动 PHP-FPM
systemctl stop php-fpm       #停止 PHP-FPM
systemctl restart php-fpm    #重启 PHP-FPM
systemctl enable php-fpm     #开机自启PHP-FPM
systemctl disable php-fpm    #禁用自启PHP-FPM

原文地址:https://www.cnblogs.com/L-ran/p/11883039.html