11. PHP for Web Service with MYSQL link
11. PHP for Web Service with MYSQL link
Introduction
PHP is a script language and interpreter that is freely available and used primarily on Linux
Web servers. PHP, originally derived from Personal Home Page Tools, now stands for PHP:
Hypertext Preprocessor. PHP is an alternative to Microsoft's Active Server Page (ASP)
technology, executes on the server. The PHP script is embedded within a Web page along
with its HTML.
Requirements
1. A machine as Web server
2. A client machine with GUI operating systems (Windows 10 or Lubuntu)
3. DNS server is turned on
4. Privileged access to your Ubuntu system as root or via sudo command is
required
Outcomes
You will provide a script language and interpreter to display dynamic content for
your website. By the end of this activity, you will have a web server on Ubuntu Server 20.04
and it will prefer PHP files first.
1. Back to the www machine and install the PHP package and all components, so that
PHP code can run under the Apache server and talk to your MySQL database:
2. Make Apache look for an index.php file first by modifying the dir.conf file in
nano text editor with root privileges:
3. Move the PHP index file to the first position after the DirectoryIndex specification:
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
<html>
<head>
<title>Welcome to DFN50303.com!</title>
</head>
<body>
<h1>Success! The DFN50303.com server block is working!</h1>
<?php
phpinfo();
?>
</body>
</html>
9. From any machine (host 1 or host2 ) on your network, you can test this by navigating to
http://www.dfn50303.com (or http://dfn50303.com).
mysql-u root -p
12. To create a new database, run the following command from your MySQL console:
Now you can create a new user and grant them full privileges on the custom database you’ve just
created.
13. The following command creates a new user named example_user, using
mysql_native_password as default authentication method. We’re defining this user’s
password as password, but you should replace this value with a secure password of your
own choosing.
14. Now we need to give this user permission over the example_database database:
This will give the example_user user full privileges over the example_database database, while
preventing this user from creating or modifying other databases on your server
exit
15. You can test if the new user has the proper permissions by logging in to the MySQL console again, this
time using the custom user credentials:
mysql -u example_user -p
Notice the -p flag in this command, which will prompt you for the password used when creating the
example_user user. After logging in to the MySQL console, confirm that you have access to the
example_database database:
SHOW DATABASES;
17. Go to index.php, remove the phpinfo(); that been put on the step 6. And put this php command.
Please type carefully and ensure all running if not you will get error.
18. Before test the mainpage ensure to restart the apache service for ensure php function.
Note: You will get this output if your configuration is correct, please check and find solution if your
facing a problem to connect it