I tried to read my DS18B20 sensor temperature with my raspberry pi adresse, I wrote this code in /var/www/html/index.php
<?php
// Fichier à lire
$file = "/sys/bus/w1/devices/28-80000026ddb1/w1_slave";
// Lecture ligne par ligne
$lines = file($file);
// Recupere la 2nd ligne
$temp = explode(’=’, $lines[1]);
// Formatage de la temperature
$temp = number_format($temp[1]/1000,2, ’.’, ’’);
// On affiche la temperature
echo $temp;echo" degrés Celius";
?>
What’s wrong with it? It shows me the following:
sanyassh
7,87213 gold badges32 silver badges63 bronze badges
asked May 15, 2019 at 14:35
1
You need to install PHP, link it to your apache installation, then tell apache that the root page is «index.php» instead that «index.html» so that when you request «/» it can execute the index.php script.
1- install PHP engine, for example as apache SAPI module:
apt install libapache2-mod-php7.0
2- put this one inside your virtualhost or in your /etc/apache2/apache2.conf file:
DirectoryIndex index.php index.html
3- restart apache
You should now be able to execute PHP code with apache httpd
answered May 16, 2019 at 22:48
dAm2KdAm2K
9,7535 gold badges41 silver badges47 bronze badges
You are seeing the root page of your webserver. Your PHP code is not in the root page, you need to browse to the page index.php .
Hit in the browser bar the url that show Apache2 Debian Default Page, followed by:
/index.php
instead of
/index.html
For example:
[ip_address]/index.php
If the apache configuration file is the default one, should not require other settings to browse your page. Further configurations are possible to change the root page to yours. See about this: How do I change the default index page in Apache?
Yes, PHP should be installed in order to run PHP code.
answered May 15, 2019 at 15:13
GabrieleMartiniGabrieleMartini
1,6152 gold badges19 silver badges26 bronze badges
I tried to read my DS18B20 sensor temperature with my raspberry pi adresse, I wrote this code in /var/www/html/index.php
<?php
// Fichier à lire
$file = "/sys/bus/w1/devices/28-80000026ddb1/w1_slave";
// Lecture ligne par ligne
$lines = file($file);
// Recupere la 2nd ligne
$temp = explode(’=’, $lines[1]);
// Formatage de la temperature
$temp = number_format($temp[1]/1000,2, ’.’, ’’);
// On affiche la temperature
echo $temp;echo" degrés Celius";
?>
What’s wrong with it? It shows me the following:
sanyassh
7,87213 gold badges32 silver badges63 bronze badges
asked May 15, 2019 at 14:35
1
You need to install PHP, link it to your apache installation, then tell apache that the root page is «index.php» instead that «index.html» so that when you request «/» it can execute the index.php script.
1- install PHP engine, for example as apache SAPI module:
apt install libapache2-mod-php7.0
2- put this one inside your virtualhost or in your /etc/apache2/apache2.conf file:
DirectoryIndex index.php index.html
3- restart apache
You should now be able to execute PHP code with apache httpd
answered May 16, 2019 at 22:48
dAm2KdAm2K
9,7535 gold badges41 silver badges47 bronze badges
You are seeing the root page of your webserver. Your PHP code is not in the root page, you need to browse to the page index.php .
Hit in the browser bar the url that show Apache2 Debian Default Page, followed by:
/index.php
instead of
/index.html
For example:
[ip_address]/index.php
If the apache configuration file is the default one, should not require other settings to browse your page. Further configurations are possible to change the root page to yours. See about this: How do I change the default index page in Apache?
Yes, PHP should be installed in order to run PHP code.
answered May 15, 2019 at 15:13
GabrieleMartiniGabrieleMartini
1,6152 gold badges19 silver badges26 bronze badges
For every website, you will eventually need to change the default index page to the home page of your website/blog. In this article, we will look at how to change default index page in Apache Web Server.
Here are the steps to change default index page in Apache web server. You can change default index page via Apache Server configuration file, or using .htaccess file. We will look at both approaches below.
Change default index page using Apache Configuration
Apache configuration file is present at one of the following locations depending on your installation:
/etc/apache2/httpd.conf
/etc/apache2/apache2.conf
/etc/httpd/httpd.conf
/etc/httpd/conf/httpd.conf
Open terminal and run the following command to open Apache configuration file
$ sudo vi /etc/apache2/httpd.conf
Also read : How to Change Timezone in Apache/PHP
You will see the following lines of code.
# # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
Change index.html index.php to your choice of web page (e.g home.html).
<IfModule dir_module> DirectoryIndex home.html </IfModule>
Make sure you have placed this file home.html at /var/www/html/. If you have placed it in a different folder (e.g /var/www/html/product/) then modify the path above accordingly (e.g /product/home.html).
<IfModule dir_module> DirectoryIndex /product/home.html </IfModule>
You can also add multiple index pages to Apache as shown below
<IfModule dir_module> DirectoryIndex home.html welcome.html </IfModule>
Restart Apache web server to apply changes.
$ sudo service apache2 restart
Also read : How to Install mod_security on CentOS 7
Change default index page using .htaccess
You can also change default index page for Apache using .htaccess. Before proceeding, please enable mod_rewrite (.htaccess) in your Apache web server.
Open .htaccess file, typically located at /var/www/html/.htaccess
$ sudo vi /var/www/html/.htaccess
Also read : How to Set Up Virtual Hosts in Apache
Add the following line to .htaccess file to set index page to home.html.
DirectoryIndex home.html
Restart Apache web server to apply changes.
$ sudo service apache2 restart
That’s it. Open browser and visit http://your_server_or_ip and you will see the new page. Replace your_server_or_ip with your domain name, or server IP address.
Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!
Related posts:
- About Author
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName [servername]
DocumentRoot /home/[username]/www/[servername]/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /home/user/[username]/[servername]/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/[username]/www/[servername]/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /home/[username]/www/[servername]/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
(sites-enabled)
Пользователь решил продолжить мысль 19 Декабря 2012, 16:10:17:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName [servername]
DocumentRoot /home/[username]/www/[servername]/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /home/user/[username]/[servername]/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/[username]/www/[servername]/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /home/[username]/www/[servername]/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
sites-available