ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

第15页 CentOS系统手动部署LAMP平台

2022-01-24 23:32:17  阅读:192  来源: 互联网

标签:httpd 15 CentOS 命令 LAMP mysql php 安装 输入


目录

1 LAMP平台简介

  1. LAMP平台是Linux、Apache(http)、MySQL、PHP组合的简称。
  2. 在这个组合平台上,各成员主要发挥以下作用:
    1. Linux是一个操作系统,没有操作系统apache,mysql,php就缺少了基础平台;
    2. apache是一个服务器软件,我们通过浏览器发送的请求都由它来转发处理,就是启到承上启下的作用;
    3. php就是用来接收apache发送来的请求,同时也起到读写数据库数据的功能。
    4. mysql主要就是用来存储数据,如果你的网页是静态页,当然不用mysql也是可以的。

2 LAMP平台安装

2.1 Linux安装

参考本专栏上一节《CentOS7虚拟机安装及界面图形化》内容。

2.2 Apache安装

2.2.1 安装前准备

  1. 打开终端,并使用命令sudo-i切换至root用户。
  2. 查询系统是否已安装过Apache。因为在Linux系统中,不同方式安装的软件其查询命令不一致,建议使用以下命名查询系统中是否已安装过Apache,在该系统中名称是httpd。查询结果如图所示,均查不到内容。
    • rpm -qa | grep httpd
    • yum list installed | grep httpd
      在这里插入图片描述

2.2.2 安装及检查

  1. 输入yum install httpd* -y用这个命令来安装apache。
    在这里插入图片描述
  2. 需要一小会的等待……提示安装完完毕。在这里插入图片描述
  3. 输入命令systemctl start httpd.service启动Apache,并输入命令systemctl status httpd.service查看启动后的状态。看到已成功启动。
    在这里插入图片描述
  4. 输入命令ss -antpl | grep 80查看是否已开启80端口,发现已正常开启。
    在这里插入图片描述
  5. 打开浏览器,输入IP地址访问网站,成功访问说明apache已安装完成。
    在这里插入图片描述

2.2.3 主页设计

  1. 默认主页目录为/var/www/html,编辑默认主页vim /var/www/html/index.html。按ins键插入模式下输入以下命名,按Esc键回到命令模式,按:进入末行模式,输入wq保存并退出。
    在这里插入图片描述
  2. 尝试访问主页。在浏览器输入IP地址进行访问,可以看到访问成功。在这里插入图片描述
  3. 有的版本访问失败可能是防火墙拦截的原因,可以使用命令setenforce 0关闭防火墙。

2.2.4 配置文件分析

  1. 配置文件使用命令 vim /etc/httpd/conf/httpd.conf打开编辑。要是编辑后的文件生效,需要重启以下服务。
  2. 配置文件规定了服务的根目录,也就是软件装在哪,其他子目录均在此根目录下展开。
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used.  If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
ServerRoot "/etc/httpd"
  1. 配置文件规定了服务端口号为80.
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80
  1. 配置文件说明了服务使用的用户身份。
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User apache
Group apache
  1. 配置文件说明了网站主页存放的目录,同时也有对目录中各种功能使用说明。
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"
  1. 配置文件对网站的访问权限进行了说明。
# Relax access to content within /var/www.
#
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
  1. 配置文件对主页下文件的功能进行了规定,如是否共享、访问权限等。
# Further relax access to the default document root:
<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

2.3 MySQL安装

2.3.1 安装前准备

  1. 打开终端,并使用命令sudo-i切换至root用户。
  2. 查询系统是否已安装过MySQL。因为在Linux系统中,不同方式安装的软件其查询命令不一致,建议使用以下命名查询系统中是否已安装过mysql。查询结果如图所示,均查不到内容。
    • rpm -qa | grep mysql
    • yum list installed | grep mysql

2.3.2 安装及检查

  1. 输入yum install mysql-server -y用这个命令来安装MySQL。这里执行安装命令是无效的,因为centos-7默认是Mariadb,所以执行该命令只是更新Mariadb数据库
  2. 打开网站http://repo.mysql.com/查询MySQL都有哪些软件版本,找到el7后缀的,表示支持的是CentOS7的版本,此处可以根据自己需要下载对应的版本。
    在这里插入图片描述
  3. 本节内容以安装最新版为例,在终端输入命令wget http://repo.mysql.com/mysql80-community-release-el7.rpm下载最新版mysql。
  4. 输入命令rpm -ivh mysql80-community-release-el7.rpm进行安装。安装后会获得两个mysql的yum repo源,输入命令cd /etc/yum.repos.d/进行查看。在这里插入图片描述
  5. 输入命令 yum install mysql-server --nogpgcheck开始安装,其中 --nogpgcheck 表示进行跳过公钥检查安装,否则会报错。在安装过程中会多次询问输入,均输入y并回车。
    在这里插入图片描述
  6. 等待一段时间的安装后,看到令人愉快的完毕字样。
    在这里插入图片描述
  7. 输入systemctl start mysqld.service 启动服务。

