Installing PHP and MySQL

PHP is one of the most popular programming languages in use today for the web look at. It is the code that runs on the server when it receives a request for a website. Unlike HTML, PHP can generate dynamic web pages that can change the look and content on the fly. We chose PHP to work with because WordPress uses PHP. Now, install PHP and the accompanying Apache packages with the following command:

$ sudo apt-get install php5 libapache2-mod-php5

We now have PHP installed with its accompanying Apache packages, and we will proceed to test it.

Navigate to the HTML folder and create a new index.php file:

$ cd /var/www/html/
$ sudo nano index.php

Add a test line to it:

<?php echo "hello world"; ?>

Save the file and exit by pressing Ctrl + X and then Y. We also need to remove the index.html file because HTML takes precedence over PHP. Do that with the following command:

sudo rm index.html

Navigate to 127.0.0.1 or localhost in the browser and you will be greeted by the hello world message. Let's now set up something static.

Replace the hello world line with the following:

<?php echo date('Y-m-d H:i:s'), ?>

Now that we have installed PHP to process the web pages that we want, the next step is to install a database to store some data. Our database of choice will be MySQL simply because WordPress uses it to store IDs of things such as Post, Pages, Comments, Users, and so on.

To install MySQL and its PHP packages, run the following command:

sudo apt-get install mysql-server php5-mysql

Once the installation proceeds, you will be asked for a root password for creating the databases. Enter the password and remember it for future use.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset