0% found this document useful (0 votes)
13 views

11. PHP for Web Service with MYSQL link

This document provides a comprehensive guide on integrating PHP with a web service using an Ubuntu server. It outlines the requirements, installation steps for PHP and Apache, and instructions for creating a MySQL database and user. The final steps include testing the setup and ensuring proper configuration for dynamic content display on the website.

Uploaded by

aimanyusuf7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

11. PHP for Web Service with MYSQL link

This document provides a comprehensive guide on integrating PHP with a web service using an Ubuntu server. It outlines the requirements, installation steps for PHP and Apache, and instructions for creating a MySQL database and user. The final steps include testing the setup and ensuring proper configuration for dynamic content display on the website.

Uploaded by

aimanyusuf7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

INTEGRATE PHP WITH WEB SERVICE

By Ruzaini Roni © 2023. Politeknik Mukah

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.

By Ruzaini Roni © 2023. Politeknik Mukah


Instructions

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:

sudo apt install php libapache2-mod-php php-mysql php-cli

2. Make Apache look for an index.php file first by modifying the dir.conf file in
nano text editor with root privileges:

sudo nano /etc/apache2/mods-enabled/dir.conf

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>

4. Save and close the file when you are finished.

5. Next, create an index.php page using nano or your favorite editor:

sudo nano /var/www/dfn50303.com/html/index.php

6. Then, edit the file as followings:

<html>
<head>
<title>Welcome to DFN50303.com!</title>
</head>
<body>
<h1>Success! The DFN50303.com server block is working!</h1>
<?php
phpinfo();
?>
</body>
</html>

By Ruzaini Roni © 2023. Politeknik Mukah


7. Save and close the file when you are finished.

8. Restart Apache to implement your changes:

sudo systemctl restart apache2

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).

10. Next part is to link website with MYSQL feature.

By Ruzaini Roni © 2023. Politeknik Mukah


11. First, connect to the MySQL console using the root account:

mysql-u root -p

You will be prompt for the password created earlier to login.

12. To create a new database, run the following command from your MySQL console:

CREATE DATABASE example_database;

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.

CREATE USER 'example_user'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

14. Now we need to give this user permission over the example_database database:

GRANT ALL ON example_database.* TO 'example_user'@'%';

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

Now exit the MySQL shell with:

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:

By Ruzaini Roni © 2023. Politeknik Mukah


16. 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;

This will give you the following output:

Now you ready to configure next part for website linked.

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.

sudo systemctl restart apache2

By Ruzaini Roni © 2023. Politeknik Mukah


19. 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).

Note: You will get this output if your configuration is correct, please check and find solution if your
facing a problem to connect it

By Ruzaini Roni © 2023. Politeknik Mukah

You might also like