欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

树莓派安装Apache2遇到问题与解决方法

程序员文章站 2024-02-06 23:47:52
...

因项目需求,在树莓派上折腾了LAMP环境,安装过程中遇到一些问题,慢慢折腾解决了。

1、更换系统源

sudo nano /etc/apt/sources.list

注释掉系统默认源,更换阿里云源。

# deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
# deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib rpi
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib rpi

2、更新系统

sudo apt-get update -y

3、安装Apache与php7.3

更新完,安装Apache。

sudo apt-get install apache2 -y

安装php7.3需要添加其他更新源

sudo nano /etc/apt/sources.list
# deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
# deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib rpi
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib rpi
#添加源 安装php7.3
deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi
deb-src http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi
sudo apt install -y -t buster php7.3-fpm php7.3-curl php7.3-gd php7.3-intl php7.3-mbstring php7.3-mysql php7.3-imap php7.3-opcache php7.3-sqlite3 php7.3-xml php7.3-xmlrpc php7.3-zip

因为在安装7.3之前有7.1版本,并且apahce在php7.3之前安装的,所以导致解析不了php。解决方法是安装 libapache2-mod-php7.3

sudo apt-get install libapache2-mod-php7.3

安装完成php解析正常

树莓派安装Apache2遇到问题与解决方法

因为项目需要用到redis,但是安装php的时候没有安装redis扩展,所以需要重新安装。因为并不需太多设置,所以就不编译安装,直接使用apt安装。

先安装redis

sudo apt-get install redis-server -y

redis 安装完以后,还需要php加载redis扩展,所以需要安装php-redis

树莓派安装Apache2遇到问题与解决方法

这里出现两个版本 我安装的是php-redis 相对较新的版本。

sudo apt-get install php-redis

redis安装完后重启apache服务测试一下。

sudo service apache2 restart

测试一下php-redis是否扩展成功

sudo nano /var/www/html/redis.php

树莓派安装Apache2遇到问题与解决方法

浏览器输入http://ip/redis.php 我这里输入http://192.168.0.103/redis.php

树莓派安装Apache2遇到问题与解决方法

redis扩展成功