--作者:飞翔的小胖猪

--创建时间:2021年5月29日

--修改时间:2021年5月29日

一、准备

1.1 环境

  • 操作系统:Ubuntu 18.04
  • 网页引擎:Apache
  • php版本:7.4
  • 数据库:Mariadb

1.2 软件地址

  • 操作系统: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/bionic/ubuntu-18.04.5-live-server-amd64.iso
  • php: 使用apt安装
  • Apache: 使用apt安装。
  • Mariadb: 使用apt安装。

1.3 apt源

清华大学镜像配置帮助:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

清华大学源

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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

1.4 配置apt

1.备份原有的apt配置文件

# cp -rp /etc/apt/source.list   /etc/apt/source.list_bak

 2.修改apt配置文件

# vim /etc/apt/source.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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.更新apt源

# add-apt-repository ppa:ondrej/php
# apt clean all
# apt-get update
# echo $?

二、安装Aapche(A)

2.1 前提条件

  • 操作系统已经安装完成。
  • 操作系统网络配置完成,能够正常访问到互联网。
  • apt源配置已完成。

2.2 安装软件

安装apache2软件、启动并设置开机自启动,检查结果应该是running。

# apt-get install apache2 apache2-dev -y
# systemctl restart apache2
# systemctl enable apache2
# systemctl status apache2

2.3 检查

手动创建一个index.html文件,在本机上请求该网页确认显示为手动添加的内容。检查结果应该能正常访问到到手动添加的网页内容。

# echo 'test_apache2' > /var/www/html/index.html
# curl x.x.x.x

三、安装Mariadb(M)

3.1 前提条件

  • 操作系统已经安装完成。
  • 操作系统网络配置完成,能够正常访问到互联网。
  • apt源配置已完成。

3.2 安装软件

安装mariadb软件,同时设置数据库软件开机自启动。

# apt-get install mariadb*  -y
# systemctl status mariadb
# systemctl enable mariadb
# mysql_secure_installation
Enter current password for root (enter for none): 直接回车
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] # mysql -uroot -p你的密

四、安装PHP(P)

4.1 前提条件

  • 操作系统已经安装完成。
  • 操作系统网络配置完成,能够正常访问到互联网。
  • apt源配置已完成。

4.2 安装软件

安装php软件前需要安装其依赖的软件。

1.安装依赖软件

# apt-get install build-essential pkg-config libxml2-dev libxpm-dev libssl-dev sqlite3 libsqlite3-dev libbz2-dev libgmp3-dev  libzip-dev libfreetype6-dev libjpeg-dev freetype2-demos libonig-dev libedit-dev libreadline-dev libpng-dev libxslt1-dev libcurl4 libcurl4-openssl-dev -y

2.安装php软件

下载并安装php软件。

简易安装,只安装少量的模块。

# apt-get install  php7.4 php7.4-fpm  php7.4-gd php7.4-mbstring  php7.4-mysql php7.4-xml php7.4-curl libapache2-mod-php7.4 -y
# php -v

apt源中所有php模块安装。使用apt-get list 命令获取到php7.4的所有模块名,并生成软件安装命令。

# apt list | grep -i php7.4- | awk -F '/' '{sum=sum" "$1};END{print "apt-get install -y php7.4 " sum}'

下面这条语句请根据第一步的命令所得,复制并执行,文档中只是做个展示,由于太长就没有全部展示出来。
# apt-get install -y php7.4 libphp7.4-embed .......... php7.4-zstd

五、测试LAMP环境

5.1 准备mariadb测试数据

创建测试数据库,创建一个测试用户。

# mysql -uroot
MariaDB [(none)]> create database test_db;
MariaDB [(none)]> grant all on test_db.* to test_user@'127.0.0.1' identified by 'Csuser_12345#';
MariaDB [(none)]> flush privileges;

5.2 准备php测试数据

在apache目录下创建一个index.php文件,用作测试。

# cd /var/www/html/
# vim index.php
<?php
$servername = "127.0.0.1";
$username = "test_user";
$password = "Csuser_12345#"; // 创建连接
$conn = new mysqli($servername, $username, $password); // 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "连接成功"; //关闭连接
$conn->close(); ?>

5.3 测试

使用web浏览器测试是否成功。如果提示连接成功表示apche能够识别php,同时php能够正常与myql数据库进行交互。

