您的位置 首页 php

树莓派介绍:PHP开发环境搭建(LAMP)

树莓派 中搭建PHP 开发环境 ,需要安装apache2, MariaDB, php7

准备

硬件:树莓派3B+

系统:Linux raspberrypi 4.19.57

更新源

sudo apt-get update
 

搭建LAMP

  • 安装apache2
	sudo apt-get install apache2
 

测试apache是否安装成功

	http://树莓派的IP
 

  • 安装 mariadb
sudo apt-get install mariadb-server
 

测试MariaDB是否安装成功

sudo mysql
 

出现如下信息,就代表安装成功

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 42

Server version: 10.3.15-MariaDB-1 Raspbian testing-staging

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]>

  • 安装PHP

因php5没有源可以安装,默认安装是php7的版本.

sudo apt-get install php-pear
 
  • 安装 phpmyadmin
sudo apt-get install phpmyadmin
sudo chmod 777 /var/www/html
sudo a2enmod rewrite
sudo ln –s /usr/share/phpmyadmin /var/www/html
 

安装过程中出现的对话框选择:

第一次的弹框有apache和lightd两个选项,按空格选中Apache2,按回车。第二次选择no。

  • 配置密码访问MariaDB
sudo mysql
use mysql;
UPDATE user SET password=password(‘密码’) WHERE user = ‘root’;
UPDATE user SET password=’mysql_native_password’ WHERE user = ‘root’;
flush privileges;
exit
 

以上执行完成后,重启服务

Sudo systemctl restart mariadb
 

重启完成后,用密码进行mariadb登录,验证是否修改成功

mysql –u root –p
 
  • 配置远程连接MariaDB

MariaDB默认只监听了127.0.0.1这个IP地址,这个时候是无法从外部连接到树莓派上的MariaDB。打开配置文件:

suto nano /etc/mysql/mariadb.conf.d/50-server.cnf
 

# Instead of skip-networking the default is now to listen only on

# localhost which is more compatible and is not less secure.

# bind-address = 127.0.0.1

bind-address表示只监听了127.0.0.1这个IP,将这一行的前面加上# 将这一行注释起来,这样MariaDB就监听了所有的IP。

最后,测试,游览器访问:

http://树莓派ip地址/phpmyadmin

在/var/www/html 中创建一个test.php

test.php写入以下代码

<?php
 echo phpinfo();
?>
 

在浏览器中输入: http://树莓派ip地址/test.php,出现以下图,代表php开发搭建环境全部完成。

文章来源:智云一二三科技

文章标题:树莓派介绍:PHP开发环境搭建(LAMP)

文章地址:https://www.zhihuclub.com/78125.shtml

关于作者: 智云科技

热门文章

网站地图