安装Apache web服务器

执行以下命令:

$ sudo apt install apache2

查看服务器的IP地址:

$ ifconfig eth0
$ ip a show eth0
$ ip a show eth0 | grep -w inet

使用浏览器打开

http://服务器ip

现在Apache HTTP服务器已成功安装在服务器上。

默认页面index.html位于/var/www/html/目录中:

$ sudo vi /var/www/html/index.html

如何停止/启动/重启/重新加载Apache HTTP服务器?

语法如下:

$ sudo systemctl {start|stop|restart|reload|status|graceful-stop|force-reload} apache2

Debian停止Apache 2服务器:

$ sudo systemctl stop apache2

Debian启动Apache 2服务器:

$ sudo systemctl start apache2

Debian重启Apache 2服务器:

$ sudo systemctl restart apache2

Debian重新加载Apache 2服务器:

$ sudo systemctl reload apache2

Debian查看Apache 2服务器的状态:

$ sudo systemctl status apache2

如何更改Apache HTTP服务器的配置?

需要编辑/etc/apache2 /目录中的文件:

$ cd /etc/apache2/
$ ls -l

需要在/etc/apache2/conf-available /目录中编辑或添加新的配置文件。
这是默认的配置文件:

$ cat /etc/apache2/sites-enabled/000-default.conf

输出示例:

<VirtualHost *:80>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	#ServerName www.example.com
 
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
 
	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn
 
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
 
	# For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, it is possible to
	# include a line for only one particular virtual host. For example the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
 
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
如何在Debian 9 Stretch上安装Linux,Apache,MySQL,PHP(LAMP)

如何在Debian 9(Stretch)上安装LAMP技术栈?

LAMP是四个经常用于开发Web应用程序的开源软件的缩写:

  • Linux操作系统
  • Apache Web服务器
  • MySQL/MariaDB关系数据库管理系统(RDBMS)
  • PHP服务器端编程语言

应用系统补丁

执行以下apt-get命令/apt命令以更新系统:

$ sudo apt update

要将其修补为最新更新:

$ sudo apt-get upgrade

安装MariaDB服务器

MariaDB可替代MySQL服务器。它是世界上最受欢迎的数据库服务器之一。
它由MySQL的原始开发人员制作,并保证保持开源。
要安装MariaDB服务器:

$ sudo apt install default-mysql-server

或者

$ sudo apt install mariadb-server

如何保护MariaDB mysql服务器?

执行以下命令:

$ sudo mysql_secure_installation

请注意,MariaDB/mysql root帐户和系统root帐户是两个不同的帐户。因此,请确保设置不同的密码。

如何测试MariaDB安装?

执行以下命令:

$ mysql -u root -p

您将看到MariaDB mysql提示符。您可以执行sql命令来查看数据库,版本等:

MariaDB [(none)]> show databases;
MariaDB [(none)]> exit

安装PHP版本7

与PHP 5.6相比,PHP版本7至少快30-50%。因此,让我们在Debian 9服务器上安装PHP版本7和php模块:

$ sudo apt install php7.0 libapache2-mod-php7.0 php7.0-mysql php7.0-gd php7.0-opcache

这将安装:

  • 适用于Apache 2的PHP版本7
  • PHP 7 MySQL连接模块
  • PHP 7 OpCache模块可加速脚本
  • PHP 7 GD图形模块

可以使用下面的语法搜索和安装其他PHP模块:

## [search php7 modules] ##
$ apt-cache search php7 | grep module
$ apt search php7 | grep mysql
$ apt-cache search php7 | egrep 'mysql|gd|zip'
$ apt-cache search php7 | more
$ apt search php7 | more
## [search php7 modules] ##
$ sudo apt install {module-name-here}

最后,重启Apache 2 HTTP服务器:

$ sudo systemctl restart apache2

测试PHP的安装

在/var/www/html /目录中创建一个php脚本文件:

$ sudo vi /var/www/html/test.php

代码如下:

<?php phpinfo(); ?>

在浏览器中打开,将会看到PHP的有关配置信息:

http://服务器ip/test.php

配置防火墙

执行以下命令来安装ufw防火墙:

$ sudo apt install ufw

打开SSH端口22:

$ sudo ufw allow 22
`Rules updated Rules updated (v6)`

打开端口80(HTTP)和443(HTTPS)

$ sudo ufw allow 80
$ sudo ufw allow 443

设置防火墙开机启动

$ sudo ufw enable

查看防火墙规则:

$ sudo ufw status verbose
日期:2020-03-23 08:03:57 来源:oir作者:oir