前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS 7 安装 Nginx, PHP,MySQL 套件

CentOS 7 安装 Nginx, PHP,MySQL 套件

作者头像
hedeqiang
发布2019-12-18 11:32:55
1.9K0
发布2019-12-18 11:32:55
举报
文章被收录于专栏:LaravelCodeLaravelCode

初始化系统

设置软件源

代码语言:javascript
复制
- aliyun , remi, mysql
# 设置aliyun库
$ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# 设置 remi 库, 设置 mysql 库
$ yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

# 由于mysql 版权方面的限制, centos 7 没有内置mysql 服务器, 必须从mysql 官方进行安装
$ yum install http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  • 设置 nginx 源

源地址: nginx: Linux packages 创建 vi /etc/yum.repos.d/nginx.repo , 并且填充以下内容来安装 yum repository

代码语言:javascript
复制
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

替换 OS 为 “rhel” 或 “centos” 替换 OSRELEASE 为 5”, “6”, 或“7”

更新元数据

代码语言:javascript
复制
# 更新元数据
$ yum makecache

安装软件

常用软件和nmp 软件

代码语言:javascript
复制
# 更新系统
$ yum update

# 安装常用软件
$ yum install vim git supervisor redis

# 安装 php 基于 remi , 所以需要安装 remi 源
# 如果需要安装其他版本, 则需要将 repo=remi-php7x 
$ yum install --enablerepo=remi-php70 php php-pdo php-fpm php-mbstring php-mcrypt php-gd php-mysqli php-zip

# 安装 nginx
$ yum install nginx --enablerepo=nginx

# 安装 mysql server
$ yum install mysql-server

启动服务

代码语言:javascript
复制
# 启动服务
$ systemctl start php-fpm mysqld nginx supervisord

开机自启动

代码语言:javascript
复制
# 开机启动
$ systemctl enable php-fpm mysqld nginx supervisord

初始化数据库

启动mysql并且获取密码
代码语言:javascript
复制
$ systemctl start mysqld

# mysql 5.7 在安装完成的时候会生成一个临时密码, 我们需要找到错误日志 `/var/log/mysqld.log`来获取这个临时密码
# use below command to see the password:
$ grep 'temporary password' /var/log/mysqld.log 
[Note] A temporary password is generated for root@localhost: _ab3BAKulW?r
初始化 mysql
代码语言:javascript
复制
$ mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: ******

New password: ******

Re-enter new password: ******

The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : *

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) :  Y

Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N

... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

Success.

All done! 

设置密码的方法

代码语言:javascript
复制
$ mysql -uroot -p******
mysql> set password for 'root'@'localhost' = password('markzhao123456');
mysql> exit

软件配置

配置nginx

配置 nginx 时候的运行组
代码语言:javascript
复制
# /etc/nginx/nginx.conf
user nginx nginx;
配置nginx虚拟主机
代码语言:javascript
复制
# /etc/nginx/conf.d/default.conf

server{
    listen 80;
    # 如果这里是 IP, 则才会允许访问, 否则, 扯破牛蛋也访问不到
    server_name www.domain.com ;
    index index.php index.html index.htm default.html default.htm default.php;
    root /webdata/www/domain/public;

    # 这里注意和服务器自带不同的是
    # fastcgi_param  SCRIPT_FILENAME  /scripts/$fastcgi_script_name;
    # fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    # 会导致 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

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

    location ~ .*\.(js|css)?$ {
        expires 12h;
    }

    access_log /webdata/logs/domain_access.log;
    error_log /webdata/logs/domain_error.log;
}

配置php

配置 php-fpm
代码语言:javascript
复制
# /etc/php-fpm.d/www.conf
user = nginx
group = nginx
配置 php.ini
代码语言:javascript
复制
# 时区
date.timezone = Asia/Shanghai
配置 session 是可写状态
代码语言:javascript
复制
$ chown -R nginx:nginx /var/lib/php/session/
配置系统允许访问
代码语言:javascript
复制
# 配置 http
$ firewall-cmd --permanent --zone=public --add-service=http
# 配置 3306
$ firewall-cmd --permanent --zone=public --add-port=3306/tcp
# 重启 防火墙
$ firewall-cmd --reload
配置数据库用户
代码语言:javascript
复制
CREATE USER 'remote'@'%' IDENTIFIED WITH mysql_native_password AS 'U*OSy)iKk$XO9dMB';
GRANT ALL PRIVILEGES ON *.* TO 'remote'@'%' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
GRANT ALL PRIVILEGES ON `1dailian\_v2`.* TO 'remote'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES

补充

下载安装 MySQL

获取最新下载地址: http://dev.mysql.com/downloads/mysql/

下载地址: http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.13-1.el7.i686.rpm http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.13-1.el7.i686.rpm

代码语言:javascript
复制
# 下载
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.13-1.el7.i686.rpm
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.13-1.el7.i686.rpm

# 安装
yum localinstall mysql-community-client**.rpm
yum localinstall mysql-community-server**.rpm

参考文章

转载自 https://juejin.im/post/5c876968e51d454170785745

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 初始化系统
    • 设置软件源
      • 更新元数据
      • 安装软件
        • 常用软件和nmp 软件
          • 启动服务
            • 开机自启动
              • 初始化数据库
                • 启动mysql并且获取密码
                • 初始化 mysql
            • 软件配置
              • 配置nginx
                • 配置 nginx 时候的运行组
                • 配置nginx虚拟主机
              • 配置php
                • 配置 php-fpm
                • 配置 php.ini
                • 配置 session 是可写状态
                • 配置系统允许访问
                • 配置数据库用户
            • 补充
              • 下载安装 MySQL
              • 参考文章
              相关产品与服务
              云数据库 SQL Server
              腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档