Web服务器的配置与管理(PHP)

项目场景

某企业在CentOS上搭建Web服务系统,以PHP作为网页开发环境,以MySQL为后台数据库。

基础知识

PHP

PHP原始为Personal Home Page的缩写,已经正式更名为 “PHP: Hypertext Preprocessor”(超文本预处理器)。 PHP 语言作为当今热门的网站程序开发语言,它具有成本低、速度快、可移植性好、 内置丰富的函数库等优点,因此被越来越多的企业应用于网站开发中。但随着互联网的不断更新换代,PHP语言也出现了不少问题。 主要特点: (一)开源性和免费性:由于PHP的解释器的源代码是公开的,所以安全系数较高的网站可以自己更改PHP的解释程序。另外,PHP 运行环境的使用也是免费的。 (二)快捷性:PHP是一种非常容易学习和使用的一门语言,它的语法特点类似于C语言,但又没有C语言复杂的地址操作,而且又加入了面向对象的概念,再加上它具有简洁的语法规则,使得它操作编辑非常简单,实用性很强。 (三)数据库连接的广泛性:PHP可以与很多主流的数据库建立起连接,如MySQL、ODBC、Oracle等,PHP是利用编译的不同函数与这些数据库建立起连接的,PHPLIB就是常用的为一般事务提供的基库。 (四)面向过程和面向对象并用:在PHP语言的使用中,可以分别使用面向过程和面向对象, 而且可以将PHP面向过程和面向对象两者一起混用,这是其它很多编程语言是做不到的。

参考资料:https://baike.baidu.com/item/php/9337

MySQL

MySQL是一种开放源代码的关系型数据库管理系统(RDBMS),使用最常用的数据库管理语言–结构化查询语言(SQL)进行数据库管理。 MySQL是开放源代码的,因此任何人都可以在General Public License的许可下下载并根据个性化的需要对其进行修改。 MySQL因为其速度、可靠性和适应性而备受关注。大多数人都认为在不需要事务化处理的情况下,MySQL是管理内容最好的选择。

参考资料:https://baike.baidu.com/item/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/10991669?fr=aladdin

配置实施

安装之前建议先安装配置DNS服务器(非必须,不然网址你只能用ip地址看,很丑)可以参考我以前的文章。 vim /var/named/hmx.com.zone

-

- $TTL 1D

- @ IN SOA hmx.com. 123213123.qq.com. (

- 1 ; serial

- 1D ; refresh

- 1H ; retry

- 1W ; expire

- 3H ) ; minimum

- NS dns.hmx.com.

- IN MX 5 mail.hmx.com.

- dns IN A 192.168.88.100

- www IN A 192.168.88.130 #改为自己服务器的IP地址

- ftp IN CNAME www.hmx.com.

- mail IN A 192.168.88.102

最后记得修改自己物理机的DNS服务器IP地址,不会参考DNS哪一篇。

Step 1:更换阿里云 yum 源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum update

Step 2:Apache 部分

安装Apache:

yum -y install httpd

启动Apache服务:

systemctl start httpd

检查Apache服务状态是否running:

systemctl status httpd

设置Apache服务自启动守卫:

systemctl enable httpd

此时,访问服务器的80端口,应可以看到Apache的默认页。如果不能访问,请检查防火墙设置。

开启80端口

firewall-cmd --add-port=80/tcp --permanent

firewall-cmd --reload

Apache的默认网页资源目录是/var/www/html,默认配置文件位置是/etc/httpd/conf/httpd.conf。

Step 3:MySQL 5.7 部分

参考往期文章,MySQL安装,并且修改密码。 注意有种情况就是按照我往期发的文章内容装不进去,装的时候修改秘钥最后安装的还是MySQL8.0(我遇到了,郁闷了一天,一个小小MySQL,淦) 可以尝试这个方法

vim /etc/yum.repos.d/mysql-community.repo

注意奥:#和后面的东西别写

[mysql-connectors-community]

name=MySQL Connectors Community

baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/

enabled=1

gpgcheck=1

gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

[mysql-tools-community]

name=MySQL Tools Community

baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/

enabled=1

gpgcheck=1

gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

[mysql-8.0-community]

name=MySQL 8.0 Community Server

baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-$basearch/

enabled=0 #给mysql8.0关了

gpgcheck=1

gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

#新加下面的

[mysql57-community]

name=MySQL 5.7 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022

file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

安装完成后 新增最高权限用户:实际操作中,我们不可能将root用户暴露到%域来做数据库操作,所以添加一个新用户。执行下列查询:

格式:

CREATE USER '[USERNAME]'@'%' IDENTIFIED BY '[PASSWORD]';

GRANT ALL ON *.* TO '[USERNAME]'@'%';

FLUSH PRIVILEGES;

例如:

CREATE USER 'hmx'@'%' IDENTIFIED BY '1234';

GRANT ALL ON *.* TO 'hmx'@'%';

FLUSH PRIVILEGES;

Step 4: PHP 7 部分

注意,直接yum安装PHP会安装5.4版本。如果不慎安装,请执行

yum remove php

yum remove php-fpm

yum remove php-common

然后reboot服务器,再进行后续安装。

为安装PHP 7,需要配置一下新的源:

yum install epel-release

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

(以上不一定有效先试试,如果网速还是卡的不行执行方案二) 方案二: 第一步:先更换清华源 如下:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak #复制原来的文件,防止你换错了,还有的救

vi /etc/yum.repos.d/CentOS-Base.repo #编辑基础源

写入以下内容:

# CentOS-Base.repo

#

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client. You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fall back you can try the

# remarked out baseurl= line instead.

#

#

[base]

name=CentOS-$releasever - Base

baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates

[updates]

name=CentOS-$releasever - Updates

baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras

baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever - Plus

baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus

gpgcheck=1

enabled=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#重构yum源

yum clean all

yum makecache

第二步:

安装epel库

yum -y install epel-release

安装remi库

yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

安装yum-utils

yum -y install yum-utils

开启remi库

yum-config-manager --enable remi-php72

更新一下yum库

yum -y update

安装源:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

安装PHP:

yum install -y php72w

安装PHP依赖:

yum -y install php72w-fpm

安装常用的PHP插件:

yum -y install php72w-cli php72w-common php72w-devel php72w-mbstring php72w-mysqlnd

验证

相关链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。