在 DigitalOcean Ubuntu 20.04 上安装配置 LAMP 环境,首先需要更新系统软件包,然后依次安装 Apache 网页服务器、MySQL 数据库和 PHP 脚本语言。安装完成后,需配置防火墙允许 HTTP 流量,运行 mysql_secure_installation 加固数据库安全,并启用 PHP 模块以便 Apache 处理动态内容。最后可通过浏览器访问服务器 IP 验证 Apache 是否正常运行,确保整个栈协同工作以支持动态网站部署。
How To Install WordPress on Ubuntu 20.04 with a LAMP Stack | DigitalOcean
Introduction WordPress is an extremely popular open-source technology for making websites and blogs on the internet today. Used by 63% of all websites that use a content management system (CMS), WordPress sites represent 36% of all websites that are currently online. There are many different approaches to getting access to WordPress and some setup processes are more complex than others. This tutorial is intended for those who desire to install and administer a Wordpress instance on an unmanaged cloud server via the command line. Though this approach requires more steps than a ready-made WordPress installation, it offers administrators greater control over their WordPress environment. If you are looking to access a ready-made WordPress installation, DigitalOcean Marketplace offers a one-click app to get you started with WordPress through installation when spinning up your server. Depending on your needs and goals, you may find other options that are more suitable. As open-source software, WordPress can be freely downloaded and installed, but to be available on the web, you will likely need to purchase cloud infrastructure and a domain name. Continue following this guide if you are interested in working through the server-side installation and set up of a WordPress site. This tutorial will be using a LAMP ( L inux, A pache, M ySQL, and P HP) stack, which is one option for a server architecture that supports WordPress by providing the Linux operating system, Apache web server, MySQL database, and PHP programming language. We'll install and set up WordPress via LAMP on a Linux Ubuntu 20.04 server. Prerequisites In order to complete this tutorial, you will need access to an Ubuntu 20.04 server and will need to complete these steps before beginning this guide: Set up your server by following our Ubuntu 20.04 initial server setup guide , and ens
How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 20.04 [Quickstart]
How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 20.04 [Quickstart] . Answer mysqlnd doesn't support, the default authentication method for MySQL 8. For that reason, when creating database users for PHP applications on MySQL 8, you'll need to make sure they're configured to use mysql_native_password instead. Please refer to step 6 of our detailed LAMP on Ubuntu 20.04 guide to learn how to do that. In this guide, we'll set up a domain called your_domain, but you should replace this with your own domain name. Apache on Ubuntu 20.04 has one server block enabled by default that is configured to serve documents from the /var/www/html directory. Instead of modifying /var/www/html, we'll create a directory structure within /var/www for the your_domain site, leaving /var/www/html in place as the default directory to be served if a client request doesn't match any other sites. Create the directory for as follows: sudo mkdir /var/www/your_domain Copy Next, assign ownership of the directory with the $USER environment variable, which will reference your current system user: sudo chown -R $USER:$USER /var/www/your_domain Copy Then, open a new configuration file in Apache's sites-available directory using your preferred command-line editor: sudo nano /etc/apache2/sites-available/your_domain.conf Copy This will create a new blank file. Paste in the following bare-bones configuration: /etc/apache2/sites-available/your_domain.conf
PHP 进阶 - 在 Ubuntu 上搭建 LAMP 环境教程
PHP 进阶 - 在 Ubuntu 上搭建 LAMP 环境教程 本文将为您提供一个在 Ubuntu 服务器上搭建 LAMP(Linux, Apache, MySQL, PHP) 环境的完整指南。通过本文,您将学习如何安装和配置 Apache、MySQL、PHP,并将您的 PHP 项目部署到服务器上。本文适用于 Ubuntu 20.04 及更高版本。一、系统更新 在开始之前,确保您的系统软件包是最新的。sudo apt update sudo apt upgrade -y 1. 2. 二、安装 Apache 1. 安装 Apache Web 服务器 sudo apt install apache2 -y 1. 2. 启动并设置 Apache 开机自启 sudo systemctl start apache2 sudo systemctl enable apache2 1. 2. 3. 验证 Apache 是否正常运行 在浏览器中访问 http://<您的服务器 IP>/,应显示 Apache 默认的欢迎页面。如果无法访问,请检查防火墙设置 (后续步骤将涵盖防火墙配置)。三、安装 MySQL 1. 安装 MySQL 服务器 sudo apt install mysql-server -y 1. 2. 启动并设置 MySQL 开机自启 sudo systemctl start mysql sudo systemctl enable mysql 1. 2. 3. 验证 MySQL 安装 登录 MySQL 以确认安装成功。sudo mysql -u root -p 1. MySQL 默认密码是 root,直接登录即可。4. 修改初始密码 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password'; 1. 5. 创建库和表 这里我们用 SQL 语句把项目需要的数据库建好即可。四、安装 PHP 及必要模块 1. 添加 Ondřej Surý的 PHP PPA(提供最新的 PHP 版本) sudo apt install software-properties-common -y sudo add-apt-repository ppa:ondrej/php sudo apt update 1. 2. 3. 2. 安装 PHP 8.3 和相关模块 这里以 8.3 为例,其他版本只需要替换这个版本号。sudo apt install php8.3 php8.3-fpm php8.3-mysql php8.3-xml php8.3-curl php8.3-mbstring php8.3-zip php8.3-gd -y 1. 其中,PHP FastCGI Process Manager,用于与 Apache 配合。3. 启动并设置 PHP-FPM 开机自启 sudo systemctl start php8.3-fpm sudo systemctl enable php8.3-fpm 1. 2. 4. 验证 PHP 安装 php -v 1. 预期输出示例:PHP 8.3.0 (cli) (built: ) 1. 五、配置 Apache 与 PHP-FPM 集成 1. 启用必要的 Apache 模块 确保启用了 proxy、proxy_fcgi 和 rewrite 模块,这对于 PHP-FPM 的集成和 URL 重写非常重要。sudo a2enmod proxy proxy_fcgi rewrite
FAQ
如何验证 Apache 是否安装成功?
在浏览器中输入服务器 IP 地址,若显示 Apache 默认欢迎页面则成功。
MySQL 安装后如何加固安全?
运行 mysql_secure_installation 脚本,设置密码策略并移除匿名用户。
PHP 模块如何与 Apache 集成?
安装 libapache2-mod-php 包并重启 Apache 服务即可启用。