Eclipse - How to add subfolder to end of XAMPP localhost - php

a quick question about running PHP applications in Eclipse PDT. I have done a lot of searching but can not find what I am looking for.
I have XAMPP installed and am trying to run my PHP applications out of eclipse. The problem is I have my source files in a SUBFOLDER of the htdocs folder. So when I run, eclipse nagivates to:
http://localhost/index.php
But I need it to navigate to:
http://localhost/MyWebApps/index.php
Is there any way I can set the PHP server to always default to MyWebApps folder in eclipse? As MyWebApps is my eclipse workspace.
Thanks in advance!

Here 3 solutions:
First way, easy for one file. Project Explorer -> Right click on file -> Run As... -> Run Configurations. Configure similar to screenshot:
Then, click (V) arrow after run button in toolbar and choose configuration, "New configuration A" as in example.
Another better way: (root needed)
Add host "127.0.0.1 mywebaps.localhost" to /etc/hosts
Configure VirtualHost mywebaps.localhost in Apache, with document root point to your Workspace (files starting with "." should be blocked for this and nested directories, this is eclipse meta files)
Configure web server in eclipse to use mywebaps.localhost as host
name, then your file will be opened as
http://mywebaps.localhost/projectname/index.php
And finally, easy way: (root may be needed)
Leave your Workspace folder inaccessible by apache.
Create new php project, not in workspace but in apache document root
folder(should be writeable by user)

Related

Correct way to use eclipse and xdebug

I downloaded the pdt plugin for eclipse for php development. I have mamp installed , with the web port set at 80. The name of my project is PHPTest.
I have one file in it ,called helloworld.php.
Hello world just echoes A text.
This project is located at
/Users/MYUSERNAME/EclipseProjects
When I run the project by right clicking on it, It shows this error in my browser :
Not Found
The requested URL /PHPTest/helloworld.php was not found on this
server.
So, why does this happen ? Is there some setting that I am missing?
or is the only way to get this running is to change the project's directory to the public html folder of mamp ?
This isn't related to xdebug support. Your HTTP server know nothing about your projects. you can fix this in three way:
Manually copy/paste project to your MAMP document root dir (default is /Applications/MAMP/httpdocs)
Change MAMP document root dir to workspace: /Users/MYUSERNAME/EclipseProjects (easies way)
Move your workspace to document root dir (/Applications/MAMP/httpdocs)

PHP in Eclipse, how to run PHP on some server?

On Eclipse i installed the PHP Development Tools and everything is cool, except i can't configure it to run on my local Apache...
I saw something like placing all my project files in some htdocs directory of Apache directory... but its kinda absurd...
I already tried:
http://www.eclipse.org/pdt/help/html/running_php_web_pages.htm
and
http://www.eclipse.org/pdt/help/html/php_servers.htm#Adding_servers
Which, as i understood, is linking calls from localhost/[project-name] (which directory is placed as htdocs) to my original repository x:/y/[project-name], but it doesn't work...
You might need to setup the workspace for your eclipse. The directory you set as workspace works as the document root directory and you don't need to place everything in htdocs. Hope this helps.

How tell PHPStorm debugger, that my project has document root other than project root

I'am trying to set up PHPStorm with xdebug. Everyting launches fine, but breakpoints just do not work and have "x" symbol on them.
I'm using openserver with PHP 5.4 and editing files directly on the local web server, so no file mapping is necessary.
I think, that my problem is that web server root is located below the project root directory (for security reasons) and PHPStorm does not that.
Project root: C:\OpenServer\domains\mysite
Web server root (configured in nginx): C:\OpenServer\domains\mysite\httpdocs
How do I tell PHPStorm, that the index.php that webserver runs is actually C:\OpenServer\domains\mysite\httpdocs\index.php, but not C:\OpenServer\domains\mysite\index.php?
You have to use path mapping.
You can find it in debug server configuration
Check out official docs and vids:
Help page
PHP Debugging webinar recording
JIT debugging
Smart step into
Simultaneous debug sessions
In my case, I tried these steps:
step 1: uncheck these two options at xdebug section
step 2: copy & paste the directory of your project at /xampp/htdocs/{your-project}

