如何在Ubuntu上安装Linux、Apache、MariaDB、PHP(LAMP)



“LAMP”堆栈是一组开源软件,通常安装在一起以使服务器能够托管用PHP 编写的动态网站和 Web 应用程序。该术语是一个首字母缩写词,代表L inux 操作系统,带有Apache Web服务器。站点数据存储在MySQL(这里用的是MariaDB)数据库中,动态内容由PHP处理。

在本指南中,您将在 Ubuntu 20.04 服务器上设置 LAMP 堆栈。

sudo apt update
sudo apt upgrade

sudo apt install -y apache2 apache2-utils
sudo systemctl start apache2
sudo apache2 -v

sudo iptables -I INPUT -p tcp –dport 80 -j ACCEPT
sudo iptables -I INPUT -p tcp –dport 443 -j ACCEPT

sudo ufw allow http
sudo ufw allow https

sudo chown www-data:www-data /var/www/html/ -R

sudo apache2ctl -t
如果错误:
sudo nano /etc/apache2/conf-available/servername.conf
加入ServerName localhost
sudo a2enconf servername.conf
sudo systemctl reload apache2
sudo apache2ctl -t

sudo apt install mariadb-server mariadb-client
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl status mariadb

sudo mysql_secure_installation
直接回车
设置密码:回答Y
后面都是Y

sudo mariadb -u root -p

sudo apt install php7.4 libapache2-mod-php7.4 php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline

sudo a2enmod php7.4

sudo systemctl restart apache2

Leave a Reply

Your email address will not be published.