Setting Up PHP Environment

Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

In the previous introductory PHP lesson, we have already pointed you to the tutorial that provides step-by-step instructions on how to install LAMP. LAMP is an acronym for Linux (operating system), Apache HTTP Server, MySQL (database software), and PHP. For Windows users, the acronym is WAMP, where W stands for Windows operating system. Sometimes P stands for Perl or Python depending on a combination of software that makes up a web server stack.

As previously discussed, in order to use PHP, you will need to install it, Apache, and a database software, where in our case we have preferred MySQL. However, an alternative stack to LAMP, preferentially, XAMPP can be used. XAMPP stands for the open-source cross-platform web server, Apache HTTP server, MySQL/MariaDB database, PHP and Perl Package (Perl/Perl scripting language). Here, X means cross-platform operating systems, implying that it can run on any operating system such as Windows, Mac OS X, Linux and so on. XAMPP is a web server solution stack package developed by Apache Friends that takes care of both LAMP and WAMP and can be used to seamlessly install and configure them. In this post, we have shown how to separately install LAMP packages on Linux Desktop, setting up and integrating Apache web server to work with MySQL database engine and PHP. XAMPP easily deals with the setting up and integration of all its separate components and provides a smooth to use control panel for managing Apache web server, MySQL and other programs such as Tomcat and FileZilla. You can download the XAMPP installer for your particular operating system from Apache Friends website and install it.

On Linux, you may want to install access to utilities such as phpMyAdmin which provides an interface for managing MySQL functionalities via GUI rather than using SQL and Terminal. You may, however, follow the tutorial on how to install Ubuntu Linux if you have not done so. Once you install Ubuntu Desktop, thereafter, you will be able to install the LAMP stack on it.

Choosing the Best PHP IDE

An integrated development environment (IDE) is a software application that provides comprehensive/suitable/useful facilities to computer programmers for software development. PHP IDE is thus a program that helps PHP developers to easily write PHP codes. Most suitable PHP IDEs are equipped with syntax highlighting, autocompletion, code re-factoring features, and a debugger. This means that when we write a PHP keyword that is known by the PHP interpreter, the keyword will be highlighted with a different color from the one used for regular PHP statements. The autocomplete feature gives intelligent suggestions by automatically popping up known PHP keywords as you type them. A debugger enables the programmer to track and monitor the execution of program operations such as restarting/stopping it, setting breakpoints, and altering values in memory for the purpose of spotting any malfunctioning in the code. These IDEs make debugging the PHP scripts easier since they help to differentiate keywords from ordinary words and aid in catching errors such as misspelled keywords and unclosed braces by highlighting the statements or parts of statements with errors, just to name a few. An IDE normally consists of at least a source code editor, built-in automation tools and a debugger.

There are several IDEs that can be used for PHP development. Here we choose Apache NetBeans, an IDE that primarily intended for development in Java (supports Java EE, Java SE), but which also suitably supports other languages, in particular PHP, C/C++, HTML5, and JavaScript. NetBeans is cross-platform and runs on Microsoft Windows, Mac OS X, Linux, Solaris, BSD and other platforms supporting a compatible JVM (Java virtual machine).

Apache NetBeans provides a dedicated PHP coding environment with syntax highlighting and code completion for keywords and other known information, it supports integration with PHP MVC (model–view–controller) frameworks (such as Symfony and Zend), code history showing the changes made to a file, SFTP (SSH File Transfer Protocol, or Secure File Transfer Protocol), FTP (File Transfer Protocol), and Apache SVN (Subversion) via plugins. Apache NetBeans PHP editor has native support for database systems like MySQL and can be used to work in a collaborative environment with other developers.

NetBeans Installation

We will showcase how to install the Apache NetBeans on Ubuntu Linux 18.04 LTS. The latest version of the IDE is 11.3, released on February 24, 2020. These are steps to follow in order to install NetBeans:

1. NetBeans requires the Java (version 8 or above) Development Kit (JDK) to run. There are two different Java packages in Ubuntu repositories, Java Runtime Environment (JRE), and the Java Development Kit (JDK). Running only Java programs needs JRE, which contains only the Java Runtime Environment. Java developers need to install JDK, which also includes the development/debugging tools and libraries. OpenJDK is a free and open-source implementation of the Java Platform, Standard Edition licensed under the GNU General Public License version 2.

