如何在 Ubuntu 18.04 上安装 LAMP 堆栈

LAMP 堆栈代表 Linux, Apache、MySQL 和 PHP – 安装在您的服务器上的一组开源软件,用于托管动态网站和应用程序。 LAMP 堆栈的每个组件都有不同的用途:

  • Linux 用作操作系统。
  • Apache 是网络服务器。
  • MySQL用于数据库存储和管理。
  • PHP 用于处理网站的动态内容。

虽然存在其他技术堆栈,但本文将指导您了解如何在 Ubuntu 18.04 系统上安装 LAMP 堆栈。

要求

要遵循并完成本教程,您将需要以下内容:

  • 安装了 Ubuntu 18.04 的系统。
  • 一个非根, sudo-启用的用户帐户。
  • 已配置的防火墙(通常在 Ubuntu 安装中默认设置)。

注意:在您的系统上安装 Ubuntu 18.04 之前,请确保至少有 25 GB 的可用存储空间。 最小安装的最低要求是 5 GB。 此外,建议您在继续安装或升级操作系统之前备份您的数据。

第 1 步:安装 Linux

安装 Ubuntu 18.04 在您的服务器上。

初始服务器设置

安装 Ubuntu 18.04 后,在准备好在 Ubuntu 系统上安装 LAMP 堆栈之前,还需要执行一些额外的步骤。

创建新用户

以 root 用户身份登录系统后,可以使用以下命令创建新用户。 在这个 example,新用户的名字是 john。

# adduser john

系统将提示您输入新创建帐户的密码以及一些可以通过按跳过的详细信息 Enter. 确保使用强密码,不要使用您可能在另一个帐户上使用过的相同密码。

