赞
踩
LAMP 是一个常用于构建动态网站和Web应用程序的开发堆栈,它由以下四个主要组件组成:
Linux(操作系统):LAMP 中的 "L" 代表 Linux,它是操作系统的一种选择。Linux 是一个开源的、免费的操作系统,广泛用于Web服务器环境,因为它稳定、安全且可扩展。在 LAMP 堆栈中,Linux 提供了服务器的基本操作系统框架。
Apache(Web服务器):LAMP 中的 "A" 代表 Apache,它是一个流行的开源Web服务器软件。Apache 提供了处理HTTP请求和响应的能力,它是 Web 应用程序的后端服务器,能够将请求发送给应用程序和处理应用程序生成的响应。
MySQL(数据库管理系统):LAMP 中的 "M" 代表 MySQL,它是一个开源的关系型数据库管理系统(RDBMS)。MySQL 用于存储和管理Web应用程序中的数据,例如用户信息、文章内容、产品信息等。它提供了高性能、可靠性和扩展性,适用于各种规模的Web应用程序。
PHP(服务器端脚本语言):LAMP 中的 "P" 代表 PHP,它是一种流行的服务器端脚本语言。PHP 用于编写服务器端的Web应用程序代码,它可以嵌入到HTML中,动态生成Web页面内容。PHP 具有丰富的功能和库,使开发人员能够创建动态和交互性的Web应用程序。
LAMP 堆栈提供了一个完整的Web开发环境,包括操作系统、Web服务器、数据库和服务器端脚本语言。这个堆栈被广泛用于开发各种类型的Web应用程序,从简单的个人博客到复杂的电子商务平台。
在开始搭建LAMP环境之前,你需要先做好以下前期工作:
Apache是一款强大的开源Web服务器软件,许多网站和Web应用程序都依赖于Apache作为其服务器基础,因此我们需要首先安装Apache。
sudo apt update && sudo apt install apache2 --yes && sudo ufw allow in "Apache"
上面的命令完成了三件事情:
接下来,你可以在浏览器中测试Apache是否正常运行,输入以下地址:
http://VPS_IP
需要注意的是,在这里应使用HTTP协议,而不是HTTPS,因为我们在上面的命令中只开放了80端口。例如,我这里访问的是:
http://20.243.21.117
如果你能打开,表明你已经配置成功了。
网页端访问VPS
MySQL是一种广受欢迎的关系型数据库,我们WordPress网站的各种数据都存储在MySQL中。
sudo apt install mysql-server -y && sudo mysql
执行完上面的命令,你就进入MySQL数据库了。
进入MySQL数据库
接下来我们需要设置MySQL数据库的密码,在MySQL中输入以下代码,其中PASSWORD必须替换成你自己的密码。请牢记这个密码,后面会用到。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'PASSWORD';
然后输入exit退出MySQL数据库。
执行成功后,你将返回到原来的VPS终端界面。
退出MySQL数据库
接下来初始化MySQL,输入以下命令:
sudo mysql_secure_installation
在运行该命令后,会要求你输入密码,直接输入上面设置的密码即可。然后,按照以下提示进行选择:
- VALIDATE PASSWORD COMPONENT 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 component?
-
- 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: 0
是否要重新设置root用户密码:选择N。
- Estimated strength of the password: 100
- Change the password for root ? ((Press y|Y for Yes, any other key for No) : N
- 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
- 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
- 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
- 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就安装并进行了基本配置。你将看到屏幕上显示 “All done” 字样。
首先,运行以下命令来安装PHP及相关模块:
sudo apt install php libapache2-mod-php php-mysql -y
安装完成后,你可以使用以下命令检查PHP版本:
php -v
你应该会看到类似于下面的输出,显示你的PHP版本(例如8.1.2)。
PHP版本
到这里,你已经成功安装了LAMP环境,可以准备运行或安装其他程序了。你可以继续按照我的教程《最新VPS搭建WordPress教程》安装WordPress,利用这个搭建出来的WordPress来创造更多的价值。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。