PHP sample project with wamp

I installed wamp stack and then installed netbeans ide. The port number for apache is 100.
Created one PHP project at
C:\Users\aaa\Documents\NetBeansProjects\PhpProject2
and project URL http://localhost:100/PhpProject2/
When I click on run, I see the message "http://localhost:100/PhpProject2/index.php URL not found on the server".
What else I need to do to connect http://localhost:100/PhpProject2/index.php to C:\Users\aaa\Documents\NetBeansProjects\PhpProject2?
Please help.
You need to configure Apache's webroot to be C:\Users\aaa\Documents\NetBeansProjects (search for DocumentRoot in the file httpd.conf).
Or you can move/copy your files to the existing webroot, which may be something like c:\wwwroot.
Apache doesn't just magically know where you put your website files, and setting the URL inside NetBeans doesn't actually configure the webserver (I think it's just so that auto-generated links are right).
If you go to http://localhost:100/, what do you see? What is your web root? The folder needs to be in your web root, and I would be surprised if it is C:\Users\aaa\Documents\
I did a Google search for "wamp stack" and found a product by Bitnami... if this is the one you are using, the default web root is C:\Program Files\BitNami WAMP Stack\apache2\htdocs\. If that is indeed the case, then you'd need to move the NetBeansProjects folder to there. (source: http://bitnami.org/files/stacks/wampstack/5.3.6-0/wampstack.pdf page 7)
You need to look into aliasing. That will let you more or less assign directories in the url path to arbitrary directories on your file system.
You have to move your files to your root folder of the Apache installation (htdocs). You should refer to your WAMP installation for where that is located. Personally, I like to use XXAMP for installation.
Netbeans is just an IDE, it doesn't serve the files.

Eclipse output to WAMP webserver www folder

I have an eclipse workspace folder. I want to store all the different projects I am working on over here. Now I am working on a PHP project and have WAMP installed. Is there some way to configure eclipse such that it outputs my project files to the server's www folder.
I don't want to create my workspace in the server's www folder, for the following reasons:
- I will work on multiple projects over time and I want all of them to reside in the same workspace
- I don't want to pollute the web server's www folder (though this is a development machine). I feel that if I have the code in a separate workspace, there is a low chance of me deleting it by mistake. I don't want to end up deciding to clean the www folder and deleting my only copy of the code!
Any alternative solutions to my concern are also welcome :)
You don't need to edit any php.ini files or anything crazy like that; you just need to change a couple of things in Eclipse.
Step #1:
Go into Eclipse and click on Window --> Preferences --> PHP --> PHP Servers
There should be a default server listed; you can edit it or just create a new one(this is what I did) and just set it as default later.
Click add or new or whatever it will come up with 2 boxes.
The first is just what you want to call the server; call it whatever you like.
The second is IMPORTANT -- this is where the www folder for your WAMP server is located. I have a shortcut to it on my desktop with a folder with all my php files in it.
I just typed localhost/name of my folder <--- your folder goes here.
It should be localhost/wamp/www if you don't have a shortcut. Don't hold me to that, though.
Step #2 : Running the program
When you have your php file you want to run, right click it and select Run as --> Run Configurations --> PHP webpage(double click). In the "File" area click Browse. Your project folder with your .php file you want to run should pop right up. If not, you'll have to look for it. Select it, then click "Run". Eclipse will open its default browser, and if all went well, you should be able to see your output.
It probably makes it easier if you just use a separate workspace for your PHP projects and store all the files in the www folder(Eclipse should make sub folders for new projects).
Hope this helps
You can keep the php code in your current eclipse workspace and then create virtual host in the httpd.conf file of apache server with document root pointing to this directory.
Only solution I found was to place your PHP files under the wamp\www folder.
Example:
c:\wamp\www\yourproject\index.php

Categories