root@ubuntu:~# adduser john
Adding user `john' ...
Adding new group `john' (1000) ...
Adding new user `john' (1000) with group `john' ...
Creating home directory `/home/john' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for john
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y

授予根权限

当您考虑 Linux 系统上的 root 权限时,请考虑 Windows 操作系统上的管理权限。 授予新用户 root 权限允许他们执行管理任务,例如编辑配置文件或重新启动系统,而无需注销并以 root 用户身份重新登录。

向您的新帐户授予 root 权限会将用户添加到 sudo 组,允许他们通过为每个命令添加前缀来以 root 身份运行命令 sudo. 将您的用户添加到 sudo 组,请使用以下命令。

# usermod -aG sudo john

这是输出。

root@ubuntu:~# usermod -aG sudo john
root@ubuntu:~# getent group sudo 
sudo:x:27:john

完成后,继续下一步安装 Apache.

第 2 步:安装 Apache

Apache 是一个免费和开源的 Web 服务器软件,适用于不同的操作系统,包括 Ubuntu 18.04。 它被广泛使用,有据可查,并且与 PHP 配合得很好。 在我们安装之前 Apache,必须更新存储库。 使用以下命令执行此操作。

# sudo apt update

如果这是第一次使用 sudo 命令,系统将提示您输入 root 密码。 一旦你输入它并点击 Enter,您将看到如下类似的输出。

john@ubuntu:/root$ sudo apt update
[sudo] password for john:
Hit:1 https://nl.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 https://nl.archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:3 https://nl.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 https://nl.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 https://nl.archive.ubuntu.com/ubuntu bionic-security/main Sources [260 kB]
Get:6 https://nl.archive.ubuntu.com/ubuntu bionic-security/universe Sources [293 kB]
Get:7 https://nl.archive.ubuntu.com/ubuntu bionic-security/restricted Sources [21.7 kB]
Get:8 https://nl.archive.ubuntu.com/ubuntu bionic-security/multiverse Sources [7,972 B]
Get:9 https://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 Packages [2,029 kB]
Get:10 https://nl.archive.ubuntu.com/ubuntu bionic-security/main i386 Packages [1,098 kB]
Get:11 https://nl.archive.ubuntu.com/ubuntu bionic-security/main Translation-en [361 kB]
Get:12 https://nl.archive.ubuntu.com/ubuntu bionic-security/restricted i386 Packages [23.2 kB]
Get:13 https://nl.archive.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [572 kB]
Get:14 https://nl.archive.ubuntu.com/ubuntu bionic-security/restricted Translation-en [77.5 kB]
Get:15 https://nl.archive.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1,166 kB]
Get:16 https://nl.archive.ubuntu.com/ubuntu bionic-security/universe i386 Packages [1,005 kB]
Get:17 https://nl.archive.ubuntu.com/ubuntu bionic-security/universe Translation-en [269 kB]
Get:18 https://nl.archive.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [20.9 kB]
Get:19 https://nl.archive.ubuntu.com/ubuntu bionic-security/multiverse i386 Packages [6,480 B]
Get:20 https://nl.archive.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [4,732 B]
Get:21 https://nl.archive.ubuntu.com/ubuntu bionic-updates/multiverse Sources [15.9 kB]
Get:22 https://nl.archive.ubuntu.com/ubuntu bionic-updates/restricted Sources [24.5 kB]
Get:23 https://nl.archive.ubuntu.com/ubuntu bionic-updates/main Sources [520 kB]
Get:24 https://nl.archive.ubuntu.com/ubuntu bionic-updates/universe Sources [470 kB]
Get:25 https://nl.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [1,403 kB]
Get:26 https://nl.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [2,374 kB]
Get:27 https://nl.archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [454 kB]
Get:28 https://nl.archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [596 kB]
Get:29 https://nl.archive.ubuntu.com/ubuntu bionic-updates/restricted i386 Packages [29.9 kB]
Get:30 https://nl.archive.ubuntu.com/ubuntu bionic-updates/restricted Translation-en [81.3 kB]
Get:31 https://nl.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1,781 kB]
Get:32 https://nl.archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1,596 kB]
Get:33 https://nl.archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [386 kB]
Get:34 https://nl.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [27.2 kB]
Get:35 https://nl.archive.ubuntu.com/ubuntu bionic-updates/multiverse i386 Packages [11.6 kB]
Get:36 https://nl.archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [6,808 B]
Get:37 https://nl.archive.ubuntu.com/ubuntu bionic-backports/main Sources [5,476 B]
Get:38 https://nl.archive.ubuntu.com/ubuntu bionic-backports/universe Sources [6,600 B]
Get:39 https://nl.archive.ubuntu.com/ubuntu bionic-backports/main i386 Packages [10.3 kB]
Get:40 https://nl.archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [10.3 kB]
Get:41 https://nl.archive.ubuntu.com/ubuntu bionic-backports/main Translation-en [4,824 B]
Get:42 https://nl.archive.ubuntu.com/ubuntu bionic-backports/universe i386 Packages [11.3 kB]
Get:43 https://nl.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [11.3 kB]
Get:44 https://nl.archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [5,772 B]
Fetched 17.3 MB in 4s (4,768 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
116 packages can be upgraded. Run 'apt list --upgradable' to see them.

更新存储库后,使用以下命令启动 Apache 安装。

# sudo apt apt install apache2

如果一切顺利,您将收到以下输出。 您必须在安装过程中确认一些选项。 Enter 出现提示时,其余的将自动完成。

john@ubuntu:/root$ sudo apt install apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 ssl-cert
Suggested packages:
  www-browser apache2-doc apache2-suexec-pristine | apache2-suexec-custom openssl-blacklist
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 ssl-cert
0 upgraded, 10 newly installed, 0 to remove and 116 not upgraded.
Need to get 1,729 kB of archives.
After this operation, 6,997 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libapr1 amd64 1.6.3-2 [90.9 kB]
Get:2 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libaprutil1 amd64 1.6.1-2 [84.4 kB]
Get:3 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-2 [10.6 kB]
Get:4 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libaprutil1-ldap amd64 1.6.1-2 [8,764 B]
Get:5 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 liblua5.2-0 amd64 5.2.4-1.1build1 [108 kB]
Get:6 https://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 apache2-bin amd64 2.4.29-1ubuntu4.21 [1,070 kB]
Get:7 https://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 apache2-utils amd64 2.4.29-1ubuntu4.21 [83.8 kB]
Get:8 https://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 apache2-data all 2.4.29-1ubuntu4.21 [160 kB]
Get:9 https://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 apache2 amd64 2.4.29-1ubuntu4.21 [95.1 kB]
Get:10 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 ssl-cert all Setting up apache2 (2.4.29-1ubuntu4.21) ...
Enabling module mpm_event.
Enabling module authz_core.
Enabling module authz_host.
Enabling module authn_core.
Enabling module auth_basic.
Enabling module access_compat.
Enabling module authn_file.
Enabling module authz_user.
Enabling module alias.
Enabling module dir.
Enabling module autoindex.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module filter.
Enabling module deflate.
Enabling module status.
Enabling module reqtimeout.
Enabling conf charset.
Enabling conf localized-error-pages.
Enabling conf other-vhosts-access-log.
Enabling conf security.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service.
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Processing triggers for systemd (237-3ubuntu10.44) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
Processing triggers for ureadahead (0.100.0-21) ...

安装完成后,验证 Apache 通过运行以下命令成功安装。

# service apache2 status

这是输出。

john@ubuntu:/root$ service apache2 status
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Sat 2022-01-29 17:07:42 CET; 4min 25s ago
 Main PID: 2161 (apache2)
    Tasks: 55 (limit: 2316)
   CGroup: /system.slice/apache2.service
           ├─2161 /usr/sbin/apache2 -k start
           ├─2163 /usr/sbin/apache2 -k start
           └─2164 /usr/sbin/apache2 -k start

您已成功安装 Apache 在您的系统上。

确保防火墙允许 HTTP 和 HTTPS 流量。 Apache 使用简单防火墙 (UFW) 代替 iptables 来管理防火墙规则。 使用以下命令验证 UFW 是否设置了配置文件 Apache.

# sudo ufw app list

在下面的输出中,我们看到了 Apache.

john@ubuntu:/root$ sudo ufw app list
Available applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH

要检查是否启用了到端口 80 和 443(HTTP 和 HTTPS)的流量,请查看完整的配置文件详细信息 Apache.

# sudo ufw app info "Apache Full"

这是输出。

john@ubuntu:/root$ sudo ufw app info "Apache Full"
Profile: Apache Full
Title: Web Server (HTTP,HTTPS)
Description: Apache v2 is the next generation of the omnipresent Apache web
server.

Ports:
  80,443/tcp

最后要做的是使用以下命令允许传入的 HTTP 和 HTTPS 流量。

# sudo ufw allow "Apache Full"

输出如下。

john@ubuntu:/root$ sudo ufw allow "Apache Full"
Rules updated
Rules updated (v6)

完成这些步骤后,通过在 Internet 浏览器中输入服务器 IP 并按 Enter. 如果您看到类似于下图的页面, Apache 正确安装,并且防火墙配置为 HTTP 和 HTTPS 流量。

H3:步骤 3:安装 MySQL

MySQL 是小型和大型应用程序的理想选择,它允许访问您将用来组织和存储信息的数据库。

要开始安装过程,我们将使用 apt install 命令。

# sudo apt install mysql-server

此命令的输出是要安装的软件包信息列表以及它们所需的磁盘空间量。

john@ubuntu:/root$ sudo apt install mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
  libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
Suggested packages:
  libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca
The following NEW packages will be installed:
  libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
  libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7
  mysql-server-core-5.7
0 upgraded, 21 newly installed, 0 to remove and 116 not upgraded.
Need to get 19.7 MB of archives.
After this operation, 156 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 mysql-common all 5.8+1.0.4 [7,308 B]
Get:2 https://nl.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libaio1 amd64 0.3.110-5ubuntu0.1 [6,476 B]
Get:3 https://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 mysql-client-core-5.7 amd64 5.7.36-0ubuntu0.18.04.1 [6,638 kB]
Get:4 https://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 mysql-client-5.7 amd64 5.7.36-0ubuntu0.18.04.1 [1,942 kB]
Get:5 https://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 mysql-server-core-5.7 amd64 5.7.36-0ubuntu0.18.04.1 [7,426 kB]
Get:6 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libevent-core-2.1-6 amd64 2.1.8-stable-4build1 [85.9 kB]
Get:7 https://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 mysql-server-5.7 amd64 5.7.36-0ubuntu0.18.04.1 [2,906 kB]
Get:8 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libhtml-tagset-perl all 3.20-3 [12.1 kB]
Get:9 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 liburi-perl all 1.73-1 [77.2 kB]
Get:10 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libhtml-parser-perl amd64 3.72-3build1 [85.9 kB]
Get:11 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libcgi-pm-perl all 4.38-1 [185 kB]
Get:12 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libfcgi-perl amd64 0.78-2build1 [32.8 kB]
Get:13 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libcgi-fast-perl all 1:2.13-1 [9,940 B]
Get:14 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libencode-locale-perl all 1.05-1 [12.3 kB]
Get:15 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libhtml-template-perl all 2.97-1 [59.0 kB]
Get:16 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libtimedate-perl all 2.3000-2 [37.5 kB]
Get:17 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libhttp-date-perl all 6.02-1 [10.4 kB]
Get:18 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libio-html-perl all 1.001-1 [14.9 kB]
Get:19 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 liblwp-mediatypes-perl all 6.02-1 [21.7 kB]
Get:20 https://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libhttp-message-perl all 6.14-1 [72.1 kB]
Get:21 https://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 mysql-server all 5.7.36-0ubuntu0.18.04.1 [9,944 B]
Fetched 19.7 MB in 2s (10.5 MB/s)
Preconfiguring packages ...

接下来,使用这个自定义的、预安装的安全脚本来处理不必要的系统威胁并锁定对数据库的访问。

# sudo mysql_secure_installation

执行时,系统会询问您是否要在数据库上放置密码保护层。 键入后 要继续并设置密码,它会提示您选择密码验证级别。

低密码设置需要八个字符的长度。 强设置需要以下内容:

  • 长度必须为八个字符。
  • 必须包含数字、混合大小写和特殊字符。
  • 它不能包括常用的字典单词。

选择完密码保护级别后,通过为 MySQL root 用户设置密码来继续安装。

注意:为 MySQL root 用户设置密码是重要的一步,因为拥有基本密码会使您的数据库面临严重的安全威胁。

之后,系统会提示对 MySQL 配置进行一些更改,以提高安全性并消除一些常见威胁。 为您的设置做出适当的选择以继续。

john@ubuntu:/root$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

使用以下命令登录 MySQL 控制台,测试 MySQL 是否正常工作。

# sudo mysql

输出如下。

john@ubuntu:~$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 10
Server version: 5.7.36-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql>

使用以下命令退出控制台。

mysql>exit

MySQL 已安装、保护并可以使用。

第 4 步:安装 PHP

PHP 是一种开源的服务器端脚本语言。 在您的服务器上安装客户端以处理您的代码并连接到您的 MySQL 数据库。 一旦 PHP 连接到您的数据库并获得所需的信息,它会将这些信息交给 Apache 向您的页面访问者显示内容。

除了 PHP 客户端本身,您还需要安装两个库:

  • libapache2-mod-php:将 PHP 集成到 Apache.
  • php-mysql:允许 PHP 连接到 MySQL 数据库。

使用以下命令安装这两个库。

# sudo apt install php libapache2-mod-php php-mysql

这是输出。

john@ubuntu:/root$ sudo apt install php libapache2-mod-php php-mysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php7.2 libsodium23 php-common php7.2 php7.2-cli php7.2-common php7.2-json php7.2-mysql php7.2-opcache
  php7.2-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php libapache2-mod-php7.2 libsodium23 php php-common php-mysql php7.2 php7.2-cli php7.2-common php7.2-json
  php7.2-mysql php7.2-opcache php7.2-readline
0 upgraded, 13 newly installed, 0 to remove and 116 not upgraded.
Need to get 4,136 kB of archives.
After this operation, 18.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Creating config file /etc/php/7.2/mods-available/pdo_mysql.ini with new version
Setting up php7.2-cli (7.2.24-0ubuntu0.18.04.10) ...
update-alternatives: using /usr/bin/php7.2 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar7.2 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar7.2 to provide /usr/bin/phar.phar (phar.phar) in auto mode

Creating config file /etc/php/7.2/cli/php.ini with new version
Setting up libapache2-mod-php7.2 (7.2.24-0ubuntu0.18.04.10) ...

Creating config file /etc/php/7.2/apache2/php.ini with new version
Module mpm_event disabled.
Enabling module mpm_prefork.
apache2_switch_mpm Switch to prefork
apache2_invoke: Enable module php7.2
Setting up php-mysql (1:7.2+60ubuntu1) ...
Setting up libapache2-mod-php (1:7.2+60ubuntu1) ...
Setting up php7.2 (7.2.24-0ubuntu0.18.04.10) ...
Setting up php (1:7.2+60ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
john@ubuntu:/root$

安装后,通过创建一个简单的 PHP 脚本来测试 PHP 是否工作,该脚本将运行 phpinfo() 函数并提供 PHP 安装的所有详细信息。 将此文件放在您的 Web 根目录中,以便您的 Web 服务器可以读取它。

# sudo vi /var/www/html/info.php

将以下文本放入文件中并保存。

<?php
phpinfo();

如果您在我们的浏览器中输入 serverIP/info.php(serverIP 应替换为您的实际服务器 IP),您将看到类似于下图的页面。

PHP 在您的服务器上按预期工作,您可以在此处查看有关 PHP 安装的所有详细信息。 我们现在可以使用以下命令删除此文件。

# sudo rm /var/www/html/info.php

您已在 Ubuntu 服务器环境中完成 LAMP 堆栈的安装。

包起来

如果您按照所有步骤操作,就可以在您的 Ubuntu 18.04 服务器上安装 LAMP 堆栈。 此安装允许您在服务器上托管动态网站和应用程序,并安装各种网络软件供您使用,包括 WordPress、Magento 等。

Liquid Web 的 VPS 主机, Cloud 专用服务器和专用服务器在部署时附带包含 LAMP 堆栈的服务器映像。 我们在核心和完全托管的服务器上提供 24/7/365 支持。 立即联系我们的销售团队以设置您的服务器。