Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Bugs & Fixes 2 years ago
Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
This question already has an answer here:
I just started working on Ubuntu 16.04 Mini, and I just star working on PHP. When I create php file and put in directory /var/www/ubunturock/dummy.php and run the apache server and when I go to my address ubunturock/dummy.php I get my PHP code file. Any idea?
/var/www/ubunturock/dummy.php
ubunturock/dummy.php
Here is my PHP code as 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 * FROM topics'); echo 'All Topics'; echo ''; echo 'IDName'; while($row = mysql_fetch_assoc($result)){ echo ''; echo '' .$row['id'].''; echo '' .$row['name'].''; echo ''; } echo ''; ?>
Apache is a webserver, so it basically does what webservers are there for: You (or your browser) asks for a file, and it sends you that file. Apache on its own doesn't "know" that this file contains code that you wanted to be executed beforehand.
PHP gets executed by the PHP interpreter. You seemed to have installed that interpreter, but you need to integrate it with Apache. The lifecycle of a PHP script basically looks like this (a bit anthromorphized, but it's easier to get the gist that way)
.php
In your current setting, Apache doesn't "know" that .php files are in any way special or how to handle them. So it just does as it would do with any other file and sends the file as-is.
There are several ways to integrate the PHP interpeter with Apache. You can use the Apache module mod_php, you can use the common gateway interface cgi or its newer versions like fcgior php-fpm. They differ in aspects like
mod_php
cgi
fcgi
php-fpm
If you just want a server to toy around and experiment, it should be sufficient to use mod_php by simply installing the package libapache2-mod-php and restarting Apache. But that SAPI (server API) is quite bad performance-wise, nearly without configuration options and not very secure (mostly because by default every PHP process is run by the same system user). It would be not a good idea to use that in production or on a server that's connected to the internet (which means, that everybody from Oslo to Timbuktu can have a go at it).
libapache2-mod-php
Two more things: Ubuntu 16.04 comes with PHP 7. The old mysql functions like the ones you're using, mysql_connect, mysql_query, mysql_fetch_assoc and so on, have been deprecated since PHP 5.0 (meaning, since twelve years ago). In PHP 7 they have been removed, so you can't use them anymore. You should use the mysqli or pdo modules. Tutorials about those are easy to find.
mysql_connect
mysql_query
mysql_fetch_assoc
And secondly, the php package contains the basic interpreter. Many additional modules are packaged in their own packages, like the php-mysql you already installed. If you want to use those, you have to install the respective package.
php
php-mysql
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.