如何在Debian 10 Buster上安装LAMP堆栈
本教程将解释如何在Debian 10 Buster Linux系统上安装Apache,MariaDB和PHP(Lamp Stack)。
灯是 - Linux,Apache,MySQL/MariaDB和PHP的首字母缩写。
灯泡堆栈不是单个包,而是一组用于电源Web应用程序和的开源工具。
每个组件可以独立使用以供应应用。
在Debian 10 Buster上安装LAMP堆栈
灯堆包括以下开源软件应用程序.
Linux - 这是托管Applications.
Apache - Apache HTTP的操作系统是一个免费和开源的跨平台Web Server.
mysql/Mariadb - 开源关系数据库管理系统。
PHP - 用于开发Web应用程序的编程/脚本语言。
我们可以在前提下使用虚拟机,在云或者专用服务器中安装和配置Debian 10操作系统上的灯泡堆栈。
此设置中使用的使用帐户需要sudo权限来安装软件,编辑配置文件和管理服务。
第1步:更新Debian 10 Buster
在我们可以在Debian 10上开始安装LAMP堆栈包之前,建议将存储库和包装保持最新。
sudo apt update && sudo apt -y upgrade
第2步:安装MariaDB数据库服务器
MariaDB是一个从MySQL分叉的关系数据库管理系统。
它是自由和开源的。
通过运行下面的命令来安装它。
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 ● mariadb.service - MariaDB 10.3.13 database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-03-29 10:31:19 UTC; 6min ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Main PID: 14616 (mysqld) Status: "Taking your SQL requests now…" Tasks: 30 (limit: 1148) Memory: 51.8M CGroup: /system.slice/mariadb.service └─14616 /usr/sbin/mysqld Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: performance_schema Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: Phase 6/7: Checking and upgrading tables Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: Running 'mysqlcheck' with connection arguments: --socket='/var/run/mysqld/mysqld.sock' --host='lo Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: # Connecting to localhost… Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: # Disconnecting from localhost… Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: Processing databases Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: information_schema Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: performance_schema Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: Phase 7/7: Running 'FLUSH PRIVILEGES' Mar 29 10:31:20 deb10 /etc/mysql/debian-start[14653]: OK
最后一步是保护数据库服务器。
这包括:设置强根Passwording匿名用户Disableding for Root User.Removing测试数据库并访问它
运行以下命令以保护数据库服务器。
$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 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 67 Server version: 10.3.13-MariaDB-1 Debian buildd-unstable Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SELECT VERSION(); +-------------------+ | VERSION() | +-------------------+ | 10.3.13-MariaDB-1 | +-------------------+ 1 row in set (0.001 sec) MariaDB [(none)]>
第3步:安装Apache Web服务器
Debian 10官方存储库上提供Apache Web Server软件包。
所需的只是使用sudo执行安装命令。
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 ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-03-29 10:56:09 UTC; 18s ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 16696 (apache2) Tasks: 55 (limit: 1148) Memory: 9.0M CGroup: /system.slice/apache2.service ├─16696 /usr/sbin/apache2 -k start ├─16698 /usr/sbin/apache2 -k start └─16699 /usr/sbin/apache2 -k start
我们可以使用systemctl命令进行更改时重新启动服务或者重新加载。
sudo systemctl reload apache2 sudo systemctl enable apache2
使服务能够在启动时启动,使用
sudo systemctl enable apache2
查看Apache服务器全部状态,使用 apache2ctl
命令。
$sudo apt -y install elinks $sudo apache2ctl fullstatus
输出应类似于下面。
打开浏览器上的服务器IP地址以查看默认的Apache页面。
第4步:在Debian 10 Buster上安装PHP
现在我们安装了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-2016 The PHP Group Zend Engine v3.3.3, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.3.3-1, Copyright (c) 1999-2016, by Zend Technologies
创建一个php脚本以测试LAMP堆栈安装。
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php
打开Debian 10 Server IP和URL: http://[ServerIP/hostname]/phpinfo.php