by Andres Baravalle
Your first step is to install the software that we are going to need to use PHP effectively - in this order:
This documentation will cover installing the software stack on Windows only. You can user WAMP distributions instead - as XAMPP or WampServer.
They are suitable as a development environment - but for production you should install the individual packages (ideally, on Linux or on another Unix-like system).
Download and install the latest stable version of Apache HTTPD from the Apache web site. You should be able to follow the links and find the right version: httpd-xyz-win32-x86-openssl-xyz.msi
(xyz will be numbers representing the Apache and OpenSSL versions).
You can use the default settings - the task shouldn't take over 15 minutes.
After you have installed the web server, try to open your defaul home page at http://localhost/.
You need to be able to install software in the system (be a "local administrator" in Windows) to be able to proceed with the installation of Apache and PHP.
If you are not a local administrator, skip to the next steps.
The main web server configuration is located in conf/httpd.conf
(we will need to modify this when installing PHP).
The log files (access_log and error_log) are located in the logs
folder.
Open your error_log
file and verify if any errors have been logged.
You can stop the server to free resources and you must restart the server after any changes in the configuration. To start/stop/restart the server, you can use the Services administration tool or the command line (net start|stop apachexyz
).
For more details, follow the Microsoft documentation.
Download and install the latest stable version of PHP from the PHP web site. Download the thread safe version, and follow this documentation: https://www.php.net/manual/en/install.windows.apache2.php
Install as an "Apache handler" and make sure that you change your httpd.conf
file as per documentation. Make sure that the DLL that you are loading matches both the version of Apache that you are using (e.g. 2.2) and they type of installation ("Apache handler"). For Apache 2.2 and PHP5, the files is php5apache2_2.dll
.
Installing PHP on Windows can be troublesome and can take anything between 10 minutes and several hours.
The main PHP configuration is located in php.ini
. You will not need to modify the file now, but you may need to modify it if you are managing your web server.
You can run PHP scripts:
You can use PHP both to write command line scripts and web pages/applications.
You should test and debug command line scripts in the proper environment; occasionally it might be convenient to debug web pages from the command line (e.g. to increase the level of verbosity without changing PHP settings).
Create a text file in your Apache root folder (htdocs
) with your notepad and call it test.php.
Include this code:
<?php
phpinfo();
?>
Restart Apache and open http://localhost/test.php.
You can run PHP scripts from the command line.
Open a command prompt and change to your Apache htdocs
folder.
Run:
c:\Program Files\php\php.exe test.php
Update paths as needed.
Seeks help! You need to complete all the previous steps before moving forward.
If, for any reason, the Apache + PHP combination doesn't work, you can still test you PHP page using the built-in web server included in PHP since version 5.4.
Copy your test.php
file in the PHP folder.
Open a terminal in the PHP folder and run:
php.exe -S localhost:8000
Then open your browser at the address http://localhost:8000/test.php
You should have already installed on your system these editors:
You'll start to use them shortly.
Do not use software as Microsoft Word or TextEdit. They are not suitable for programming.
A number of environments automatically generate your PHP code (e.g. Adobe Dreamweaver when using Behauviours).
Never, ever use automatic code generators; automatic code generators make it very hard to mantain the code, or to build on top of existing code.
Instead, you must study the PHP lexical structure and speed up your development using:
Notepad++ is a general-purpose lightweight text editor, that can be used to write code in a number of different programming languages.
Editing features include:
Additional plugins allow to extend the program and integrate further features.
Eclipse is both an editor and a generic platform used to build editors.
The original codebase was developed by IBM, and is now developed and maintained by a large community.
Eclipse:
Editing features include:
Aptana Studio is a editor built on top of Eclipse, targeting development using Python and PHP
Aptana Studio is a more complete application compared to all the ones seen in the previous slides
Open Source is software released under a license that guarantees to its users the:
Software that is not Free Software is usually called proprietary
Free Software and Open Source are synonyms used by different groups that see a different role for Free Software/Open Source
Free to use means that Open Source software can be used without restrictions:
Other editors include:
eapp-win32 (eclipse/apatana/python/php) is a package we have compiled including:
and a few other bits 'n' pieces.
aptana-studio-x |
Aptana Studio (x is version number) |
eclipse-platform-x.y-win32 |
Eclipse (x.y is version number) |
notepad++ |
notepad++ |
portable-git-x.y.z |
git (used for versioning and configuration management; x.y.z is version number) |
php5.4 | python (includes IDLE; x.y is version number) |
hello.php | your Hello World in PHP |
other files/folders |
ignore – not relevant on this module |
You can use eapp-win32 in the KD labs:
In the next activities we will be running a simple "Hello World" file in PHP
We'll create the file with all our editors and run it from the command line and from the server.
The file should just include the following line:
<?php
echo "Hello World";
?>
If you have any problems, you can find the file in C:\Program Files (x86)\eapp-win32\hello.php.
Run the existing hello.php from the command line.
Copy the existing hello.php into your Apache root folder and open it from the browser.
Set up Notepad++ to run PHP scripts using the NppExec plugin:
The start-up string is: "C:\Program Files (x86)\eapp-win32\php5.4\php.exe" "$(FULL_CURRENT_PATH)" (make sure you include the quotes)
Write your hello.php and run it!
A demo (based on Python! remember: you are using PHP) is available here.
Assuming that you are in the KD lab, we'll set up and test your development environment:
Notes:
You will have to create a project folder for Aptana Studio; there are advantages in creating the folder on your network drive
A demo (based on Python! remember: you are using PHP) is available here.
You may find start-up errors when running Aptana Studio; you can normally ignore the start-up errors.
You do not need to configure Git support; please select "Check this if you do not want to be asked again".
We are now going to run the version of Aptana Studio available in the UEL network
This is similar to running the local install, but will give you lower performance (e.g. start-up time)
The network installation might have minor problems – common ones include:
A demo (based on Python! remember: you are using PHP) is available here.
Set up Eclipse as you have done with Aptana Studio (local install)
Make sure that you configure your PHP path
Use Run -> Run to test your script
You will be able to access a copy of eapp-win32 in Z:\Win32Apps\Eclipse 2013\eapp-win32
This should be available to all computers at UEL. The disadvantage of this approach is performance – run a local copy of eapp-win32 whenever possible
Remember: eapp-win32 uses Open Source software only; that means that you can use the full software stack at home
Just download the software from here (about 580mb).
Copy in your c:\Program Files (x86) (or c:\Program Files) folder and start using it
Good! Download and install the individual components of eapp-win32 on your computer.
Make sure you download and install the Linux (or *nix) version and that it matches your architecture (32 vs 64 bits).
That's ok – we're against discrimination. Download and install the individual components of eapp-win32 on your computer
Make sure you download and install the Mac version and that it matches your architecture (32 vs 64 bits)
We would recommend that you download an install eapp-win32 on a USB stick
You will be able to use your software in any computer (including the library) with a better performance compared to a network installation
Is it still slower than a local install
Share your experience on twitter #uel #IM2801
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License