专栏首页LaravelCodeCentOS 7 安装 Nginx, PHP,MySQL 套件

CentOS 7 安装 Nginx, PHP,MySQL 套件

初始化系统

设置软件源

- 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

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

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

更新元数据

# 更新元数据
$ yum makecache

安装软件

常用软件和nmp 软件

# 更新系统
$ 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

启动服务

# 启动服务
$ systemctl start php-fpm mysqld nginx supervisord

开机自启动

# 开机启动
$ systemctl enable php-fpm mysqld nginx supervisord

初始化数据库

启动mysql并且获取密码

$ 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

$ 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! 

设置密码的方法

$ mysql -uroot -p******
mysql> set password for 'root'@'localhost' = password('markzhao123456');
mysql> exit

软件配置

配置nginx

配置 nginx 时候的运行组

# /etc/nginx/nginx.conf
user nginx nginx;

配置nginx虚拟主机

# /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

# /etc/php-fpm.d/www.conf
user = nginx
group = nginx

配置 php.ini

# 时区
date.timezone = Asia/Shanghai

配置 session 是可写状态

$ chown -R nginx:nginx /var/lib/php/session/

配置系统允许访问

# 配置 http
$ firewall-cmd --permanent --zone=public --add-service=http
# 配置 3306
$ firewall-cmd --permanent --zone=public --add-port=3306/tcp
# 重启 防火墙
$ firewall-cmd --reload

配置数据库用户

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

# 下载
$ 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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Yii2 连接多个数据库

    日常生活中我们一个项目一个数据库就足够了,但是难免会有意外,会使用多个数据库进行读写操作。例如:从另一个数据库导入数据到现在的数据库 今天就探讨下,Yii2.0...

    hedeqiang
  • 关于Linux服务器部署laravel项目

    hedeqiang
  • Yii2.0 RESTful API 基础配置教程

    这是安装Yii2.0的首选方法。如果你还没有安装 Composer,你可以按照这里的说明进行安装。

    hedeqiang
  • react-native 自动化构建过程(ipa包)

    准备工作 1.安装xcode 2.安装cocospod 3.react-native源文件(git获取源码) 4.安装npm包管理工具 5.安装rea...

    酷走天涯
  • QT5中操作QWidgetItem下的集合元素

    Sindsun
  • QT5获取文件信息

    Sindsun
  • 2559. [NOIP2016]组合数问题

    【题目描述】 【输入格式】    从文件中读入数据。    第一行有两个整数t, k,其中t代表该测试点总共有多少组测试数据,k的意义见【问题描述】。 ...

    attack
  • Python操作Excel模块,你猜哪家强?

    导读:Python操作excel的模块简直不要太多,今天就为大家比较下各模块之间的优缺点。

    华章科技
  • P1880 石子合并

    题目描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分。 试...

    attack
  • LeetCode 139 Word Break

    ShenduCC

扫码关注云+社区

领取腾讯云代金券