centos7搭建apache服务器(如何配置centos7下的apache服务)

您好,想请教下怎么在 linux(centos 7)中配置安装apache服务器

安装Apache

yum install httpd #根据提示,输入Y安装即可成功安装

systemctl start httpd.service #启动apache

systemctl stop httpd.service #停止apache

systemctl restart httpd.service #重启apache

systemctl enable httpd.service #设置apache开机启动

在客户端浏览器中打开服务器IP地址,会出现下面的界面,说明apache安装成功

如何在CentOS 7.3上安装Apache,PHP 7.1和M6767ySQL

1初步说明

在本教程中,我使用IP地址为192.168.1.100的hostname server1.example.com 。 这些设置可能会有所不同,因此您必须在适当的情况下更换它们。

我会在这里添加EPEL repo来安装最新的phpMyAdmin,如下所示:

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*

yum -y install epel-release

要在shell上编辑文件,我将安装nano编辑器。 如果您喜欢vi进行文件编辑,请跳过此步骤。

yum -y install nano

2安装MySQL / MariaDB

MariaDB是原始MySQL开发人员Monty Widenius的MySQL分支。  MariaDB与MySQL兼容,我选择使用MariaDB而不是MySQL。 运行此命令以安装MariaDB:

yum -y install mariadb-server mariadb

然后,我们为MySQL创建系统启动链接(以便每当系统启动时,MySQL自动启动)并启动MySQL服务器:

systemctl start mariadb.service

systemctl enable mariadb.service

设置MySQL根帐户的密码:

mysql_secure_installation

[root@server1 ~]# mysql_secure_installation

/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

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.

Enter current password for root (enter for none): --ENTER

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

Set root password? [Y/n]

New password: --yourmariadbpassword

Re-enter new password: --yourmariadbpassword

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] --ENTER

... Success!

Normally, root should only be allowed to connect from \'localhost\'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] --ENTER

... 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.

Remove test database and access to it? [Y/n] --ENTER

- 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] --ENTER

... Success!

Cleaning up...

All done!  If you\'ve completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

[root@server1 ~]#

3安装Apache

CentOS 7附带apache 2.4。  Apache可以直接作为CentOS 7软件包使用,因此我们可以这样安装:

yum -y install httpd

这里是安装过程的截图。

现在配置您的系统启动Apache启动时...

systemctl start httpd.service

systemctl enable httpd.service

为了能够从外部访问Web服务器,我们必须打开防火墙中的HTTP(80)和HTTPS(443)端口。  CentOS上的默认防火墙是firewalld,可以使用firewalld-cmd命令配置。

firewall-cmd --permanent --zone=public --add-service=http

firewall-cmd --permanent --zone=public --add-service=https

firewall-cmd --reload

现在将您的浏览器指向服务器的IP地址,在我的情况下为 ,您应该看到Apache占位符页面:

4安装PHP

CentOS附带的PHP版本相当旧(PHP 5.4),因此,我将在此步骤中显示一些选项,从Remi存储库安装更新的PHP版本,如PHP 7.0或7.1。

添加Remi CentOS存储库。

rpm -Uvh 

安装yum-utils,因为我们需要yum-config-manager实用程序。

yum -y install yum-utils

并运行yum更新

yum update

现在您必须选择要在服务器上使用哪个PHP版本。 如果你喜欢使用PHP 5.4,那么继续下一个命令。 要安装PHP 7.0,请遵循第4.1章和PHP 7.1中的命令,使用第4.2章。

要安装PHP 5.4,请运行以下命令:

yum -y install php

4.1安装PHP 7.0(可选)

我们可以安装PHP 7.0和Apache PHP 7.0模块,如下所示:

yum-config-manager --enable remi-php70

yum -y install php php-opcache

4.2安装PHP 7.1(可选)

如果要使用PHP 7.1,请使用:

yum-config-manager --enable remi-php71

yum -y install php php-opcache

在这个例子中,在可下载的虚拟机中,我将使用PHP 7.1。

我们必须重新启动Apache来应用更改:

systemctl restart httpd.service

5测试PHP /获取有关您的PHP安装的详细信息

默认网站的文档根目录是/ var / www / html。 我们将在该目录中创建一个小型的PHP文件(info.php),并在浏览器中调用它来测试PHP安装。 该文件将显示有关我们的PHP安装的许多有用的细节,例如安装的PHP版本。

nano /var/www/html/info.php

?php

phpinfo();?

现在我们在浏览器中调用该文件(例如 ):

如您所见,PHP 7.1正在工作,它正在通过Apache 2.0处理程序,如Server API行所示。 如果您进一步向下滚动,您将看到在PHP中已启用的所有模块。  MySQL没有列出,这意味着我们还没有在PHP中支持MySQL。

6在PHP中获取MySQL支持

