ubuntu18搭建详细的php环境,Ubuntu 18.04上安装LAMP完整过程图文详解

本文详细介绍了如何在Ubuntu 18.04 Server上搭建LAMP环境,包括安装Apache2、MySQL和PHP,以及配置和测试PHP功能。通过遵循步骤,用户可以成功创建一个支持动态网页的Web服务器。

在这篇文章中,我将向您展示如何在Ubuntu 18.04 Server上安装LAMP。 LAMP代表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。

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

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

systemctl restart apache2

测试PHP

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

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

保存并退出该文件。

现在浏览到以下URL:

http://{your_server}/info.php

您应该看到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 php-bcmath

php-mbstring php-pdo-mysql php-gd

安装之后要修改目录
vi /etc/apache2/sites-available/000-default.conf

结论

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安卓学习乐园

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值