Ubuntu 18.04 安装配置LAMP的更多相关文章

  1. Ubuntu 18.04安装配置Apache Ant

    Ubuntu 18.04安装配置Apache Ant 文章目录 Ubuntu 18.04安装配置Apache Ant 下载 执行以下命令 `/etc/profile`中配置环境变量 载入配置 测试 执 ...

  2. Ubuntu 18.04 安装配置 go 语言

    Ubuntu 18.04 安装配置 go 语言 1.下载 下载 jdk 到 Downloands 文件夹下 cd 进入 /usr/local, 创建 go 文件夹, 然后 cd 进这个文件夹 cd / ...

  3. Ubuntu 18.04 安装配置 MySQL 5.7

    Ubuntu 18.04 安装 mysql 的过程中,竟然没有让你输入秘密?!(之前在 Ubuntu 14.04 下,安装过程中会询问密码),这导致安装完 mysql 初始秘密不知道的问题. $ su ...

  4. Ubuntu 18.04安装配置pure-ftpd解决中文乱码问题

    之前用的是vsftpd配置ftp服务器,前面用的挺好,没什么问题,但是后面接收设备上传的文件夹时发现了一个大坑,当设备上传的文件夹名字中包含中文时,在Linux上显示的是乱码...各种转码都不行,折腾 ...

  5. Ubuntu 18.04 安装配置 java jdk

    1.下载 下载 jdk 到 Downloands 文件夹下 cd 进入 /usr/local, 创建 jdk 文件夹, 然后 cd 进这个文件夹 cd /usr/local sudo mkdir jd ...

  6. Ubuntu 18.04安装Samba服务器及配置

    Ubuntu 18.04安装Samba服务器及配置 局域网下使用samba服务在Linux系统与Windows系统直接共享文件是一项很方便的操作.以Ubuntu为例配置samba服务,Linux服务器 ...

  7. Ubuntu 18.04 安装MySQL

    最近在写东西的时候,需要用到MySQL,在网上查了一下,都说Ubuntu18.04不能安装MySQL5.7.22, 总觉的不可能,所以自己就研究了一下,然后分享给大家 工具/原料   VMware W ...

  8. Ubuntu 18.04 安装博通(Broadcom)无线网卡驱动

    目录 Ubuntu 18.04 安装博通(Broadcom)无线网卡驱动 Package gcc is not configured yet. 解决办法 history history | grep ...

  9. Ubuntu 18.04 安装部署Net Core、Nginx全过程

    Ubuntu 18.04 安装部署Net Core.Nginx全过程 环境配置 Ubuntu 18.04 ,Nginx,.Net Core 2.1, Let's Encrypt 更新系统 sudo a ...

随机推荐

  1. 关于笨蛋式病毒创作(CMD式)C++

    ​ 对于病毒创作,有好多种原因:有想装逼的,想盗取信息的...... 任何理由千奇百出,有的在下面评论出来. 对于病毒创作,我可是既会有不会,只会乱写,回头一看,全错了. 我今天写的这篇博客就是面向于 ...

  2. SpringCloud整合Hystrix

    1.Hystrix简介 Hystrix是由Nefflix开源的一个延迟和容错库,用于隔离访问远程系统.服务或第三方库,防止级联失败,从而提升系统的可用性.容错性与局部应用的弹性,是一个实现了超时机制和 ...

  3. .NET Core分析程序集最优美的方法,不用Assembly.LoadFile(),超越ReflectionOnlyLoad

    在编写.NET程序的时候,如果需要对一个程序集文件进行分析,我们可以使用Assembly.LoadFile()来加载这个程序集,然后对LoadFile()方法返回的Assembly对象进行进一步的分析 ...

  4. 「SNOI2017」一个简单的询问

    「SNOI2017」一个简单的询问 简单的解法 显然可以差分一下. \[get(l,r,x)\times get(l1,r1,x)=get(1,r,x) \times get(1,r1,x)-get( ...

  5. Ubuntu下Java JDK安装

    1.仓库安装 待更新 2.手动安装 1.下载linux平台sdk. 官网:https://www.oracle.com/technetwork/java/javase/downloads/index. ...

  6. PHP中常见的数字掐头去尾操作方法

    四舍五入round round( float $val[, int $precision = 0[, int $mode = PHP_ROUND_HALF_UP]] ) : float 对浮点数进行四 ...

  7. 自定义的类实现copy操作

    1.自定义类实现copy操作 让类遵守NSCopying协议 实现 copyWithZone:方法,在该方法中返回一个对象的副本即可. 在copyWithZone方法中,创建一个新的对象,并设置该对象 ...

  8. 出现Table ‘./mysql/proc’ is marked as crashed and should be repaired

    一般这种表崩溃的问题出现在mysql异常停止,或者使用kill -9命令强行杀掉进程导致,进入MySQL命令行后,执行下面的命令即可修复'./mysql/proc'表 repair table mys ...

  9. 生成树协议(STP)的精髓知识

    STP生成树协议   1.STP介绍 2.STP生成树算法 1.STP  -   Spanning tree protocol (生成树协议)是逻辑上断开环路,防止广播风暴的产生.当线路故障,阻塞接口 ...

  10. LeetCode随缘刷题之截断句子

    这道题相对比较简单.正好最近学到StringBuilder就用了. package leetcode.day_12_06; /** * 句子 是一个单词列表,列表中的单词之间用单个空格隔开,且不存在前 ...