要在PHP中获得MySQL支持,我们可以安装php71w-mysql包。 安装一些其他PHP模块是一个好主意,也可能需要它们用于应用程序。 您可以搜索可用的PHP5模块,如下所示:

yum search php

选择您需要的并安装它们:

yum -y install php-mysql

在下一步中,我将安装一些常见的PHP模块,CMS系统如Wordpress,Joomla和Drupal所需:

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-devel

现在重新启动Apache Web服务器:

systemctl restart httpd.service

现在在您的浏览器中重新加载并再次向下滚动到模块部分。 你现在应该找到很多新的模块,如Curl等。

如果您不再需要php信息输出,那么为了安全起见,请删除该文件。

rm /var/www/html/info.php

7 phpMyAdmin安装

phpMyAdmin是一个Web界面,您可以通过它来管理MySQL数据库。

phpMyAdmin现在可以安装如下:

yum -y install phpMyAdmin

现在我们配置phpMyAdmin。 我们更改Apache配置,以便phpMyAdmin不仅允许从localhost进行连接(通过注释RequireAny节并添加“要求所有已授予”行):

nano /etc/httpd/conf.d/phpMyAdmin.conf

[...]

Alias /phpMyAdmin /usr/share/phpMyAdminAlias /phpmyadmin /usr/share/phpMyAdminDirectory /usr/share/phpMyAdmin/

AddDefaultCharset UTF-8

IfModule mod_authz_core.c

# Apache 2.4

# RequireAny

# Require ip 127.0.0.1

# Require ip ::1

# /RequireAny

Require all granted

/IfModule

IfModule !mod_authz_core.c

# Apache 2.2

Order Deny,Allow

Deny from All

Allow from 127.0.0.1

Allow from ::1

/IfModule

/Directory

Directory /usr/share/phpMyAdmin/

       Options none        AllowOverride Limit

       Require all granted/Directory

[...]

接下来,我们将phpMyAdmin中的身份验证从cookie更改为http :

nano /etc/phpMyAdmin/config.inc.php

[...]$cfg[\'Servers\'][$i][\'auth_type\']     = \'http\';    // Authentication method (config, http or cookie based)?[...]

重新启动Apache:

systemctl restart  httpd.service

之后,您可以访问下的phpMyAdmin :

8作为虚拟机下载

此设置可用于以ova / ovf格式(与VMWare和Virtualbox兼容)的虚拟机下载,以了解用户的身份。

VM的登录详细信息

Linux root密码是:howtoing。

Rhe MySQL的root密码是:howtoing

请在第一次登录时更改两个密码。

虚拟机的IP地址为192.168.1.100

如何在阿里云服务器centos 7上安装Apache

你好,Linux系统安装apache的步骤很简单,可以通过yum源来安装。

命令:yum makecache 先弄一些缓存,这一步做不做也行,这我个人习惯。

然后 yum install -y httpd即可

...安装很快,apache的主配置文件在/etc/httpd/conf/httpd.conf

具体配置请参考百度相关文档博客

LAMP - CentOS7+Apache2.4+MySQL8+PHP7.3环境搭建

yum -y install epel-release

yum -y install yum-utils

yum update

yum -y install httpd

systemctl enable httpd

systemctl start httpd

firewall-cmd --permanent --zone=public --add-service=http

firewall-cmd --permanent --zone=public --add-service=https

firewall-cmd --reload

# 隐藏版本号

vim /etc/httpd/conf.d/secure.conf

TraceEnable off

ServerSignature Off

ServerTokens Prod

# 配置vhost

vim /etc/httpd/conf.d/vhosts.conf

DocumentRoot \"/var/www/html\"

ServerName example.com

ServerAlias

ErrorLog \"logs/example.com-error_log\"

CustomLog \"logs/example.com-access_log\" combined

yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

yum install certbot python2-certbot-apache

certbot --apache

systemctl restart httpd

# 安装MySQL8 YUM源

rpm -Uvh

yum install mysql-community-server

systemctl enable mysqld

systemctl start mysqld

# 查看自动生成的MySQL密码

grep \"password\" /var/log/mysqld.log

# 登录MySQL后修改密码

ALTER USER \'root\'@\'localhost\' IDENTIFIED WITH mysql_native_password BY \'新密码\';

# 刷新MySQL权限表

FLUSH PRIVILEGES;

yum-config-manager --disable remi-php54

yum-config-manager --enable remi-php73

yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-opcache php-redis php-soap

# 隐藏php版本号

vim /etc/php.ini

expose_php = off

系统参数设置

# 文件打开数设置

ulimit -n 65535

vim /etc/security/limits.d/nofile.conf

* soft nofile 65535

* hard nofile 65535

# 内核网络优化

vim /etc/sysctl.conf

# 启用timewait 快速回收

net.ipv4.tcp_tw_recycle = 1

未经允许不得转载:便宜VPS网 » centos7搭建apache服务器(如何配置centos7下的apache服务)