--=REKLAMA=--
Ta strona wymaga przetłumaczenia lub jest w trakcie tłumaczenia! Pomoc jest mile widziana. Ostatnio edytowane przez Bazyl (dyskusja. Data edycji: Thu, 11 Jun 2009 22:39:01 +0000
Uwaga: Ten artykuł został skorygowany w styczniu 2009 r., by uwzględnić nowe wydania - Eclipse PDT w wersji 2.0 oraz XAMPP w wersji 1.7, z włączonym programem XDebug. To upraszcza instalację. Uwaga: Jeśli masz zainstalowane Eclipse PDT w wersji 1.0 z XDebug, wystarczy zainstalować Eclipse PDT 2.0 w nowym folderze i połączyć z istniejącym obszarem roboczym (and point to your existing workspace.)
Ten artykuł przedstawia szczegółową instrukcję konfiguracji Twojej stacji roboczej dla projektanta Joomla!. Zwróć uwagę, że istnieje wiele możliwych konfiguracji środowiska projektowego dla programistów Joomla!. Dowolne środowisko z obsługą Apache, MySql, PHP oraz Subversion będzie dobrym rozwiązaniem dla projektantów rozszerzeń.
Dokument przedstawia instrukcję krok po kroku, objaśniającą jak skonfigurować IDE Eclipse. Przykłady i ilustracje odnoszą się do Windows XP, ale podstawowe kroki w systemie Linux są takie same.
XAMPP jest poręcznym pakietem instalującym serwer Apache, PHP, XDEBUG oraz MySQL. Umożliwia stworzenie na komputerze lokalnym środowiska potrzebnego do uruchomienia Joomla!. Najnowsza wersja XAMPP jest dostępna na stronie projektu. Można pobrać pakiet na dowolną z platform - Linux, Windows, Mac OS X oraz Solaris. Pobierz odpowiednią dla swojego systemu.
Ważne uwaga odnośnie XAMPP and Skype: Apache oraz Skype nasłuchują, korzystając z portu 80 bądź alternatywnego. Jeśli korzystasz ze Skype, wybierz z menu Skype kolejno: Narzędzia → Opcje → Zaawansowane → Połączenia, wyłączamy opcję Użyj portów 80 oraz 443 jako alternatywnych dla połączeń przychodzących [Use 80 and 443 as alternatives for incoming connections]. Jeśli serwer Apache startuje przed Skype, problem może się nie pojawić, ale bezpieczniej wyłączyć tę opcję w Skype.
Instalacja w Windows jest bardzo prosta. Uruchamiamy plik instalacyjny (na przykład "xampp-win32-1.7.0-installer.exe") i wykonujemy instrukcje podane na kolejnych ekranach. Szczegółowa instrukcja instalacji znajduje się tutaj lub w artykule Instalacja XAMPP albo Instalacja XAMPP.
W Windows zalecana jest instalacja w katalogu "c:\xampp" (a nie w "c:\program files"). Jeśli zainstalujesz w tym katalogu, Twój Joomla! (i inne katalogi lokalnych witryn) umieszczamy w katalogu "c:\xampp\htdocs". (Zgodnie z konwencją, wszystkie strony internetowe umieszczane są w katalogu "htdocs".)
Jeśli masz kilka serwerów http (np. IIS), musisz w konfiguracji XAMPP zmienić port nasłuchujący. Zmodyfikuj w pliku <xamppDir>\apache\conf\httpd.conf linię Listen 80 na Listen [numerportu] (np: "Listen 8080").
Pobierz najnowszą wersję dostępną na stronie projektu XAMPP Po pobraniu po prostu wpisz w wierszu poleceń:
sudo tar xvfz xampp-linux-1.7.1.tar.gz -C /opt
Aby wystartować xampp, wpisz polecenie:
sudo /opt/lampp/lampp start
Do pakietu XAMPP dla Linuksa nie włączono debuggera XDebug PHP. Aby zainstalować XDebug w systemie Debian lub Ubuntu:
- Zainstaluj pakiet build-essential:
sudo apt-get update sudo apt-get install build-essential sudo apt-get install autoconf
- Pobierz ze strony pakiet projektanta dla swojej wersji XAMPP i rozpakuj go do swojej istniejącej instalacji:
sudo tar xvfz xampp-linux-devel-1.7.1.tar.gz -C /opt
- Build XDebug:
wget http://xdebug.org/files/xdebug-2.0.4.tgz tar xzf xdebug-2.0.4.tgz cd xdebug-2.0.4/ /opt/lampp/bin/phpize
W efekcie na Twojej konsoli pojawi się następujące komunikat:
Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519
./configure --with-php-config=/opt/lampp/bin/php-config make sudo make install
Then the output will be this. please monitor the directory specified.
Installing shared extensions: /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/
Create a folder in your temp folder that will holds the data file generated by XDebug:
sudo mkdir /opt/lampp/tmp/xdebug sudo chmod a+rwx -R /opt/lampp/tmp/xdebug
Po zainstalowaniu XMAPP-a sprawdź poprawność działania - otwórz przeglądarkę i przejdź na stronę "http://localhost". Powinien zostać wyświetlony ekran powitalny, jak na ilustracji poniżej.
Wybierz z lewego menu odnośnik nazwany "phpinfo()", który otwiera stronę z informacją o konfiguracji PHP, jak poniżej:
W tym momencie mamy zainstalowany pomyślnie XAMPP. Zwróć uwagę na wyróżnienie na ilustracji "Loaded Configuration File". Poddamy redakcji ten plik w następnej części, aby skonfigurować XDebug.
Dla Windows Poczynając od wersji 1.7, XAMPP posiada włączony PHP XDebug, ale wymaga on konfiguracji. W tym celu poddajemy edycji plik "php.ini". "Loaded Configuration File" [Wczytany plik konfiguracyjny] na zdjęciu powyżej wskazuje, który plik jest używany. W Windows jest to zwykle plik "c:\xampp\apache\bin\php.ini".
Ważna uwaga dla użytkowników Windows Vista: W kwietniu 2009 r. (XAMPP version 1.7.0), plik "php_xdebug.dll" włączony do instalacji XAMPP nie działa z Windows Vista. Symptomem problemu jest zatrzymanie serwera Apache podczas ładowania XDebug. Aby rozwiązać ten problem, pobierz XDebug w wersji "Xdebug 2.0.0 / 5.2 VC6" z witryny XDebug. This will download a file calledphp_xdebug-2.0.0-5.2.2.dll
. Save this file in the extensions folder (for example,c:\xampp\php\ext
) and change the php.ini file to point to this file, as shown below. With this file, XDebug works correctly with Vista, including 64-bit.
Aby skonfigurować XDebug, dokonujemy w pliku php.ini następujących zmian:
implicit_flush = On
[XDebug] ;; Only Zend OR (!) XDebug zend_extension_ts="C:\xampp\php\ext\php_xdebug.dll" xdebug.remote_enable=true xdebug.remote_host=localhost xdebug.remote_port=10000 xdebug.remote_handler=dbgp xdebug.profiler_enable=1 xdebug.profiler_output_dir="C:\xampp\tmp"
W przypadku Windows Vista, konieczne jest jeszcze wczytanie odpowiedniego pliku, co konfigurujemy w pierwszej linii (oczywiście, plik należy umieścić w katalogu \php\ext\):
zend_extension_ts="C:\xampp\php\ext\php_xdebug-2.0.0-5.2.2.dll"
Linux
We will edit the "php.ini" file to configure XDebug. The "Loaded Configuration File" in the screenshot above tells you what "php.ini" file is being used. For Linux, it will be something like "/opt/lampp/etc/php.ini".
We need to edit this file to configure XDebug as follows:
implicit_flush = On
;xDebug Configuration starts zend_extension = /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so xdebug.profiler_output_dir = "/tmp/xdebug/" xdebug.profiler_enable = On xdebug.remote_enable=On xdebug.remote_host="localhost" xdebug.remote_port=10000 xdebug.remote_handler="dbgp" ;xDebug Configuration ends
Now, we need to check that XDebug is installed correctly. To do this, we need to re-start XAMPP. In Windows, we can just browse to the "c:\xampp" folder in Windows Explorer and double-click the program "xampp-control.exe" to open the application shown below.
Press the "Stop" button for "Apache". The button with then read "Start". Press "Start" for Apache and wait a few seconds and the green "Running" message will again display. Then press "Exit" to close the application.
In Windows, if you get "ERROR: MySQL service not started [-1]", you may be able to correct this by going to c:\xampp\mysql and running mysql_uninstallservice.bat followed by mysql_installservice.bat.
In Linux, to restart XAMPP execute the command
sudo /opt/lampp/lampp restart
Once XAMPP has been restarted, open a browser and navigate to "http://localhost" to display the XAMPP welcome message. Press the "phpinfo()" link again to display the PHP information screen. Scroll down to the lower part of the screen. You should see a section for "XDebug" as shown below.
Look at the settings you entered in the "php.ini" file above. You should see these same settings in the xdebug display, as shown below.
At this point, XDebug is set up correctly.
Eclipse został napisany w Java, dlatego przed instalacją Eclipse, upewnij się, że uruchomiona jest najnowsza wersja Java. Note that many Linux distributions include third-party Java runtimes (or JVM's for "Java Virtual Machine"), some of which don't work with Eclipse. The safest thing is to make sure you are running the Sun JRE (Jave Runtime Environment). Najnowszą wersję Java można pobrać ze strony www.java.com. Jeśli już masz zainstalowaną najnowszą wersję Sun JRE (przykładowo 1.5 or 1.6), możesz opuścić ten krok.
Kolejny krok to pobranie Eclipse. Najłatwiejszym sposobem jest instalacja paczki "wszystko w jednym" - Eclipse PDT (PHP Development Tools), którą można pobrać tutaj. Dostępne są wersje dla Windows, Linux, oaz Mac OS X. Gdy wskażesz pakiet, który chcesz pobrać, pojawi się prośba o wybór serwera lustrzanego - wskaż np. najbliżej położony. Po chwili na dysku komputera zacznie się zapisywanie pliku archiwum wielkości około 120mb np. "pdt-all-in-one-S20080601_RC2-win32.zip".
Instalacja Eclipse jest bardzo prosta - rozpakuj pakiet archiwum do docelowego katalogu za pomocą ulubionego programu dekompresującego. Windows Explorer nie jest odpowiednim do tego celu. Zastosuj np. ???
Stwórz katalog docelowy, np. "c:\eclipse_php" i rozpakuj do niego archiwum. Po rozpakowaniu otrzymasz katalog nazwany eclipse, a w nim 5 folderów i sześć plików.iles.
Eclipse używa domyślnej maszyny wirtualnej Java JVM zainstalowanej w systemie. Wersja dla Windows odnajduje lokalizację JRE (zwykle Sun) za pomocą wpisów w rejestrze. W niektórych dystrybucjach Linuksa domyślna JVM może nie działać poprawnie z Eclipse. W takim przypadku możesz wykorzystać plik eclipse.ini w folderze eclipse, aby wskazać ścieżkę dostępu do zainstalowanej w systemie wersji Java JVM z Sun, w następujący sposób:
-showsplash org.eclipse.platform --launcher.XXMaxPermSize 512M -vm /usr/lib/jvm/java-1.5.0-sun/jre/bin/java -vmargs -Xms512m -Xmx512m
Note that the path to the JVM goes on the line below the "-vm". Also note that the file ends with a blank line.
At this point, you should be able to start up Eclipse. Just find the "eclipse.exe" file inside the eclipse folder and double-click to execute it. In Linux: /path/to/your/eclipse/folder/eclipse
Alternatywnie możesz zainstalować Eclipse ze środowiskiem phpEclipse, korzystając z EasyEclipse for PHP. To rozwiązanie zawiera wszystko, czego potrzebujesz (włącznie z Subclipse) i łatwo instaluje się na większości platform. Kolejne instrukcje nie są przydatne w instalacji EasyEclipse dla PHP.
Podczas pierwszego uruchomienia Eclipse (przejdź do katalogu docelowego i uruchom eclipse.exe) pojawi się widoczne na ilustracji poniżej okno dialogowe:
Zanim zaczniesz korzystać z Eclipse, musisz stworzyć perspektywę - przestrzeń roboczą (workspace). Jest to najogólniej folder, w którym Eclipse przechowuje wszystkie pliki i informacje o projektach. Ponieważ będziemy pracowali nad projektami sieciowymi, chcemy, żeby one były widoczne dla XAMPP-a. Dlatego tworzymy katalog roboczy w folderze "c:\xampp\htdocs" czy - w przypadku Linuksa w folderze "/opt/lampp/htdocs".
Naciśnij przycisk Przeglądaj, przejdź do katalogu "c:\xampp\htdocs" albo "/opt/lampp/htdocs" i naciśnij przycisk New Folder. Nazwij nowy katalog np. "joomla_projekt" i upewnij się, że taka sama nazwa pojawiła się w polu "Folder. (Możesz kliknąć jakikolwiek inny folder, a następnie kliknąć folder nowo utworzony). Ekran powinien wygllądać njak na ilustracji poniżej.
Naciśnij OK. Powrócisz do okna wywołującego przestrzeń roboczą, które widać poniżej:
Zanim naciśniesz OK, zaznacz pole wyboru Używaj domyślnie i nie pytaj więcej', aby przyspieszyć uruchamianie programu.
Być może zobaczysz ekran powitalny. Zamknij go, a zobaczysz zwykły ekran roboczy Eclipse, jaki widać poniżej:
W tym momencie Eclipse jest zainstalowane.
Pierwsze, co musimy zrobić, to poinformować Eclipse o zainstalowanym wcześniej XDebug. Wybierz z paska nawigacyjnego Window/Preferences:
Zostanie otwarte okno dialogowe Preferencje. Rozwiń węzeł PHP z lewej strony i wybierz opcję Debug, aby wyświetlić poniższy ekran:
Zauważ, że pole wyboru Break at first line jest zaznaczone. W ten sposób powodujemy, że debuger zawsze zatrzyma się lub zawiesi wykonanie w pierwszej linii kodu. Przekonamy się o tym później, gdy uruchomimy debugger.
Na pierwszej rozwijanej liście wybierz XDebug jako debugger PHP. Możesz otrzymać poniższy komunikat:
Zignoruj ją, naciśnij OK (NIe będziemy zmieniać teraz portu).
Aby zapewnić zgodność z ustawieniami w php.ini, naciśnij odnośnik Configuredla debugera PHP, aby wyświetlić poniższy ekran:
Zaznacz linię XDebug i naciśnij odnośnik Configure, aby wyświetlić poniższy ekran:
Zmień numer portu na 10000, jak widać poniżej, tak, aby odpowiadał ustawieniu w php.ini (tam zmieniłem również numer portu dla debugera Zend na 10001 po to, aby uniknąć błędu powodowanego przypisaniem portu 90000.
W niektórych systemach może się zdarzyć bład Javascript, sygnalizowany komunikatem:A Runtime Error has occurred. Do you wish to Debug? Line: 1 Error: Syntax error.W takim przypadku możesz wyeliminować ten komunkat, zmieniając ustawienie "Output Capture Settings / Capture stdout" z "copy" na "off".
Następnie musimy skonfigurować niektóre opcje. Wybierz z menu pozycję Window → Preferences, rozwiń węzeł PHP i Debug oraz zaznacz Workbench Options:
Zmień ustawienia, jak widać powyżej. Poeksperymentuj, aby wybrać odpowiednie dla siebie.
Następnie wybierz pozycję HP Servers, aby wyświetlić poniższy ekran:
Wybierz Default PHP Web Server (tylko jeden na liście) i naciśnij przycisk Edit, aby otworzyć okno widoczne poniżej:
Pamiętasz, że utworzyliśmy nasz katalog roboczy, nazwany "joomla_projekt" w katalogu "c:\xampp\htdocs". Zatem URL do naszych projektów musi zawierać nazwę katalogu "joomla_projekt" (na przykład http://localhost/joomla_projekt/Projekt_test/test.php. Jeśli zmienimy tutaj ścieżkę, Eclipse będzie tworzyć URL automatycznie. Uzupełnij wiec pole .... jak pokazano powyzej i naciśnij OK.
Let's do one final configuration setting, which only applies if you are running Windows. As you may know, Windows and Linux use different characters to terminate lines in text files. Since the Joomla! source code repository is on a Linux machine, we need to tell Eclipse to create Linux-style patch files. To so this, we'll navigate to Window / Preferences and expand the General tree and select "Workspace". The screen below will display.
Make two changes. Select Other / UTF-8 for the Text file encoding and Other / Unix for the New text file line delimiter, as shown above. Press OK.
At this point, Eclipse is set up and we can start working with PHP files.
Now we finally get to have some fun. We're going to write a simple PHP script and run and debug it to test that Eclipse is set up correctly. If you are already familiar with Eclipse, you can just skip over this section. If not, we'll go through some basics.
First, some quick Eclipse terminology. In Eclipse, we talk about the workbench, perspectives, and views. The workbench is just the whole screen. It has an edit area, where we will edit our PHP files, and a series of views around the outside. A view is an area that displays information about a file or some other resource. A perspective is just a pre-packaged layout of views designed for a specific purpose. When we're writing PHP programs, two perspectives are of interest: the PHP perspective and the PHP Debug perspective.
Let's open the PHP perspective. We can select Window / Open Perspective / PHP, as shown below.
Plik:Php perspectieve menu.png
Now the workbench displays a different set of views, including the PHP Explorer, in the upper left, and three views in the lower left. Note that Eclipse has pretty good Help, which you can access by pressing F1 or selecting Help / Help Contents from the menu. The screen below shows some of the contents available, including Getting Started, Basic Tutorials, and other useful information.
Remember that we created a workspace when we launched Eclipse. Before we can write any code, we need to create a project. A project stores a group of related program files. For example, the entire Joomla! application will be one project. We're going to create a test project that we can use to test our setup. We'll select the menu File / New / PHP Project, as shown below.
This will open the first screen in the new project wizard, shown below. Enter the project name, in this case "Test Debug", and press Finish.
Our new project will now show in the PHP Explorer view.
Next, we need to create a PHP file. Select the "Test Debug" project, right click, select New / PHP File, as shown below.
Press the Browse button and select the "Test Project" for the source folder. The New PHP File wizard will display, as shown below. Enter "test.php" for the file name, and press Finish.
An empty PHP file will now display in the editor. Enter the code shown below, and press the Save button in the upper left toolbar to save the "test.php" file.
Now, we're going to execute the script. We'll select the file "test.php" and right-click and select Run As / PHP Web Page, as shown below.
The script will be run in your default browser, and should display as shown below.
If your php files are set by default to open in a text editor, you may get an error. If so, go to Window/Preferences/General/Web Browser and explicitly select your preferred option.
Note that the "phpinfo()" command displays information about your PHP configuration. This is the same screen we saw earlier, when we clicked on the "phpinfo()" link in the XAMPP home page.
Now, let's try debugging this script. Again, select the "test.php" file and right-click, but this time select "Debug As / PHP Web Page", as shown below.
This time, the browser opens and suspends. (Note: If Eclipse does not suspend at the first line, try closing Eclipse and re-starting it.)
Go back to Eclipse and open the PHP Debug perspective by selecting Window / Open Perspective / PHP Debug, as shown below.
Plik:Open debug perspective.png
This opens the Debug Perspective, with the "test.php" file suspended, as shown below.
Recall from earlier that the "Break at first line" option was selected. This is why the debugger has suspended here, on the first line in our program.
There is a lot going on in this screen. The Debug view in the upper left shows the "frame" information. In this case, we are suspended on line 2. The editor window is now in the middle of the screen. A small blue arrow shows where the program is suspended.
In the upper right is the Variables view. This shows the variables that are in scope at this point in the program.
The toolbar in the Debug perspective is important. The tools are labeled below.
If you are familiar with debuggers from other IDEs, these commands will probably be familiar. If not, you can read more about it in the Eclipse help documentation and experiment on your own.
To finish, let's press the Step Over button. The Debug view and editor now show that we are on line 3. Note that this means that we are about to execute line 3. Also, note the change in the Variables view. Now the variable $mytest has a value of "this is a test" because line 2 has now executed.
Press Step Over again. Now we're on line 4. Look at the browser window. It should now say "this is a test", since now line 3 has executed. Press Step Over again and look at the browser window. Now it shows the output of "phpinfo()".
Finally, press Resume. Notice that the program is no longer suspended and the browser no longer shows that it is waiting to complete the page. The script has completed, but our debugger session is still running.
To close the debugger, select the "Remote Launch" in the Debug view and press the Terminate button. Two things happen. In the browser, a new window launches showing a terminate message. In Eclipse, the PHP perspective automatically displays. This is because we set this in the Debug preferences.
Now we had to manually open the Debug perspective, which is an extra step. We can tell Eclipse to do this automatically for us. We just go to Window / Preferences / Run/Debug / Perspectives, select "PHP Web Page", and check "Always" for "Open the associated perspective when launching", as shown below.
Plik:Php debug preferences.png
At this point, the XDebug is working correctly in Eclipse.
Before we can start coding in Joomla!, we need to be able to work with the Subversion (SVN) source code repository. Subversion is a third-party plugin for Eclipse, so we need to use the Eclipse Update Manager to install it. To do this, navigate to Help / Software Updates, as shown below.
Plik:Eclipse help software updates.png
The Software Updates and Add-ons dialog will display. Select the "Available Software" tab. The list of available update sites will display. Press the "Add Site" button to display the Add Site dialog. Enter "http://subclipse.tigris.org/update_1.6.x" as the URL, as shown below.
Plik:Subclipse update site 1.6.png
Press OK and the "Available Software" tab should again display, this time with additional options from the Subclipse site. Select all Subclipse options as shown below. Then press the "Install" button.
Plik:Eclipse install update 1.6.png
Eclipse will work for a minute and then display the Install window, shown below. Press the "Next" button. A "Review Licenses" window appears. Click "I accept the terms of the license agreements". Now click finish.
Plik:Eclipse install update2 1.6.png
After the files have been downloaded and installed, Eclipse will show the message below recommending that you restart Eclipse. Press "Yes" and Eclipse will restart.
Plik:Eclipse install update3.png
Once Eclipse has restarted, we can test that the Subversion plugin is working. Select File / Import as shown below.
Then expand the SVN element in the tree. You should see an option called "Checkout Projects from SVN", as shown below.
Plik:Svn checkout projects.png
At this point, the plugin has been installed successfully. Press "Cancel" to cancel the import. (We'll import the Joomla! project in the next section.)
This article is continued here: Setting up your workstation for Joomla! development -- Part 2. This includes checking out the Joomla! source code, debugging Joomla! from Eclipse, creating patch files, and Eclipse tips and tricks.