前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ubuntu 18.04上安装LAMP完整过程图文详解

Ubuntu 18.04上安装LAMP完整过程图文详解

作者头像
星哥玩云
发布2022-07-19 15:47:22
1.2K0
发布2022-07-19 15:47:22
举报
文章被收录于专栏:开源部署

在这篇文章中,我将向您展示如何在Ubuntu 18.04 Server上安装LAMPLAMP代表Linux,Apache Web服务器,MySQL和PHP。

目前部署的大部分Web应用程序都部署在LAMP环境上。

这意味着Linux Web服务器安装了Apache Web Server,MySQL数据库服务器和PHP超文本预处理器,以便为基于Web的应用程序提供服务。

在这篇文章中,我将引导您完成整个过程。

确保安装并完全更新了Ubuntu Server 18.04的全新副本。

安装Apache2

首先,我们需要安装Apache 2 Web服务器

apt install apache2 -y

安装后,您可以浏览到服务器的IP地址或DNS名称,并查看Apache附带的默认网页。

默认情况下,您的所有Web内容都位于/var/www/html中。

此外,/var/www/html目录中的所有内容都需要由www-data用户和www-data组拥有,以便Apache Web Server能够读取文件。

接下来,我们将安装MySQL数据库。

安装MySQL

MySQL是一个非常强大的开源关系数据库。

运行以下命令安装MySQL。

apt install mysql-server -y

安装完成后,我们需要保护它。 运行此命令以保护MySQL。

mysql_secure_installation

这个脚本会问你几个问题。

第一个问题将要求您安装验证密码插件。

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

我通常会回答“N”这个问题,因为我知道我的密码是安全的。 如果您愿意,可以回答“Y”。

接下来,该脚本将要求您为根MySQL用户设置新密码。

New password:  Re-enter new password:

该脚本现在将要求您删除匿名用户。 回答“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

接下来,它会询问您是否要远程禁止root登录。 我们应该总是回答“Y”。

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

它会要求您删除测试数据库并访问它。 回答“Y.”

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

接下来,它会要求您重新加载权限表。 回答“Y.”

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

最后,脚本完成。

MySQL现已安装。

安装PHP

在Ubuntu 18.04上安装LAMP的最后一步是安装PHP超文本预处理器。

PHP添加了支持动态网页的服务器端网页处理。

运行以下命令以安装PHP。

apt install php -y

接下来,我们需要告诉Apache首先提供PHP页面。

打开/etc/apache2/mods-enabled/dir.conf文件并将其更改为首先列出index.php。

<IfModule mod_dir.c>         DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>

最后,我们需要重新启动Apache Web服务器。

systemctl restart apache2

测试PHP

我们应该确保PHP工作正常。

在/var/www/html中创建一个名为info.php的新文件。

使用以下内容调用info.php:

<?php phpinfo(); ?>

保存并退出该文件。

现在浏览到以下URL:

http://{your_server}/info.php

您应该看到PHP信息页面。

验证PHP正常工作后删除该文件。

rm /var/www/html/info.php

安装PHP模块

最有可能的是,当您安装基于PHP的应用程序时,它将具有PHP模块依赖性。

一个常见的PHP模块是php-curl模块。

我们可以用apt来安装这些。 只需在您需要安装的模块前面添加“php-”。

apt install php-curl

如果您在查找所需的模块时遇到问题,只需输入“apt install php”(模块的第一个字母),然后点击TAB键。

Ubuntu将为您列出所有匹配的包。

# apt install php-c php-cache-integration-tests  php-cgi                      php-common                  php-console-table php-cache-lite              php-cli                      php-composer-ca-bundle      php-constant-time php-cache-tag-interop        php-cli-prompt              php-composer-semver          php-curl php-cas                      php-codecoverage            php-composer-spdx-licenses    php-cassandra                php-codesniffer              php-console-commandline

结论

在这篇文章中,我们学习了如何在Ubuntu 18.04上安装LAMP。

我希望你喜欢这篇文章,这很有帮助。 如果是,请分享并在下面发表评论。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档