apache2 - cant run php file - Ask Ubuntu
this question has answer here:
i started working on ubuntu 16.04 mini, , star working on php. when create php file , put in directory /var/www/ubunturock/dummy.php
, run apache server , when go address ubunturock/dummy.php
php code file. idea?
here php code well:
<?php $servername='localhost'; $username='root'; $password='root'; $schema='demir'; $conn=mysql_connect($servername, $username, $password) or die('connection failed : ' . $conn-> connect_error); mysql_select_db($schema); $result=mysql_query('select * topics'); echo '<h1>all topics</h1><br>'; echo '<table>'; echo '<tr><td>id</td><td>name</td></tr>'; while($row = mysql_fetch_assoc($result)){ echo '<tr>'; echo '<td>' .$row['id'].'</td>'; echo '<td>' .$row['name'].'</td>'; echo '</tr>'; } echo '</table>'; ?>
apache webserver, webservers there for: (or browser) asks file, , sends file. apache on own doesn't "know" file contains code wanted executed beforehand.
php gets executed php interpreter. seemed have installed interpreter, need integrate apache. lifecycle of php script looks (a bit anthromorphized, it's easier gist way)
- a client requests file ending
.php
. - apache knows, such files need handed php interpreter. does.
- the php interpreter executes php code , generates output, hands apache.
- apache sends output client.
in current setting, apache doesn't "know" .php
files in way special or how handle them. other file , sends file as-is.
there several ways integrate php interpeter apache. can use apache module mod_php
, can use common gateway interface cgi
or newer versions fcgi
or php-fpm
. differ in aspects like
- how easy set up
- what performance offer
- how extensively can configure them
- how can secure setup
if want server toy around , experiment, should sufficient use mod_php
installing package libapache2-mod-php
, restarting apache. sapi (server api) quite bad performance-wise, without configuration options , not secure (mostly because default every php process run same system user). not idea use in production or on server that's connected internet (which means, oslo timbuktu can have go @ it).
two more things: ubuntu 16.04 comes php 7. old mysql functions ones you're using, mysql_connect
, mysql_query
, mysql_fetch_assoc
, on, have been deprecated since php 5.0 (meaning, since twelve years ago). in php 7 have been removed, can't use them anymore. should use mysqli or pdo modules. tutorials easy find.
and secondly, php
package contains basic interpreter. many additional modules packaged in own packages, php-mysql
installed. if want use those, have install respective package.
Comments
Post a Comment