前端开发入门到精通的在线学习网站

网站首页 > 资源文章 正文

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

qiguaw 2024-11-23 21:22:04 资源文章 9 ℃ 0 评论

因项目需求,在树莓派上折腾了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解析正常



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

先安装redis

sudo apt-get install redis-server -y


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

sudo apt search php-redis

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



sudo apt-get install php-redis

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

sudo service apache2 restart


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

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



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



redis扩展成功

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表