树莓派编译安装PHP7.3

首先安装依赖

apt install -y libxml2 libxml2-dev libjpeg-dev libcurl4-openssl-dev libreadline-dev libzip-dev libfreetype6-dev

下载源码并安装

wget https://www.php.net/distributions/php-7.3.15.tar.gz
tar zxf php-7.3.15.tar.gz
cd php-7.3.15
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-curl --with-gettext --with-iconv-dir --with-gd --with-jpeg-dir --with-openssl --with-openssl-dir=/usr/local/openssl --with-pear --with-readline --with-xmlrpc --with-zlib \
--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--enable-bcmath --enable-calendar --enable-exif --enable-fpm --enable-ftp --enable-intl --enable-mbstring --enable-mysqlnd \
--enable-soap --enable-sockets --enable-zip
make -j4 && make install

配置文件

cp php.ini-production /usr/local/php/lib/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/php/lib/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/lib/php.ini
sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/lib/php.ini
sed -i 's/expose_php = On/expose_php = Off/g' /usr/local/php/lib/php.ini

配置 Apache 支持 PHP

echo "AddType application/x-httpd-php .php" >> /usr/local/apache/conf/httpd.conf

增加软连接

ln -s /usr/local/php/lib/php.ini /etc/php.ini
ln -s /usr/local/php/bin/php /usr/local/bin/
ln -s /usr/local/php/bin/phpize /usr/local/bin/
ln -s /usr/local/php/bin/pecl /usr/local/bin/
ln -s /usr/local/php/bin/php-config /usr/local/bin/

树莓派编译安装Apache2.4

首先安装基础依赖库

apt install libpcre3 libpcre3-dev libssl-dev libexpat1-dev

下载源码并安装

cd /usr/local/src
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.0.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
tar zxf httpd-2.4.41.tar.gz
tar zxf apr-1.7.0.tar.gz
tar zxf apr-util-1.6.1.tar.gz
mv apr-1.7.0 httpd-2.4.41/srclib/apr
mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-util
cd httpd-2.4.41
./configure \
--prefix=/usr/local/apache \
--enable-so --enable-mime-magic --enable-rewrite --enable-deflate \
--with-included-apr --with-mpm=prefork \
--disable-autoindex --disable-status --disable-env --disable-alias --disable-version
make -j4 && make install

修改配置文件

sed -i 's/^#ServerName www.example.com:80/ServerName localhost:80/' /usr/local/apache/conf/httpd.conf
sed -i 's/^#LoadModule expires_module/LoadModule expires_module/' /usr/local/apache/conf/httpd.conf
sed -i 's/^#LoadModule rewrite_module/LoadModule rewrite_module/' /usr/local/apache/conf/httpd.conf
sed -i 's/^#LoadModule deflate_module/LoadModule deflate_module/' /usr/local/apache/conf/httpd.conf

增加软连接

ln -s /usr/local/apache/conf/httpd.conf /etc/
ln -s /usr/local/apache/conf/extra/httpd-vhosts.conf /etc/
ln -s /usr/local/apache/bin/apachectl /usr/local/sbin/

启动 Apache

apachectl

完整脚本

apt update
apt install -y libpcre3-dev libexpat1-dev

# 下载源码
wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.0.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz

# 解压
tar zxf httpd-2.4.41.tar.gz
tar zxf apr-1.7.0.tar.gz
tar zxf apr-util-1.6.1.tar.gz
mv apr-1.7.0 httpd-2.4.41/srclib/apr
mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-util

# 编译安装
cd httpd-2.4.41
./configure \
--prefix=/usr/local/apache \
--enable-so --enable-mime-magic --enable-rewrite --enable-deflate --enable-ssl \
--with-ssl=/usr/local/openssl \
--with-included-apr --with-mpm=prefork \
--disable-autoindex --disable-status --disable-env --disable-alias --disable-version
make -j4 && make install

# 修改Apache配置文件
sed -i 's/^#ServerName www.example.com:80/ServerName localhost:80/' /usr/local/apache/conf/httpd.conf
sed -i 's/^#LoadModule expires_module/LoadModule expires_module/' /usr/local/apache/conf/httpd.conf
sed -i 's/^#LoadModule rewrite_module/LoadModule rewrite_module/' /usr/local/apache/conf/httpd.conf
sed -i 's/^#LoadModule deflate_module/LoadModule deflate_module/' /usr/local/apache/conf/httpd.conf
sed -i 's/^#Include conf\/extra\/httpd-vhosts.conf/Include conf\/extra\/httpd-vhosts.conf/' /usr/local/apache/conf/httpd.conf
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/g' /usr/local/apache/conf/httpd.conf

# 配置虚拟主机
mkdir /www/html -p
cat > /usr/local/apache/conf/extra/httpd-vhosts.conf<<EOF

<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs"
    ServerName localhost
</VirtualHost>

<Directory "/www/">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<VirtualHost *:80>
    DocumentRoot "/www/html"
    ServerName localhost
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" common
</VirtualHost>

EOF

# Apache安全设置
echo "ServerTokens Prod" >> /usr/local/apache/conf/httpd.conf
echo "TraceEnable off" >> /usr/local/apache/conf/httpd.conf

# 创建Apache配置文件快捷方式
ln -s /usr/local/apache/bin/httpd /usr/local/bin/
ln -s /usr/local/apache/bin/apachectl /usr/local/bin/
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf
ln -s /usr/local/apache/conf/extra/httpd-vhosts.conf /etc/vhosts.conf

树莓派使用GPIO

用操作文件的方式操作树莓派的gpio


# 激活 gpio-4 *(物理针脚7号)
echo 4 > /sys/class/gpio/export
cd /sys/class/gpio/gpio4

# 设置模式为输出
echo out > direction

# 设置高电位
echo 1 > value
# 设置低电位
echo 0 > value

将len小灯一边连接针脚7号,一边连接针脚6号,就可以控制小灯的开关了。

树莓派自动连接WiFi网络

# /boot/wpa_supplicant.conf
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
 
network={
    ssid="WiFi-A"
    psk="12345678"
    priority=1
}

network={
    ssid="WiFi-B"
    psk="12345678"
    priority=2
}

在树莓派的SD卡上新建文件 wpa_supplicant.conf 添加以上内容到新的配置文件中,修改WiFi账号和密码。

priority是优先级