CentOS7之apache2.4.6配置、Mysql 8.0.21安装、php5.4.16 全过程(LAMP)

目录

LAMP之Apache安装&访问控制

首先确定有没有安装httpd

关闭防火墙

关闭selinux

访问控制设定

设置仅允许192.168.43.1主机访问主页

访问这个页面需要先输入用户名,再输入密码才可以访问

LAMP之Mysql数据库安装

LAMP之php5.4.16安装


Web服务有个很有名的词: LAMP——(Linux         apache          mysql            php)

比如一个网站的发帖留言功能, 在网页提交,php将你的留言提交到数据库中,php登陆数据调用你所有的留言,将你的留言产生html语句显示到主页上。

这个对外服务需要确定IP地址和端口号(https 443,http 80)

LAMP之Apache安装&访问控制

首先确定有没有安装httpd

一般都是自带的。可以看到我这个是有的

[root@localhost ryan]# rpm -qa | grep httpd
httpd-manual-2.4.6-93.el7.centos.noarch
httpd-tools-2.4.6-93.el7.centos.x86_64
httpd-2.4.6-93.el7.centos.x86_64
httpd-devel-2.4.6-93.el7.centos.x86_64

如果没有,通过下列命令安装

yum -y install httpd*

然后启动服务

[root@localhost ryan]# systemctl start httpd.service

来验证一下80端口是不是真的开启了(ss是查看本地开启端口的命令,a代表所有,n代表数字显示numeric,t代表TCP,p代表进程号pid,l代表listening,监听状态),有了!

[root@localhost ryan]# ss -antpl | grep 80
LISTEN     0      128         :::80                      :::*                   users:(("httpd",pid=11963,fd=4),("httpd",pid=11962,fd=4),("httpd",pid=11961,fd=4),("httpd",pid=11960,fd=4),("httpd",pid=11959,fd=4),("httpd",pid=11955,fd=4))

主页建立,这个服务的主页在哪儿呢?        ——     /var/www/html

进入该目录ls发现啥也没有,于是自己新建呗.

做这个实验时候,最好把SELinux和防火墙都关上保证成功.

关闭防火墙

systemctl stop firewalld         --临时关闭防火墙 
systemctl disable firewalld      --永久关闭防火墙

关闭selinux

临时关闭:
[root@Apache ~]# setenforce 0
setenforce: SELinux is disabled

永久关闭:
[root@Apache ~]# vim /etc/selinux/config
SELINUX=disabled                 # 将enforcing改为disabled

[root@Apache ~]# reboot   --重启系统永久生效

现在验证一下刚才的主页能不能看见啊!   建立主页成功!

 关于apache主配置文件的分析. 打开主配置文件, 

gedit /etc/httpd/conf/httpd.conf

这里还有个配置, 代表是否支持文件共享, 一般关闭. 不然把你密码文件拷贝出来然后远程下载, 慢慢暴力破解

[root@localhost html]# mkdir /var/www/html/share
[root@localhost html]# pwd
/var/www/html
[root@localhost html]# cp /etc/passwd /etc/shadow /var/www/html/share/
[root@localhost html]# cd share/
[root@localhost share]# ls
passwd  shadow

 现在远程访问网页

passwd可以直接下载, 但是shadow文件由于权限问题不能下载. 启动apache的用户是程序用户apache, 这个用户没有权限看shadow. 

[root@localhost share]# ll
总用量 8
-rw-r--r--. 1 root root 2157 9月   2 10:24 passwd
----------. 1 root root 1218 9月   2 10:24 shadow

给他加个权限 . 

[root@localhost share]# chmod o+r shadow 

现在就可以下载查看shadow文件了.这次保存就不报错了, 这个共享功能怎么关闭啊?

在配置文件里注释掉这行即可

重启服务使改动生效/

[root@localhost share]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service

现在再次访问share路径_——

访问控制设定

设置仅允许192.168.43.1主机访问主页