2.3.3 登录并修改密码

  1. 从mysql5.6开始就不支持空密码登录了,安装时会在自动生成一个随机的初始密码,这个密码可以输入命令:cat /var/log/mysqld.log,在该日志文件中查找,比如在本次安装中,log文件第四行,就说了生成了一个临时密码为frc?h9SrPtIq。
2022-01-24T08:20:12.790955Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 12665
2022-01-24T08:20:12.825559Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-24T08:20:13.309612Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-24T08:20:14.519212Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: frc?h9SrPtIq
2022-01-24T08:20:16.647145Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 12712
2022-01-24T08:20:16.665299Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-24T08:20:16.951166Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-24T08:20:17.327996Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-01-24T08:20:17.328057Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-01-24T08:20:17.726155Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-01-24T08:20:17.726208Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.28'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.
  1. 输入mysql -u root -p"回车,输入上述临时密码登录数据库。
    在这里插入图片描述
  2. 输入alter user'root'@'localhost' IDENTIFIED BY '新密码'; 新密码要包含大小写、特殊字符、数字、长度位数等要求,例如123456.comCOM,不然会提示不满足复杂度。输入密码时注意要以分号结尾。
    在这里插入图片描述
  3. 输入\q退出,使用新密码再次尝试登录。

2.4 php安装

2.4.1 安装前准备

  1. 打开终端,并使用命令sudo-i切换至root用户。
  2. 查询系统是否已安装过Aphp。因为在Linux系统中,不同方式安装的软件其查询命令不一致,建议使用以下命名查询系统中是否已安装过php。查询结果如图所示,均查不到内容。
    • rpm -qa | grep php
    • yum list installed | grep php

2.4.2 安装及检查

  1. 输入命令yum install php开始安装php。
    在这里插入图片描述
  2. 安装过程中会有多次提示,输入y。
    在这里插入图片描述
  3. 经过一小会的等待……php安装完成。
    在这里插入图片描述

2.4.3 安装插件php-mysql

  1. 考虑到在该平台使用时,php需要起到连接数据库的作用,还需要安装插件。输入命令yum install php-mysql进行安装。
  2. 跟安装php同理,安装过程中有提示则输入y,知道安装完成。
    在这里插入图片描述

2.4.4 安装插件php-mbstring

  1. 多国语言并存就意味着多字节,PHP内置的字符串长度函数strlen无法正确处理中文字符串,它得到的只是字符串所占的字节数。对于GB2312的中文编码,strlen得到的值是汉字个数的2倍,而对于UTF-8编码的中文,就是1~3倍的差异了。
  2. 输入命令yum install php-mbstring进行安装,同理地,安装过程有提示时输入y。

2.4.5 php配置

  1. 输入命令vim /etc/php.ini进行PHP配置短标记功能,在命令模式下输入/short进行关键字查找,如下图。
    在这里插入图片描述
  2. 按ins键进入插入模式,将short_open_tag值从Off该为On,保存退出。

3 测试Apache是否支持PHP解析

  1. 输入命令vim /var/www/html/index.php在默认网站目录下新建一个网页。
  2. 进入插入模式下,按下图输入命令,注意有分号,保存并退出。
    在这里插入图片描述
  3. 在浏览器中输入192.168.1.2/index.php测试Apache能否成功解析PHP,自行使用自己的IP地址。看到一片空白,出了问题。
  4. 将index.php文件的语句修改成如下这版,可以解决问题,应该是编辑语言和软件版本的问题,而不是Apache配置文件的问题。
    在这里插入图片描述
  5. 在浏览器中输入192.168.1.2/index.php测试看到以下界面,说明LAMP平台搭建成功。
    在这里插入图片描述

4 总结

  1. 了解LAMP平台中各个软件的主要作用;
  2. 了解各软件的安装方式;
  3. 了解配置文件的内容。

5 参考文献

  1. Linux(centos 7)系统下mysql8及以上版本修改root账户密码
  2. linux++php无法解析,怎么解决linux php无法解析的问题

标签:httpd,15,CentOS,命令,LAMP,mysql,php,安装,输入
来源: https://blog.csdn.net/Fighting_hawk/article/details/122664043

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有