1. LAMP Server with PHP5
2. Eclipse with PDT
3. Xdebug
Below description is totally adapted from the sites mentioned in the references so for any further information the reader should refer those links, but I feel the below tutorial should be sufficient.
We will assume Ubuntu version of Linux but I think even for other Linux flavors following steps should work just fine.
A. Installing Apache
LAMP i.e Linux, Apache, MySQL and PHP is a very famous setup for PHP development. Lets start with installing Apache server.
1. Open up the terminal ( Applications > Accessories > Terminal).
2. Copy/Paste the following line of code into Terminal and then press enter:
sudo apt-get install apache2
3. The Terminal will then ask you for you're password, type it and then press enter.
B. Testing Apache2. Copy/Paste the following line of code into Terminal and then press enter:
sudo apt-get install apache2
3. The Terminal will then ask you for you're password, type it and then press enter.
To make sure everything installed correctly we will now test Apache to ensure it is working properly.
1. Open up any web browser and then enter the following into the web address:
http://localhost/
Open it and you will see a message saying "It works!" , congrats to you!
http://localhost/
Open it and you will see a message saying "It works!" , congrats to you!
C. Install PHP
Step 1. Again open up the terminal ( Applications > Accessories > Terminal).
Step 2. Copy/Paste the following line into Terminal and press enter:
sudo apt-get install php5 libapache2-mod-php5
Step 1. Again open up the terminal ( Applications > Accessories > Terminal).
Step 2. Copy/Paste the following line into Terminal and press enter:
sudo apt-get install php5 libapache2-mod-php5
Step 3. In order for PHP to work and be compatible with Apache we must restart it. Type the following code in Terminal to do this:
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/apache2 restart
D. Test PHP
To ensure there are no issues with PHP let's give it a quick test run.
Step 1. In the terminal copy/paste the following line:
sudo gedit /var/www/testphp.php
This will open up a file called phptest.php.
Step 2. Copy/Paste this line into the phptest file:
<?php phpinfo(); ?>
Step 3. Save and close the file.
Step 4. Now open you're web browser and type the following into the web address:
http://localhost/testphp.php
A PHP info page will open authenticating the fact that you have installed PHP and Apache successfully.
E. Install MySQL
Step 1. Once again open up the amazing Terminal and then copy/paste this line:
sudo apt-get install mysql-server
After some time it will prompt for accepting user license. Accept it. Further it will prompt for root user for MySQL which you should provide.
Step 2. We are now going to install a program called phpMyAdmin which is an easy tool to edit your databases. Copy/paste the following line into Terminal:
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file entitled php.ini. To open it type the following:
gksudo gedit /etc/php5/apache2/php.ini
Now we are going to have to uncomment the following line by taking out the semicolon (;).
Change this line:
;extension=mysql.so
To look like this:
extension=mysql.so
Now just restart Apache and you are all set!
sudo /etc/init.d/apache2 restart
F. Install Xdebug
Step 1: Open a terminal
sudo apt-get install php5-xdebug
and then copy/paste this line:
Step 2: After the installation we will modify xdebug.ini file. In the terminal copy paste the following command
sudo nano /etc/php5/conf.d/xdebug.ini
Don't delete the content of this file, just go to the end of the file add 2 blank lines and paste the following configuration:
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
-Now save changes and run following command sudo service apache2 restart
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
-Now save changes and run following command sudo service apache2 restart
G. Configure Eclipse
Note: My suggestion is to go for PHPEclipse instead of PHP plugin (PDT) for Eclipse. This would make PHP development environment separate from Java Eclipse IDE. This is a bit faster than the PDT plugin. And the installation and configuration for PHPEclipse is very straight forward. Hence, we will discuss PDT plugin in the following steps.
I am assuming you have Eclipse installed on your machine.
-Open eclipse
-On the eclipse main menu go to: Help--> Install New Software...
-open the dropDownList "work with"
-select "--All Available Sites--"
-On the filter text field put: php
-Check out: "Programming Languages"
-Check out: "Web, XML, and Java EE Development"
-Follow the wizard instruction until finish
-On the eclipse main menu go to: Window--> Preferences
-Navigate on the tree menu to: PHP--> Debug
-open the dropDownList "work with"
-On "PHP Debugger" select "XDebug"
-Leave alone "Server" and "PHP Executables"
-Save changes and close the window
-On the eclipse main menu go to: Run--> Debug configurations...
-Do a double click over "PHP Web Page" just to add a new setting
-On the DropDowList "Server Debugger" select "XDebug"
-On the file section browse and select the "index.php" of your project or whatever file you need to start your application
-Uncheck "Break at Fist Line"
-Apply changes and close the window
-On the eclipse main menu go to: Window--> Web Browser--> Default System Web Browser
Testing xdebug
-Open a project with source code that already is hosted in your LAMP server
-Place a "break point" at some point of you script
-Press "F11" to start the debugger
-Your code should stop at the break point
-Now move the mouse over variables so watch its values
-On the eclipse main menu go to: Help--> Install New Software...
-open the dropDownList "work with"
-select "--All Available Sites--"
-On the filter text field put: php
-Check out: "Programming Languages"
-Check out: "Web, XML, and Java EE Development"
-Follow the wizard instruction until finish
-On the eclipse main menu go to: Window--> Preferences
-Navigate on the tree menu to: PHP--> Debug
-open the dropDownList "work with"
-On "PHP Debugger" select "XDebug"
-Leave alone "Server" and "PHP Executables"
-Save changes and close the window
-On the eclipse main menu go to: Run--> Debug configurations...
-Do a double click over "PHP Web Page" just to add a new setting
-On the DropDowList "Server Debugger" select "XDebug"
-On the file section browse and select the "index.php" of your project or whatever file you need to start your application
-Uncheck "Break at Fist Line"
-Apply changes and close the window
-On the eclipse main menu go to: Window--> Web Browser--> Default System Web Browser
Testing xdebug
-Open a project with source code that already is hosted in your LAMP server
-Place a "break point" at some point of you script
-Press "F11" to start the debugger
-Your code should stop at the break point
-Now move the mouse over variables so watch its values
References:
http://www.howtoforge.com/ubuntu_lamp_for_newbies
http://ubuntuforums.org/showthread.php?t=1569309
No comments:
Post a Comment