linux环境安装 CentOS7 + Apache2.4 + MySQL5.7 + PHP7

CentOS7 + Apache2.4 + MySQL5.7 + PHP7 

CentOS7

1. 创建linux 用户密码

$ useradd hoge
$ passwd hoge

   确认用户列表

$ cat /etc/passwd

   确认用户名

$ id hoge

组名=用户名,如果需要的话,组合名称适当变更(developer)

$ groupmod -n developer hoge

2. sudo设置

对创建的普通用户(hoge)给予sdo权限的给予

在visuo打开/etc/sudoers,取下以下行的注释

$ visudo

%wheel ALL=(ALL) ALL

3.将用户添加到wheel集团

$ usermod -G wheel hoge

4. su设置

只做wheel组

删除以下行的注释

$ vi /etc/pam.d/su

auth            required        pam_wheel.so use_uid

5. 变更日语

$ localectl set-locale LANG=ja_JP.UTF-8

查看编码配置
$ localectl status

   System Locale: LANG=ja_JP.UTF-8
       VC Keymap: jp106
      X11 Layout: jp

6. SELinux 停止

$ vi /etc/selinux/config

SELINUX=disabled

7. firewalld (动态防火墙)

从CenOS 7开始,防火墙的设定由“IPtables”改变为“firewald”

确认现在的设定(默认)

$ firewall-cmd --list-all

public (default, active)
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

  添加http,设定反映(想打开80号端口)

$ firewall-cmd --add-service=http --permanent

success

$ firewall-cmd --reload

success

   查看变更状态

$ firewall-cmd --list-all

public (default, active)
  interfaces: eth0
  sources:
  services: dhcpv6-client http ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

查看防火墙是否运行
$firewall-cmd --state

8. 重启服务器

shutdown -r now

定位设置

设置安装中的定位。

在CenOS中,准备了正式的定位,通常的yum命令可以使用,但是因为不保守的是最新的软件和版本更新,所以安装了提包和remi这个包装,利用各个定位中的最新软件。

1. 安装封装

$ yum install epel-release.noarch

[epel]一部分的enable = 1,换成enable = 0

$ vi /etc/yum.repos.d/epel.repo

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=0

2. remi安装

$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

[remi]一部分的enable = 1,换成enable = 0

$ vi /etc/yum.repos.d/remi.repo

[remi]
name=Remi's RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/7/remi/mirror
enabled=0

Apache2.4

1. 安装httpd服务

$ yum install httpd

2. 启动httpd服务

$ systemctl start httpd.service

※设置自动启动httpd服务

$ systemctl enable httpd.service

MySQL5.7

在CenOS 7中,有可能被默认安装了MAiaDB(MySQL兼容的DB),所以不要与MySQL发生冲突

1. 删除现有mariaDB、MySQL

$ yum remove mariadb-libs
$ yum remove mysql* 

2. 安装

※适当的URL将为最新改变

$ yum install http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
$ yum -y install mysql-community-server

3. 检查安装版本

$ mysqld --version

mysqld  Ver 5.7.15 for Linux on x86_64 (MySQL Community Server (GPL))

4. 启动

systemctl start mysqld.service

※设置自动启动

systemctl enable mysqld.service

5. root用户的初始密码

MySQL5.7在第一次启动的同时,将随机文字列的密码设定为root用户,并输出到记录。

$ cat /var/log/mysqld.log | grep 'password is generated'

201*-**-15T09:53:28.904448Z 1 [Note] A temporary password is generated for root@localhost: _aBC12#/dEF:

6. 初始化设置

运行mysql_secure_installation命令
※请注意,新路线的密码必须包含大写字母、小写字母、数字和符号

$ mysql_secure_installation

Enter password for user root: //输入在日志中输出的初始密码
Set root password? //设置root密码
Remove anonymous users? //谁都可以登录,可以删除吗?
Disallow root login remotely? //是否允许远程登录
Remove test database and access to it? //是否删除测试数据库吗?
Reload privilege tables now? //重新加载生效?
All done!

7. MySQL测试确认

$ mysql -u root -p
Enter password:

8. my.cnf 設定

mysql> SHOW VARIABLES LIKE 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

my.cnf以下设置

  • 存储引擎,将InnD数据库,数据文件、日志文件设置为每个表格
  • 文字代码在utf8中
vi /etc/my.cnf

[mysqld]
default-storage-engine=InnoDB
innodb_file_per_table

character-set-server = utf8
collation-server = utf8_general_ci

[mysql]
default-character-set = utf8 

[client]
default-character-set = utf8
mysql> SHOW VARIABLES LIKE 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.02 sec)

mysql> SHOW VARIABLES LIKE 'innodb_file_per_table';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| innodb_file_per_table | ON    |
+-----------------------+-------+
1 row in set (0.00 sec)

PHP7

1. libmcrypt

mcrypt安装时需要安装

$ yum --enablerepo=epel install libmcrypt

2. 安装

FastCGI配置安装扩展

$ yum --enablerepo=remi-php70 install -y php php-cli php-devel php-common php-mbstring php-mysql php-fpm php-gd php-mcrypt php-opcache php-pdo php-xml
$ php -v
PHP 7.0.17 (cli) (built: Mar 14 2017 15:14:30) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.17, Copyright (c) 1999-2017, by Zend Technologies

3. php.ini 设置

备份初始文件

$ cp /etc/php.ini /etc/php.ini.bk

php.ini设置以下

$ vi /etc/php.ini

[PHP]
# 不显示PHP的版本头
expose_php = Off
# 输出全部错误日志
error_reporting = E_ALL
# 不显示错误
display_errors = Off
# 开启错误日志
log_errors = On
# 设定错误日志的长度
log_errors_max_len = 4096
# 错误日志输出目的地
error_log = "/var/log/php_errors.log"
# 字符编码
default_charset = "UTF-8"

[Date]
# 设置时区
date.timezone = "Asia/Tokyo"

[mbstring]
# 默认语言
mbstring.language = Japanese
# 内部文字编码
mbstring.internal_encoding = UTF-8
# HTTP输入文字编码的默认
mbstring.http_input = auto
# 字符编码检测顺序的默认
mbstring.detect_order = auto

4. 输出确认

在文档路线中创建输出phpinfo的php文件。

※/ vay / www / html /…文档路径

$ vi /var/www/html/info.php

 
     

转载于:https://www.cnblogs.com/corper/p/9040878.html

你可能感兴趣的:(linux环境安装 CentOS7 + Apache2.4 + MySQL5.7 + PHP7)