We can install officially supported OpenJDK, currently version 11.0.6 (default OpenJDK that ships with the distribution) on Debian/Ubuntu system by running the commands below. JRE is included in the JDK package. If you need only JRE, install the default-jre package.

1. First, update the apt package index with:

  1. $sudo apt update


2. Once the package index is updated install the default OpenJDK package with:

  1. $sudo apt install default-jdk


3. Verify the installation by running the following command which will print the Java version:

  1. $java --version


This should print something like this:

  1. openjdk 11.0.6 2020-01-14
  2. OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
  3. OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing)


See references: [1] and [2]


See also Best PHP Editor.


Installing NetBeans IDE

At the time of writing this article, the latest stable version of NetBeans is version 11.3 . The easiest way to install NetBeans on Ubuntu 18.04 is by using snap packaging system.

To download and install the NetBeans snap package, open the Terminal (Ctrl+Alt+T) and run:

  1. $sudo snap install netbeans --classic


Thi process may take some time depending on the speed of your internet connection. After the NetBeans IDE has been installed on your Ubuntu desktop, you will see the following:

  1. Output
  2. netbeans 11.3 from Apache NetBeans✓ installed


To start NetBeans, type on the terminal:


A Quick Introduction to NetBeans IDE

NetBeans has the following partitions (see image below):
  • Project explorer -- this panel is used to displaying all the opened projects which are usually listed in a tree view.
  • Shortcuts tool bar -- this toolbar contains shortcuts to frequently performed tasks such as creating a new project, opening an existing project, undoing and redoing actions.
  • Startup page -- this page contains 3 tabs namely- Learn & Discover, My NetBeans and What’s New.

    Learn and Discover introduces features, showcases some demos and tutorials that can be developed in the NetBeans IDE. My NetBeans tab lists the recently opened projects, allows you to install plugins and activate the IDE features. What's New introduces you to new NetBeans IDE features.
  • Output window -- is used to display output from programs such as Java console applications. It is also used to display log and debug information.
NetBeans.png

Creating a Project with NetBeans IDE
  • Click on the create new project button on the top panel: File -> New Project.
  • Choose PHP under project category, and PHP Application under Projects then click on the Next button.
  • Enter the name of the project, click Next.
  • Set Run As to "Local Web Site (running on local web server)".
  • Set Project URL to http://localhost/phpcourse (Replace phpcourse by the name of your project). For now, we will not select any MVC framework, so click the Finish button.
  • A newly created project will be displayed in the project browser and an index.php page automatically created for you.
  • The newly created page contains some html code as shown below.
PHP_editor.png

Running PHP code


Now, let's replace the html code in the newly created page with the PHP Hello World program:

  1. <?php
  2. echo "Hello World!";
  3. ?>


Remember in the first lesson we placed our PHP program in /var/www/html, but now the default PHP file index.php we have created resides in /var/www/phpcourse. We will thus create a symbolic link, the link folder (/var/www/html) that will actually contain what the real folder (/var/www/phpcourse) has so that any file saved in the real folder will be contained in the link folder:

  1. ln -s /var/www/phpcourse/ /var/www/html/


We can verify that the link was actually created with

  1. ls -l /var/www/html/


which will output something like this:

  1. lrwxrwxrwx 1 username username  19 Mar 21 19:25 phpcourse -> /var/www/phpcourse/


Without creating a symbolic you are likely to get a 404 Not Found error:

  1. Not Found
  2. The requested URL was not found on this server.
  3. Apache/2.4.29 (Ubuntu) Server at localhost Port 80


To run the program, click on the Run Project button (green button below Tools menu) on the toolbar. A default browser will be opened with the URL http://localhost/phpcourse/index.php. The output “Hello World!” will be displayed in the browser.

<<< Previous
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Robot
Super Administrator
Senior Expert Member
Reactions: 24
Posts: 124
Joined: 7 years ago
Has thanked: 7 times
Been thanked: 7 times

#2

Read to program in PHP? Here is a PHP Programming Tutorial from freeCodeCamp by Mike Dane:

0
Post Reply

Return to “LAMP (Linux, Apache, MySQL, PHP)”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests