记录一次Ubuntu搭建LAMP环境笔记

1、什么是LAMP?

简单的说就是Linux+Apache+MySQL+PHP

2、准备工作

1、连接Linux服务器

这还用说嘛?当然是连接Linux的服务器咯!因为我电脑是深度系统(Deepin OS),所以我就可以免了这部分的工作了

2、更换源(非必要)

连接上服务器之后,我们先更新源(我在这个遇到过很多种报错,但大多数都是因为源的问题,进入到/etc/apt/sources.list里面删除原来的文件内容,复制下面的任意一个到其中并保存(常用的是阿里源和清华源,推荐阿里源下面我提供几个常用的源)

阿里源:

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

清华源:

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

3、更新源

桌面终端执行下列命令:

sudo apt update  更新软件列表,换源完成。

3、安装工作

1、安装Apache2

桌面终端执行下列命令:

sudo apt install apache2 -y

安装完成以后浏览器的地址栏输入:http://localhost/,如过出现下图则表示安装成功

Apache

2、安装MariaDB

桌面终端执行下列命令:

sudo apt install mariadb-server mariadb-client

访问数据库:

mysql -u root -p

修改数据库密码:

sudo mysql_secure_installation

3、安装PHP

桌面终端执行下列命令:

sudo apt install php
sudo apt install install libapache2-mod-php
sudo apt install php-mysql

安装完成后我们来进行测试一下是否成功了?

cd /var/www/html
vi test.php

Ctrl+i输入以下内容:

<?php
    echo phpinfo();
?>

输入完成后ESC:wq,回车进行保存文件 ,回到浏览器输入:http://localhost/test.php,出现以下界面就安装成功了

phpinfo

4、安装phpMyadmin

sudo apt install php-mbstring php7.3-mbstring php-gettext
sudo systemctl restart apache2.service
sudo apt install phpmyadmin

如果这个命令无法安装phpmyadmin的话 就手动下载好 复制到网站目录就好了


相遇不一定有结果 但一定有意义.