CentOS7 安装 Apache PHP MariaDB FTP

CentOS7 安装 Apache PHP MariaDB FTP

本教程需要一些 vi 的基础知识,因为所有修改配置文件的操作都是在 vi 文本编辑器中进行的,需要会 搜索 修改 插入 复制 保存 覆盖 等基本操作
vi编辑器的基础和高级知识,请点击这里

CentOS 7 之后,操作服务不再用 service xxx start|stop|restart了,而用 systemctl start|stop|restart|status xxx


vsftp

  1. 配置目录 /etc/vsftpd/
  2. 取消匿名登录
  3. 如果你想用root登录,需要将 root 用户从 user_list ftpusers 两个文件中去掉,以允许 root 用户登录。
  4. 新建 ftp 用户 ftpuser
useradd ftpuser

修改密码

passwd ftpuser

apache

  1. 配置目录 /etc/httpd/conf/
  2. 安装
yum install httpd
  1. 配置 /etc/httpd/conf/httpd.conf 修改admin自己邮箱,修改首文件 index.php(因为我用php作为后台支持
DirectoryIndex index.php index.html

mariaDB

关于 mariaDB 与 Mysql 什么关系, 可以点击这里查看

  1. 安装
yum install mariadb mariadb-server
  1. 启动 MariaDB
systemctl start mariadb
  1. 初始化数据库
mysql_secure_installation

下面是一个很友好的安装指导过程:

[root@host html]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
# 为了安全的登录 MariaDB,我们需要纠正一下root用户的密码,如果你是第一次安装,那么root的密码是空,可以直接回车确定。

Enter current password for root (enter for none): 
# 输入现在的 root 密码(也就是空):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
# 设置root密码

Set root password? [Y/n] y
# 设置root密码?
New password: 
# 新密码:
Re-enter new password: 
# 重新输入密码:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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.
# 一般来说,root用户应该允许在本地登录,以免有人会恶意猜测root密码并强行破解。

Disallow root login remotely? [Y/n] y
# 是否禁止root用户远程登录?
 ... Success!

By default, MariaDB 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.
# 默认情况下,Maria数据库会随机带着一个 test 的数据库,意图是为了测试用,该库任何人都可以进入,你也应该在产品上架之前移除这个数据库。

Remove test database and access to it? [Y/n] y
# 是否移除 test 数据库?
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
# 重新加载授权列表,来使之生效。

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
# 全部完成了,如果你完成了上面的步骤,你的 MariaDB 现在应该是很安全的了。

Thanks for using MariaDB!
# 感谢使用 MariaDB
  1. 添加用户 kyle
    mysql.user 列表中添加用户 kyle

先进入数据库

mysql -uroot -p
insert into mysql.user(host,user,password) values("localhost","用户名",password("密码"))

允许远程登录(不然没法远程登录)

GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;

如果遇到本地能正常登录,远程无法连接的问题,看这里
https://blog.csdn.net/KimBing/article/details/91414752


PHP

  1. 给 yum 添加 php 源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

如果提示错误

Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.T2KjDq: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
error: Failed dependencies:
        epel-release >= 7 is needed by webtatic-release-7-3.noarch

需要安装 epel-release

yum -y install epel-release 
  1. 安装
yum install php71w
  1. 安装需要的扩展
yum install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-fpm php71w-gd php71w-mbstring php71w-mysqlnd php71w-opcache php71w-pdo php71w-xml
  1. php -v 会有这样的信息
[root@host /]# php -v
PHP 7.1.26 (cli) (built: Jan 12 2019 09:59:05) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.26, Copyright (c) 1999-2018, by Zend Technologies

如果没有,或者错误安装了 5.4.16 版的php,需要完全卸载才能继续安装

# 查看所有的包名
rpm -qa | grep php

# 卸载相关的包,这后面写的内容根据上面显示的写
rpm -e php-cli php-common
  1. 添加 apache 与 php 的关联:
    目录切到 /etc/httpd/modules 看看里面有哪些 php 文件,会看到下面的结果

ll | grep php

-rwxr-xr-x 1 root root 4943032 Jan 12 18:10 libphp7-zts.so
-rwxr-xr-x 1 root root 4745568 Jan 12 18:10 libphp7.so

然后在 /etc/httpd/conf/httpd.conf 文件末尾添加如下内容:(后面的文件名根据自己上面列出的实际情况加)

LoadModule php7_module /etc/httpd/modules/libphp7-zts.so
LoadModule php7_module /etc/httpd/modules/libphp7.so
  1. 重启 apache 使更改生效
systemctl restart httpd

回到系统中,开机自动启动

systemctl enable httpd
systemctl enable mariadb
systemctl enable vsftpd

你可能感兴趣的:(Linux)