还是在那个配置文件(参考:https://www.linuxidc.com/Linux/2019-08/160127.htm)

保存更改后重启服务使之生效。     systemctl restart httpd.service
现在访问centos的ip就会出现,

这个页面可不是访问成功,不信加index.html

 现在我又想对页面进行加密,

访问这个页面需要先输入用户名,再输入密码才可以访问

用户名和密码需要自己配置,添加用户tom,密码12321,之后查看该目录,确实有Tom用户,且该文件 apache用户有r权限、

[root@localhost share]# htpasswd -c /etc/httpd/conf/httpuser tom
New password: 
Re-type new password: 
Adding password for user tom
[root@localhost share]# cat /etc/httpd/conf/httpuser
tom:$apr1$aCU1S/MB$VGlrUoZgJuyq2PFNbPYZ8/
[root@localhost share]# ll /etc/httpd/conf/httpuser
-rw-r--r--. 1 root root 42 9月   2 14:28 /etc/httpd/conf/httpuser

对于这个密码文件,建议只有apache用户可以读,其他用户都不能。

[root@localhost share]# cd /etc/httpd/conf/
[root@localhost conf]# chmod -r httpuser
[root@localhost conf]# chmod -w httpuser
[root@localhost conf]# chmod u+r httpuser
[root@localhost conf]# chown apache httpuser
[root@localhost conf]# ll
总用量 32
-rw-r--r--. 1 root   root 11908 9月   2 14:36 httpd.conf
-r--------. 1 apache root    42 9月   2 14:28 httpuser
-rw-r--r--. 1 root   root 13064 4月   2 21:14 magic

实现该需求还需要去/etc/httpd/conf/httpd.conf配置文件里修改配置

重启服务        systemctl restart httpd.service       再次访问

正确输入后可以访问

LAMP之Mysql数据库安装

安装跟着这个来的: https://juejin.im/post/6844903870053761037#heading-5

rpm -qa|grep mariadb
rpm -e --nodeps mariadb-server
rpm -e --nodeps mariadb
rpm -e --nodeps mariadb-libs
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

最终输入             yum repolist            看到以下结果就成功了

[root@localhost httpd]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64       MySQL Connectors Community           165
mysql-tools-community/x86_64            MySQL Tools Community                115
mysql80-community/x86_64                MySQL 8.0 Community Server           193

安装mysql

sudo yum install mysql-community-server

经过了漫长的安装,启动mysql

sudo systemctl start mysqld.service

MySQL第一次启动后会创建超级管理员账号root@localhost,初始密码存储在日志文件中,将日志文件中的 tqqYI&14j4ru 用来登录账户设置正常的账户密码。

[root@localhost httpd]# sudo grep 'temporary password' /var/log/mysqld.log
2020-09-02T07:23:49.986937Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: tqqYI&14j4ru
[root@localhost httpd]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.21

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

出现这个代表密码策略不接受弱密码,要设置一个强密码。

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Qmm!1:^7^*';
Query OK, 0 rows affected (0.01 sec)

LAMP之php5.4.16安装

参考: https://www.jianshu.com/p/8d42fe65170c

安装php

yum install php php-devel

重启apache使php生效

/bin/systemctl start httpd.service

修改/etc/php.ini,使得apache可以解析php

此时可以在目录:/var/www/html/下建立一个PHP文件index.php,加入代码:

<?php phpinfo(); ?>

访问发现没有权限读取此文件,于是查看权限,发现apache用户没有r,于是授权

chmod o+r index.php

我的php版本是    PHP 5.4.16 (cli)        ,现在开始了漫长的排错之路。

主要做的就是修改配置文件,还安装了挺多乱七八糟的模块,php-fpm。。。

修改apache配置文件
vim /usr/local/apache24/bin/conf/httpd.conf
  1、在LoadModule后面添加:LoadModule php5_module modules/libphp5.so         //不添加则访问.php文件将会变成下载
  2、在DirectoryIndex后面添加:index.php
  3、在AddType application/x-gzip .gz .tgz后面添加:AddType application/x-httpd-php .php   //.php前面有一个空格

重启apache服务

systemctl restart httpd.service

再次访问,成功!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值