云网牛站
所在位置:首页 > Linux云服务器 > Debian 10 Buster安装LAMP的方法[MariaDB 10.3+Apache 2.4+PHP 7.3]

Debian 10 Buster安装LAMP的方法[MariaDB 10.3+Apache 2.4+PHP 7.3]

2019-03-30 16:31:24作者:倍素玲稿源:云网牛站

本文介绍在Debian 10 Buster上安装和配置LAMP Stack的方法,使用MariaDB 10.3+Apache 2.4+PHP 7.3构架。此配置中使用的帐户需要sudo权限才能安装软件、编辑配置文件和管理服务。

 

一、更新Debian 10 Buster

在我们开始在Debian 10上安装LAMP Stack软件包之前,建议让存储库和软件包保持最新:

sudo apt update && sudo apt -y upgrade

 

二、安装MariaDB 10.3数据库

通过运行以下命令安装MariaDB数据库:

sudo apt install -y mariadb-server mariadb-client

安装的MariaDB版本是10.3:

$ apt policy mariadb-server

mariadb-server:

Installed: 1:10.3.13-1

Candidate: 1:10.3.13-1

Version table:

*** 1:10.3.13-1 500

500 http://httpredir.debian.org/debian buster/main amd64 Packages

100 /var/lib/dpkg/status

MariaDB数据库的服务名称是mysql或mariadb:

$ systemctl status mariadb

Debian 10 Buster安装LAMP的方法[MariaDB 10.3+Apache 2.4+PHP 7.3]

最后一步是保护数据库,这包括:设置强root密码、删除匿名用户、禁用root用户的远程登录、删除测试数据库并访问它。

运行以下命令以保护数据库:

$ sudo mysql_secure_installation

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): 

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

New password: 

Re-enter new password: 

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

… 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] Y

… 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] Y

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

… 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!

测试MariaDB数据库安装,运行mysql -u root -p命令:

Debian 10 Buster安装LAMP的方法[MariaDB 10.3+Apache 2.4+PHP 7.3]

参考:在Debian 9/Debian 8系统中安装MariaDB 10.4数据库的步骤

 

三、安装Apache Web Server 2.4.38

Debian 10官方存储库中提供了Apache Web服务器软件包,所需要的只是使用sudo执行install命令:

sudo apt install -y apache2 apache2-utils

确认Apache版本信息:

$ sudo apache2 -v

Server version: Apache/2.4.38 (Debian)

Server built: 2019-01-31T20:54:05

安装后自动启动服务:

$ systemctl status apache2

Debian 10 Buster安装LAMP的方法[MariaDB 10.3+Apache 2.4+PHP 7.3]

使用systemctl命令进行更改时,可以重新启动服务或重新加载:

sudo systemctl reload apache2

sudo systemctl enable apache2

要使服务在引导时启动,请使用:

sudo systemctl enable apache2

要查看Apache服务器完整状态,请使用apache2ctl命令:

$ sudo apt -y install elinks

$ sudo apache2ctl fullstatus

你的输出应类似于以下信息,如下图:

Debian 10 Buster安装LAMP的方法[MariaDB 10.3+Apache 2.4+PHP 7.3]

在浏览器上打开服务器IP地址以查看默认的Apache页面:

Debian 10 Buster安装LAMP的方法[MariaDB 10.3+Apache 2.4+PHP 7.3]

 

四、在Debian 10 Buster上安装PHP 7.3

现在我们已经安装了Apache和MariaDB,缺少的部分是PHP,我们将安装常用的PHP和标准扩展,Debian 10上安装的PHP版本是PHP 7.3:

sudo apt install php libapache2-mod-php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd  php-mbstring php-curl php-xml php-pear php-bcmath

启用Apache模块(如果尚未启用),然后重新启动Web服务器:

sudo a2enmod php7.3

确认PHP版本:

$ php -v

PHP 7.3.3-1 (cli) (built: Mar  7 2019 19:43:34) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.3-1, Copyright (c) 1999-2018, by Zend Technologies

创建一个php脚本来测试你的LAMP stack安装:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php

打开Debian 10服务器IP和URL地址http://[ServerIP/hostname]/phpinfo.php:

Debian 10 Buster安装LAMP的方法[MariaDB 10.3+Apache 2.4+PHP 7.3]

显示如上图后,标志着我们在Debian 10 Buster上安装LAMP Stack已经成功。

 

相关主题

使用LAMP在Debian 9 Stretch上安装NextCloud 15.0.0的步骤

精选文章
热门文章