Home > Article > Backend Development > How to set up a php environment on Raspberry Pi 3+
The Raspberry Pi is a small computer that is widely used in the production of embedded systems and single-board computers. Among them, Raspberry Pi 3 is the latest version with excellent performance. Many developers and enthusiasts choose to build a PHP environment on the Raspberry Pi to run their own websites or applications. In this article, we will introduce how to set up a php environment on Raspberry Pi 3.
To build a php environment on Raspberry Pi 3, you first need to install the Apache server. Enter the following command in the terminal:
sudo apt-get update sudo apt-get install apache2
After the installation is complete, enter the following command to check whether Apache has been successfully installed:
sudo service apache2 restart
At this time, enter the IP address of Raspberry Pi 3 in the browser , you can see the welcome page of the Apache server.
Before installing php, we also need to install some dependent libraries. Enter the following command to install:
sudo apt-get install php7.0 sudo apt-get install libapache2-mod-php7.0 sudo apt-get install php7.0-mysql sudo apt-get install php7.0-curl sudo apt-get install php7.0-json sudo apt-get install php7.0-cgi
After the installation is completed, We can enter the following command in the terminal to check whether php has been successfully installed:
php -v
If you can see the version information of php, it means the installation is successful.
Now, we need to modify the Apache configuration file and connect the php module to the Apache module. Enter the following command in the terminal to open the Apache configuration file:
sudo nano /etc/apache2/mods-enabled/dir.conf
In the opened file, we will add index.php between \
Now, we have successfully set up the php environment and can test it. In the /var/www/html directory, create a new php file. The content can be the following code:
<?php phpinfo(); ?>
After saving and exiting, enter the IP address and file name of the Raspberry Pi 3 in the browser, that is You can see the relevant information and configuration information of php.
Summary
In this article, we introduced how to set up a php environment on Raspberry Pi 3. First you need to install the Apache server, then install php and its dependent libraries, and modify the Apache configuration file. Finally, conduct a test to confirm that the PHP environment has been set up successfully. Whether you want to run your own website or application, the PHP environment of Raspberry Pi 3 can provide you with excellent performance and stable operating environment.
The above is the detailed content of How to set up a php environment on Raspberry Pi 3+. For more information, please follow other related articles on the PHP Chinese website!