1. Trang chủ
  2. » Công Nghệ Thông Tin

PHP Application Development with NetBeans Beginner''''s Guide doc

302 912 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 302
Dung lượng 9,15 MB

Nội dung

He enjoys creating site architecture and infrastructure, backend development using open source toolsets PHP, MySQL, Apache, Linux, and others, such as LAMP, and frontend development with

Trang 2

PHP Application Development with NetBeans Beginner's Guide

Boost your PHP development skills with this step-by-step practical guide

M A Hossain Tonu

Trang 3

PHP Application Development with NetBeans

Beginner's Guide

Copyright © 2012 Packt Publishing

All rights reserved No part of this book may be reproduced, stored in a retrieval system,

or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.Every effort has been made in the preparation of this book to ensure the accuracy of the information presented However, the information contained in this book is sold without warranty, either express or implied Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book

Packt Publishing has endeavored to provide trademark information about all of the

companies and products mentioned in this book by the appropriate use of capitals However, Packt Publishing cannot guarantee the accuracy of this information

First published: August 2012

Trang 5

About the Author

M A Hossain Tonu graduated in Computer Science and Engineering from Dhaka University

of Engineering and Technology (DUET) in Bangladesh He has been a passionate developer over the past six years, has worked for leading software companies in the country, such as Somewherein and Improsys, and has developed a series of web applications, services, and solutions for foreign clients as part of the offshore software development and outsourcing team He is an agile software craftsman, who loves to code, keep himself updated with cutting-edge technologies, and play with PHP, Zend Framework, Ruby-on-Rails, JavaScript, and more He loves to moderate the local PHP community—phpXperts—and conducts seminars and workshops at different tech premises

You can reach Tonu at mahtonu@gmail.com, and his tech blog is available at

http://mahtonu.wordpress.com

It takes many people to create a book like this, and I'd like to thank some

people for their contributions to this work

First of all, I would like to thank my wife Shamima Rahman Jhumur

for her tremendous patience when I was unavailable to her I appreciate

my family, friends, and well-wishers, who continuously tolerate my

computer madness

To the people at Packt, I am much obliged: Kartikey Pandey, the man

who started the process; Dayan Hyames, for guiding me throughout;

Alka Nayak, the kind soul accepting my delays; and Lubna Shaikh,

for being such a great help

I'd also like to thank those who provided prepublication feedback, such as

Ondřej Nešpor, Tomáš Myšík and Nurul Ferdous

Lastly, I would like to dedicate this book to Hasin Hayder, the PHP mentor

Trang 6

About the Reviewers

Tomáš Myšík is a Java Software Developer working on NetBeans, on its PHP support He used to be a Java Enterprise, and PHP developer working on modern websites In his leisure time, he likes sports (especially football and ice-hockey), reading books, and of course, learning all new things related to software development

Deepak Patil is a Software Architect, Mobile Web Enthusiast, and Instructor of

Standards-Based Mobile Web Development

His initial responsibilities included the architecture, design, development, implementation, and support of web applications, especially into the LAMP stack

He has eight years of experience in the Internet industry, and specializes in LAMP

technologies and open source He has experience in all areas of application development processes, including database design, user interface, e-commerce, security, web services, optimization, and scalability

He is the Tech Lead at @netCore Solutions; is an Open Source Entrepreneur, and loves all things social, mobile, cricket, and soccer; and is a proud Indian

Deepak holds a Masters degree in Computer Applications (2004) from Shivaji University, Kolhapur in Maharashtra, India

Trang 7

of Westminster, UK He was first introduced to NetBeans IDE during his placement at a London-based Internet Service Provider In his placement role, he realized the power of NetBeans IDE to develop Real Estate Management Software, which is used by the top estate agencies in London.

After graduating, Azizur secured employment with the University of Manchester as a Web Application Developer Throughout his six years of employment with the University, he successfully used NetBeans IDE to develop a variety of internal applications Some of his most challenging projects have been to develop secure, reliable, scalable, and robust, client-facing web applications using PHP Zend Framework and MySQL database

In late 2011, he decided to pursue new pastures, and currently works for a world-class, broadcasting company in the UK, developing innovative web applications used by millions of users across the globe, where NetBeans IDE still firmly remains the tool of choice

A firm believer in philanthropy, he spends his spare time supporting philanthropic

causes, using his knowledge and expertise of open source technologies, and has helped international, non-profit organizations, such as Mercy Mission World; he is currently leading the development team at ProductiveMuslim.com He uses NetBeans IDE to develop web applications, custom WordPress themes, and plugins to support his work

His keen interest in open source software makes him a regular attendee at the Manchester WordPress User Group and wider PHP and open source community events

I would like to thank everyone who helped in tech reviewing this book You

know who you are; you have been absolutely amazing in supporting me

when I needed it most Thank you for all your help

Anthony Reid is a Software Developer, who currently works within the Information Systems Department of a London insurance brokerage firm Anthony has over 20 years of programming experience His career started in the pre-Windows era, developing database systems in DataEase, Paradox, FoxPro, and Visual Basic

For the last 10 years, he has focused on developing an array of PHP/SQL applications

covering financial risk management, workflow, and accounting solutions

Trang 8

University of Engineering and Technology (KUET), and his M.Sc degree in Computer Science and Engineering from United International University, Dhaka He is also a co-founder of CyberXpress.Net Inc, based in Bangladesh.

He has a wide breadth of technical skills and Internet knowledge, and has experience across the spectrum of online development in the service of building and improving online properties for multiple clients He enjoys creating site architecture and infrastructure, backend development using open source toolsets (PHP, MySQL, Apache, Linux, and others, such as LAMP), and frontend development with CSS and HTML/XHTML

I want to thank my loving wife, Maria Akter, for her great support

Mushfiq-E Mahabub is a Software Engineer, driven by passion

He has been writing production-level code for the last three years using open source technologies, such as LAMP, Python/Django, YII, Zend, MySQL, and MongoDB

Currently, he is working as a Platform Engineer for a new start-up

After acquiring his BSc Engineering degree in Computer Science, he participated in the development of open source software based on Python

He has been conducting different workshops and seminars on open source software since 2009 for university students

He writes technical notes at http://mushfiq.com on a regular basis

Trang 9

Support files, eBooks, discount offers and more

You might want to visit www.PacktPub.com for support files and downloads related to your book

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy Get in touch with us at service@packtpub.com for more details

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks

http://PacktLib.PacktPub.com

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library Here, you can access, read and search across Packt's entire library of books

Why Subscribe?

‹ Fully searchable across every book published by Packt

‹ Copy and paste, print and bookmark content

‹ On demand and accessible via web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books Simply use your login credentials for immediate access

Trang 10

Table of Contents

Preface 1

Why NetBeans for PHP application development? 8

Time for action – downloading the NetBeans IDE 10

Time for action – installing NetBeans step by step 13 Setting up your development environment in Windows 18 Time for action – installing XAMPP in Windows 18 Setting up your development environment in the Ubuntu desktop 21 Time for action – installing LAMP on the Ubuntu desktop 21 Setting up your development environment in Mac OS X 25 Time for action – installing MAMP in Mac OS X 26

Time for action – creating a NetBeans PHP project 31

Chapter 2: Boosting Your Coding Productivity with the PHP Editor 37

Familiarizing yourself with the base IDE features 38

Using rename refactoring and instant rename 53

Trang 11

Chapter 3: Building a Facebook-like Status Poster using NetBeans 67

Time for action – connecting with MySQL database server 73

Time for action – creating MySQL database and table 75

Time for action – creating a class, adding a constructor, and creating methods 80

Time for action – adding CSS support to the document 85 Time for action – adding jQuery support and custom JS library 89

Hatching out the status poster using PHP-AJAX 96 Time for action – adding the status input box to the interface 97

Time for action – creating status poster using JQuery AJAX 100

Debugging – the ancient art of programming 109

Time for action – installing XDebug on Windows 111

Time for action – installing XDebug on Ubuntu 113

Trang 12

Debugging the PHP source with NetBeans 115

Time for action – running a debugging session 117

Time for action – adding the expression to watch 122

Time for action – installing PHPUnit via PEAR 125

Time for action – running tests with Selenium 136

Time for action – documenting a PHP function or method 146

Time for action – documenting the PHP class and class variables 149

Time for action – installing ApiGen and configuring it with NetBeans 156

Time for action – generating documentation using ApiGen 158

Trang 13

Git – the fast and distributed version control system 169

Time for action – initializing a Git repository 170

Time for action – cloning a Git repository from GitHub via the SSH protocol 173

Time for action – staging files to a Git repository 177

Time for action – committing changes to the local repository 181

Time for action – reverting changes of the working tree 184

Time for action – fetching source code updates 186

Time for action – pulling updates from the remote repository 187

Time for action – pushing source code changes 189

Chapter 7: Building User Registration, Login, and Logout 201

Understanding the application architecture 202

Trang 14

Reviewing OOP issues 205

Time for action – creating the BaseDao class 208

Time for action – creating the User Dao class 211

Time for action – creating the ValidatorService class 216

Time for action – creating the UserService class 224

Time for action – creating the user application 233

Time for action – creating the user interface 237

Appendix A: Introducing Symfony2 Support in NetBeans 7.2 249

Downloading and integrating the latest Symfony Standard Edition 249 Time for action – integrating Symfony2 with NetBeans 249

Time for action – creating a Symfony2 project using NetBeans 250 Running Symfony2 console commands inside NetBeans 254

Time for action – creating a bundle using the Symfony2 console command 255

Trang 15

Code folding 266

Chapter 2, Boosting your Coding Productivity with the PHP Editor 269 Chapter 3, Building a Facebook-like Status Poster using NetBeans 270 Chapter 4, Debugging and Testing using NetBeans 271

Chapter 6, Understanding Git, the NetBeans way 272

Trang 16

Productivity is an important factor for a software developer A good development

environment or surrounding tools with the essence of a particular programming flavor can boost up our coding productivity and yield a quality and optimized software product In order to maintain a fast-paced development, developers seek the environment with which they feel at home Such an Integrated Development Environment (IDE) can really accelerate code implementation and be the magic wand to your project development

A good IDE is more like a Swiss army knife with crafted features It consists of:

‹ A source editor

‹ A compiler/an interpreter

‹ A debugger

‹ Database management support

‹ Version Control System

‹ Tools for Object-Oriented Programming, such as Class Browser and Object InspectorIDE, like NetBeans, comes with greater flexibility, with such features where the developer can feel at home Moreover, NetBeans is absolutely free of charge and is provided by the open source community Simply put, the IDE for PHP will facilitate your productivity from development to production, in every respect

In this book, PHP Application Development with NetBeans Beginner's Guide, you will learn

how to cover different categories of web-based applications with the help of NetBeans IDE through a couple of real-life, trendy PHP projects, and will complete the book as a confident PHP developer

Trang 17

What this book covers

Chapter 1, Setting Up Your Development Environment, guides you through the process of

NetBeans installation and sets up the PHP development environment step by step By the end

of this chapter, you will have your development environment ready on your operating system

Chapter 2, Boosting Your Coding Productivity with PHP Editor, shows how you can write

faster code using the NetBeans PHP Editor You will be introduced to killer features of the IDE, such as code completion, code templates, rename refactoring, and code generation

At the end of this chapter, you will have a full, hands-on knowledge of the editor's smart features and increased coding productivity

Chapter 3, Building a Facebook-like Status Poster using NetBeans, jumps directly to a

real-life, PHP application development that will be used to display Facebook/Twitter-like, posted status streams By the end of this chapter, you will be able to develop simple PHP applications with the NetBeans IDE

Chapter 4, Debugging and Testing using NetBeans, will explain how to debug and test a

PHP application using the IDE Topics covered in the chapter include configuring XDebug, debugging the PHP source code, testing with PHPUnit and Selenium, and code coverage

Chapter 5, Using Code Documentation, guides the developer through the process of creating

source and project documentation You will become familiar with PHPDoc standard tags and their use, to document the source code with the help of the editor Also, you will use an external document generator for the project API

Chapter 6, Understanding Git, the NetBeans Way, will show you how to use Git, a free and

open source-distributed version control system Using the IDE, you will be working on Git operations, such as initializing or cloning a repository, staging files, committing changes, reverting modifications, and remote repository operations such as fetching, pulling, and pushing, while working with branches By the end of this chapter, you will be able to be part

of a development team using the NetBeans collaborative development feature

Chapter 7, Building User Registration, Login, and Logout, deals with a professional PHP

application You will design and develop a PHP application where users can register

themselves, and after the registration they can log in to the application, view, and update their own profile, and more

Appendix A, Introducing Symfony2 Support in NetBeans 7.2, will discover the Symfony2

PHP framework support by NetBeans This introduces Symfony2's project creation, runs Symfony2 commands, and introduces bundle creation from NetBeans

Appendix B, NetBeans Keyboard Shortcuts, is a convenient reference for common NetBeans

keyboard shortcuts

Trang 18

What you need for this book

In Chapter 1, Setting up your Development Environment the Recommended system

requirements section, explains the system requirements, and the sections beginning with Setting up your development environment explains the PHP development environment for

specific operating systems In summary, you should have the following:

‹ NetBeans IDE

‹ Latest package of Apache, MySQL, and PHP

Who this book is for

The book is aimed at beginning level PHP developers who wish to develop PHP applications while taking advantage of the NetBeans functionality to ease their software development efforts and utilize the powerful features of the IDE Familiarity with NetBeans is not assumed However, a little familiarity with PHP development is expected

Conventions

In this book, you will find several headings appearing frequently

To give clear instructions on how to complete a procedure or task, we use:

Time for action – heading

What just happened?

This heading explains the working of tasks or instructions that you have just completed.You will also find some other learning aids in the book, including:

Pop quiz – heading

Trang 19

Have a go hero – heading

These set practical challenges and give you ideas for experimenting with what you

have learned

You will also find a number of styles of text that distinguish between different kinds of information Here are some examples of these styles, and an explanation of their meaning.Code words in text are shown as follows: "Set the installation folder using the

When we wish to draw your attention to a particular part of a code block, the relevant lines

or items are set in bold:

Any command-line input or output is written as follows:

sudo apt-get install lamp-server^

New terms and important words are shown in bold Words that you see on the screen, in

menus or dialog boxes, for example, appear in the text like this: "By clicking on the Next

button, you will be asked to accept the license agreement."

Trang 20

Warnings or important notes appear in a box like this.

Tips and tricks appear like this

Reader feedback

Feedback from our readers is always welcome Let us know what you think about this book—what you liked or may have disliked Reader feedback is important for us to

develop titles that you really get the most out of

To send us general feedback, simply send an e-mail to feedback@packtpub.com,

and mention the book title via the subject of your message

If there is a book that you need and would like to see us publish, please send us a note in the

SUGGEST A TITLE form on www.packtpub.com or e-mail suggest@packtpub.com

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you

to get the most from your purchase

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly

to you

Trang 21

Although we have taken every care to ensure the accuracy of our content, mistakes do happen If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us By doing so, you can save other readers from frustration and help us improve subsequent versions of this book If you find any errata, please report them by visiting http://www.packtpub.com/support,

selecting your book, clicking on the errata submission form link, and entering the details

of your errata Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media At Packt,

we take the protection of our copyright and licenses very seriously If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy

Please contact us at copyright@packtpub.com with a link to the suspected pirated material

We appreciate your help in protecting our authors, and our ability to bring you valuable content

Questions

You can contact us at questions@packtpub.com if you are having a problem with any aspect of the book, and we will do our best to address it

Trang 22

Setting up your Development

Environment

NetBeans is a free and open source Integrated Development Environment

(IDE), which complies with multiple programming languages For a long time

it has been the editor of choice to major developer communities Along with

the growing market demand, NetBeans has integrated the PHP development

features since NetBeans 6.5 (November 2008), and these days, it has become

one of the most popular IDEs for the PHP community

In this chapter we will discuss:

‹ Why NetBeans for PHP application development?

‹ Downloading the NetBeans IDE

‹ Step-by-step NetBeans installation

‹ Setting up your PHP development environment

‹ Creating a NetBeans project

So let's get on with it

Trang 23

Why NetBeans for PHP application development?

NetBeans IDE facilitates our daily PHP application development activities with the following:

‹ Creating and managing projects: The IDE for PHP enables us to create PHP

projects, and helps to grow the project It can perform project-related settings and operations; that is, creating documentation for the project, testing the project, and

so on

‹ Editing features for the source code: The code editor comes with an exciting

collection of source-editing capabilities within the PHP project scope It empowers faster code writing with the following features:

‰ Syntax highlighting enables highlighting PHP syntax in project files.

‰ Code folding enables the folding and unfolding of selected classes and

method codes within the current file

‰ Navigation helps to explore classes and methods in the current PHP file.

‰ Code templates help in using predefined code snippets.

‰ Code completion shows the code's auto completion list.

‰ Parameter hints give information about the formal parameters of a method

where the method is called

‰ Smart indent provides auto formatting while code pressing.

‰ Formatting provides auto code formatting in the current file.

‰ Bracket completion adds/removes paired quotes, parentheses, and braces

during code writing

‰ Mark occurrences marks all the occurrences of a code string within the

opened project files

‰ Error detection shows the PHP parsing error immediately after typing is

finished

‰ Pair matching highlights matched pair of quotes, braces, parentheses, and

so on

‰ Semantic highlighting identifies the keywords, method names, call, unused

variables, and so on

‰ Go to declaration sends the cursor to where the chosen type is declared.

Trang 24

‰ Instant rename renames all occurrences of a variable within its scope.

‰ Spell checker shows spelling mistakes and corrections.

‰ Code documentation helps with an automatic documentation structure.

‹ Deploying the project: Provides synchronization within the PHP project content,

with remote server content

‹ Database and services: Provides support for database management and web

services

‹ SCM tools: Provides source code management tools, such as Git, Subversion, CVS,

and Mercurial, built-in for source code versioning, tracking changes, and so on

‹ Running PHP scripts: Enables the parsing of PHP scripts, and yields output within

the IDE without going to the browser

‹ Debugging the source code: You can inspect local variables, set watches, set

breakpoints, and evaluate the code, live You can also perform command-line debugging, and check the PHP output in the IDE without going to the browser, which provides competence for remote debugging

‹ Supporting PHP frameworks: It also offers the support for popular PHP frameworks,

such as the Zend Framework and Symfony

Comparison of integrated development environments for PHP can be found at http://en.wikipedia.org/

wiki/Comparison_of_integrated_development_

environments#PHP

Recommended system requirements

Before we proceed with downloading the latest version, let's have a look into the

recommended system requirements of various platforms for installing and running

the NetBeans IDE:

‹ Microsoft Windows XP Professional SP3/Vista SP1/Windows 7 Professional:

‰ Processor: 2.6 GHz Intel Pentium IV or equivalent

‰ Memory: 2 GB

‰ Disk space: 1 GB of free disk space

Trang 25

‰ Disk space: 850 MB of free disk space

Downloading the NetBeans IDE

NetBeans can be your daily IDE for development that will assist you in increasing your coding productivity It is a free-of-cost, open source IDE, which can be downloadable for different technologies, including Java, C/C++, PHP, and so on, and platforms such as Windows, Linux, Mac OS X, or even OS-independent bundles Moreover, you may download the IDE only for PHP technology, or for all technologies in an installer package

Again, if you are already using the IDE for the development of Java, C/C++, and so on, then you may skip this download, and the installation section, and jump directly to the section

named Adding PHP as a plugin to an already existing NetBeans installation.

Time for action – downloading the NetBeans IDE

Go through the following steps to download the NetBeans IDE:

1 Visit http://netbeans.org/downloads/ in order to download the latest NetBeans release The download page will automatically detect your computer's operating system, and will let you download the operating, system-specific installer.Note that you can add or remove packs or plugins later, using the IDE's plugin manager Also, you can select "OS-independent ZIP" if you want to avoid installation Again, NetBeans is a must-have IDE for those programmers who work with multiple programming language platforms Currently, NetBeans IDE supports various

development platforms—J2SE, J2EE, J2ME, PHP, C/C++, and so on

Trang 26

Next, we are going to download the PHP bundle, as shown in the screenshot above

2 After clicking on the Download button, the page will be redirected to an auto

download, along with a direct download link, as shown in the following screenshot:

Trang 27

As you can see, your download starts automatically; Firefox users should see a window to save the file, which will appear as follows:

3 Save the file onto your disk space

What just happened?

We just downloaded the installation file for the NetBeans PHP bundle The PHP bundle provides tools for PHP 5.x development, and Zend and Symfony framework support If

you click on the All download option, you'll have the installation file for all mentioned

technologies and during installation you will be able to choose exactly what tools and runtimes to install So, now we are ready launch the installation wizard

Installing NetBeans

Installing NetBeans is pretty much easier with the installation wizard, which guides the user with the required steps or configurations Those who are already using NetBeans for other technologies, such as Java or C/C++, can skip this section and jump directly to the section

named Adding PHP as a plugin to an already existing NetBeans installation.

The PHP and C/C++ NetBeans bundles only require the Java Runtime Environment (JRE) 6 to be installed However, if you are planning to use any of the Java features, you need JDK 6 or JDK 7

Trang 28

Time for action – installing NetBeans step by step

In this section, we will install the NetBeans IDE step by step, for Windows OS—that is, Windows 7 In order to install the software, you need to run the installer and proceed with the followings steps:

1 Run or execute the installer The first step will look similar to the following screenshot:

Trang 29

2 By clicking on the Next button, you will be asked to accept the license agreement:

3 The next step will ask you for the installation location for NetBeans and the JRE, with some default program file path:

Trang 30

Note that JRE is the Java software for your computer, or the Java Runtime

Environment, which is also referred to as the Java Virtual Machine (JVM)

JRE will be installed as well

4 Set the installation folder using the file browser, and click on the Next button

The next screenshot shows the total installation size:

5 If everything is set, start the installation by clicking on the Install button, which will

start the installation process

Trang 31

6 After everything is installed correctly, you will see the finish wizard, as shown in the following screenshot:

7 You may check or uncheck the Contribute to the NetBeans project by providing

anonymous usage data checkbox, as per your wish to participate or not Note that

it will send project-specific usage data to netbeans.org, so read the on-screen instructions carefully before checking it Complete the installation by clicking on the

Finish button Now, go to your OS's Program menu or into the directory where you have

installed the IDE to be run The IDE initializes with a splash screen, as shown below:

Trang 32

8 Finally, the running IDE looks similar to the following screenshot:

What just happened?

Now that we have the IDE up and running, we can go on to explore setting up the development environment with various operating systems

In the next section, we will configure our PHP development environment on various

operating systems We will use the latest Apache-MySQL-PHP package installer, that is LAMP, XAMPP, and MAMP, for corresponding operating systems

Adding PHP as a plugin to an already existing NetBeans installation

If you want to add functionality to your NetBeans IDE configuration, use the NetBeans Plugin Manager For example, assume that you have already been running the NetBeans IDE for the Java or C/C++ pack You then decide that you want to try out the PHP functionality To do

this, go to the NetBeans Plugin Manager from the IDE (choose Tools | Plugins), and add the

PHP pack to your existing installation

Trang 33

Multiple installation support

Multiple installations of NetBeans IDE 5.x, 6.x, and 7.x can coexist with the latest version on the same system You do not have to uninstall the earlier versions in order to install or run the latest one

If you have an earlier installation of the NetBeans IDE, you can choose whether or not to import the user settings from the existing user directory when you run the latest IDE for the first time

Have a go hero – adding or removing features from NetBeans

So, you have NetBeans up and running on your computer Now, add more features or remove unnecessary features, to or from your installed NetBeans, and check the newly added feature(s) inside the IDE You may try the plugin manager to do this

Setting up your development environment in WindowsInstead of installing and configuring Apache, MySQL, and PHP individually, we will use the XAMPP package to have all of them installed and configured automatically We will download and install the latest XAMPP package (v 1.7.7), which includes the following:

Time for action – installing XAMPP in Windows

The following steps will download and install the XAMPP package:

1 We will download the installer for the latest XAMPP package from:

Trang 34

4 After completing the installation process successfully, you will be able to proceed with further steps Open the XAMPP control panel from your operating system's

Start | Programs | XAMPP.

Svc checkboxes indicate that the module was installed as a Windows service, and

hence will start with the Windows startup, or you can check them to be running as

a service If you ever need to restart your Apache web server, use the Stop/Start button besides Status of Apache.

5 Now, check your XAMPP installation Visit the URL http://localhost from your web browser; the XAMPP welcome page looks similar to the following screenshot:

Trang 35

6 From the left, click phpinfo() to check the PHP release and the installed

components that you have configured:

7 Click on the Status menu under the Welcome menu to check the installed tools

status; the activated green status beside corresponding columns means that you are running Apache, MySQL, and PHP successfully:

Trang 36

What just happened?

We have successfully installed and run the XAMPP package on our system We have the XAMPP control panel in order to control the installed services and we also have a web interface to manage MySQL databases

Have a go hero – securing your XAMPP installation

XAMPP is not meant for production use, but only for developers in a development

environment XAMPP is configured to be as open as possible, and it allows the web

developers to fetch anything they want For development environments, this is great But, in a production environment, it could be fatal So, you need to secure your

XAMPP installation with the help of the A matter of security section, at

http://www.apachefriends.org/en/xampp-windows.html

To display errors in the development environment, update the loaded php.ini file to set display_errors = On, and do the reverse display_errors = Off for the production environment

Setting up your development environment in the Ubuntu desktop

Linux, Apache, MySQL, and PHP (LAMP) are some of the most common web hosting

platforms So, it's a perfect environment for you to build and test your website code

In this section, we will have our own LAMP set up, configured, and running easily into our Ubuntu 12.04 desktop

Time for action – installing LAMP on the Ubuntu desktop

Follow the steps listed here in order to install the LAMP package in Ubuntu:

1 Instead of installing each item separately, we will go with installing the LAMP server in

a package in Ubuntu, which is fairly simple, along with a single terminal command:

sudo apt-get install lamp-server^

The apt-get command is a powerful command-line tool, which is used to work

with Ubuntu's Advanced Packaging Tool (APT) performing functions such as the

installation of new software packages, upgrading the existing software packages, updating of the package list index, and even upgrading the entire Ubuntu system

Trang 37

sudo, used to invoke the current user with the power of a super user and a caret (^) symbol, is placed after the package name to indicate that tasks are being performed together.

2 This command will cause the LAMP package to start installing immediately along with the latest PHP5, Apache 2, MySQL and PHP5-MySQL software By default, Apache 2 and MySQL install as a service, and your document root will be at /var/www/, and an index.html file will be at /var/www/

3 Both Apache and MySQL should be running However, if required, you may start Apache by using the servicestart command as follows:

sudo service apache2 start

You can stop Apache by using the following command:

sudo service apache2 stop

4 Now, let's check the LAMP installation Point your browser to http://localhost/, and you will see the default, Apache 2 landing page, as shown in the following screenshot:

This means that your Apache 2 web server is running You can still check these service statuses as follows:

sudo service apache2 status

The previous command will give you the following output:

Apache is running Process #

Trang 38

5 Again, to check the MySQL status, simply run the following command:

sudo service mysql status

The following output will be displayed:

mysql start/running Process #

6 To check the PHP installation, simply create a file named test.php in /var/www/, with the following line:

<?php phpinfo(); ?>

You can create a new file from the terminal by using touch test.php or using gedit application, then editing the file, and saving it

7 Now, point your browser to http://localhost/test.php, and you will see the installed PHP and the component's configuration details:

Steps 8 to 12 are optional, as we install phpMyAdmin in these steps

Trang 39

8 Though we can maintain our databases using NetBeans, we still need to maintain the MySQL database functionalities using a web-based interface To do this, we may use phpMyAdmin.

sudo apt-get install phpmyadmin

phpMyAdmin will be installed with this command, and during the installation, you will receive a blue window asking which server you want to use—apache2 or lighttpd Choose apache2, and click on OK to continue with the installation

Note that during the installation, you may be asked to configure phpMyAdmin for database-config, passwords, and so on

9 After the installation point, open your browser with http://localhost/

phpmyadmin/, and you will be able to view a phpMyAdmin landing page,

as shown in the following screenshot:

Trang 40

10 If you receive a 404 error at http://localhost/phpmyadmin/, then you need

to manually set up phpMyAdmin under Apache, by modifying /etc/apache2/apache2.conf using gedit (the official text editor for the GNOME desktop):

sudo gedit /etc/apache2/apache2.conf

11 gedit will open the file in a graphical mode, and will add the following line inside apache2.conf at the bottom:

Include /etc/phpmyadmin/apache.conf

12 Now, restart the Apache server to make the changes effective:

sudo service apache2 restart

Refresh your browser, and you will now have the same phpMyAdmin login screen as shown in the previous screenshot

What just happened?

The PHP development environment in the Ubuntu desktop has been set up successfully The installation of the LAMP server was really a charm with a single command We learned how

to stop or restart services such as Apache and MySQL, along with checking their status.Also, we have optionally installed phpMyAdmin for managing databases via the web

interface Note that phpMyAdmin is not meant for production use, but only for developers,

in a development environment

Have a go hero – displaying errors

As we have crafted our environment for development, PHP error messages will be very helpful for us to resolve them By default, PHP error messages are turned off in your LAMP installation You can enable the error messages displaying from the loaded php.ini file (see phpinfo) by modifying the line that contains display_errors Note that any changes to php.ini requires the Apache 2 server to restart

Setting up your development environment in Mac OS X

As we are interested in setting up AMP in a bundle, a MAMP package could be a good one for Mac OS X

Ngày đăng: 29/03/2014, 17:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w