PHP Programming in Linux
Introduction
PHP is an open-source programming language that can be used to create dynamic web pages. It was designed to work with the Apache server and MySQL database, which are also open source. This article explains how to install PHP on Ubuntu Linux to use it with Apache and MySQL.
How To Test PHP
To test your installation, you can create a simple file named "test.php" in your home directory (the directory you see when you first log in). Add this code inside of it:
Now run this command from the terminal or command line: php -v . You should see something similar to this:
PHP 7.1.0 (cli) (built: Oct 8 2016 15:58:51) ( NTS )
Prerequisites
To follow along with this tutorial, you'll need to have the following installed on your system:
Linux
Apache and/or Nginx web server (we'll be using Apache)
MySQL database server (if you are planning on completing all of the exercises) or MariaDB database server (if you are planning on completing all of the exercises). You can download the latest version from http://www.mariadb.org/. If you want to know more about SQLite, visit http://sqlite.org/, if you want to know more about PostgreSQL, visit http://postgresql.org/ or if you want to know more about Oracle Database, visit https://www.oracle.com/database/ .
Step 1 - Installing Apache
Install Apache
Apache is a web server that works with PHP and MySQL to allow you to create dynamic websites. To install it, open up Terminal (or your terminal program).
Make sure Apache is running and configured properly:
a) Type in this command: sudo /etc/init.d/apache2 status This will tell you whether or not your apache configuration file is set up correctly, or if apache needs to be restarted for changes to take effect. If your system does not respond with "active (running)" then go back over step 5 below (make sure apache has been installed) and make sure that the directory of conf-available contains the file called php5-common
Step 2 - Installing MySQL and PHP
You can install MySQL and PHP through the command line.
Install MySQL with this command: sudo apt-get install mysql-server libmysqlclient-dev
If prompted, enter a root password for your database. We recommend using a strong password that is different from the one you use for your user account. You will need to remember it later when creating databases in phpMyAdmin.
To verify that MySQL is installed correctly, type mysql -u root -p at the prompt and press Enter. You should see a message similar to this one: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.5.50-0ubuntu0.14.04 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement."
Step 3 - Testing PHP Processing on Your Web Server
Now that you have PHP installed on your web server, it's time to test out some of the other features of PHP. In this section, you'll learn how to embed PHP code in HTML documents and see how it works.
Let's start with a simple example:
Hello World This is a paragraph. To do this, we need to go back and edit the _config.php file again so that the PHP engine runs when we visit our website:
<?php include(TEMPLATEPATH . '/footer.php');
You can set up a local web server that handles PHP requests to test your own web applications!
You can set up a local web server that handles PHP requests to test your own web applications!
The easiest way to do this is with the [LAMP stack](https://en.wikipedia.org/wiki/LAMP_stack). This stands for Linux, Apache, MySQL and PHP and it's a collection of software that you can use to quickly create a functioning web server on which you can run PHP scripts. In this article we'll go over how to install the LAMP stack on Ubuntu Linux.
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.