I installed Eclipse PDT for PHP development on my Ubuntu box (running Apache2 as server),
I tried to create a PHP project and run it as "PHP Web Application" as show in the picture:
But when I click "Run" the browser pops out and giving 404 error saying it cant find localhost/test/newfile.php .
Does Eclipe PDT having its own internal webserver? (If so, I tried by shutting down my Apache2 ,but still giving the same error)
Finally, as a work around, I changed my workspace location to "/var/www" and created my projects there. But wondering whether its the best way to develop using PDT?
The questions you ask are not directly related to Eclipse PDT but how to setup the development server.
I suggest not to move the project into the webroot but to make Apache visit your development/project directory instead.
There are multiple ways to do that:
You can create a symlink (softlink) making a URL-Path point to a directory. You need to allow Apache to follow symlinks.
You can make use of the Alias directive to do something similar.
Virtual Hosts to make the webserver point to the location you're looking for via it's domain name. You can then create "fake" domain names within your hosts file like example.com.loc for the local development version of your website.
You can even use mod_rewrite for that (not that good option).
As you can see there are multiple ways to have this in a manageable fashion. Depending on your needs, the symlink variant is probably most easy to accomplish. If you need more security, the Alias Directive is similarly easy to accomplish. Virtual hosts start to make sense if you're more familiar with apache configuration and you need more control of the URLs (some software is that dumb that it needs to reside on the top path / beneath an URL otherwise it just does not work (yeah, crap, but virtual hosts come to the rescue then). The mod_rewrite "solution" is just named for completeness reasons, it's more asking for trouble if you're not firm with mod_rewrite and as you're new to apache configuration, leave it next to your road and ignore that suggestion.
All these ways allow you to have one or more development projects next to static websites on your server. I personally have configured virtual hosts on my devbox, and on my earlier devbox I was just using alias directives.
Keep in mind that you need to restart the apache service if you edited the configuration:
$ sudo /etc/init.d/apache2 restart
And most importantly: Before you edit the configuration file, copy it over to a backup file-name. Always backup configuration files before you edit them. You don't want to loose the working settings, believe me ;)
Related
I want to run different web app on different ports on same server, I have a apache php server running on a Linux machine. How can I achieve this ? and when I Google I stumble upon 'tomcat', what is this ? I am a noob, so please forgive if that is a stupid question.
Check the apache manual for the VirtualHost directive. It'll explain everything.
One thing to remember (it caught me out first time) - if you use virtual hosts, you have to define a virtual host for the default page too.
Don't worry about Tomcat at the moment. If you don't know what it is, you don't need it yet.
Step 1: Install the Tomcat files
Download Tomcat 4.1 or 5.5, and unzip it into an appropriate directory. I usually put it in /usr/local, so it ends up in a directory called /usr/local/apache-tomcat-5.5.17 (5.5.17 being the current version as of this writing), and make a symlink named /usr/local/tomcat to that directory. When later versions come out, I can unzip them and relink, leaving the older version in case things don’t work out (which rarely if ever happens, but I’m paranoid).
Step 2: Make directories for each instance
For each instance of Tomcat you’re going to run, you’ll need a directory that will be CATALINA_BASE. For example, you might make them /var/tomcat/serverA and /var/tomcat/serverB.
In each of these directories you need the following subdirectories: conf, logs, temp, webapps, and work.
Put a server.xml and web.xml file in the conf directory. You can get these from the conf directory of the directory where you put the tomcat installation files, although of course you should tighten up your server.xml a bit.
The webapps directory is where you’ll put the web applications you want to run on the particular instance of Tomcat.
I like to have the Tomcat manager webapp installed on each instance, so I can play with the webapps, and see how many active sessions there are. See my instructions for configuring the Tomcat manager webapp.
I've officially reached the end of my wits on this problem. As someone who constantly works on several websites at a time (I'm sure I'm not alone here), it becomes frustrating renaming my "htdocs" directory whenever I want to work on a different site, so I decided to throw together a simple script.
My first approach was to reset the "DocumentRoot" variable in "httpd.conf" based on the directory input I provided, however, having a DocumentRoot outside of the main "/Applications/XAMPP/" directory has proven to be a bigger problem. As you can see, I'm running OSX with an XAMPP installation. Ideally, I'd like to have all my sites located at "/Users/Me/Sites/*". Even when I tried to move my sites within XAMPP's base directory, Apache does not want to load anything other than "htdocs" as my DocumentRoot.
My next approach was to simply add symbolic links to all the files/directories within each site I was working on at the time to "htdocs". This loads fine in the browser for basic html files, however, I work primarily with PHP and this does not appear to want to render (I can see the file but it will not display as a webpage).
Neither of these approaches in themselves sound too difficult, but from learning Xcode, to AppleScript, to Apache's httpd.conf documentation, I feel I've experienced enough headaches. I've played with permissions for each attempt I've gone through and nothing has panned out for me yet.
I'm sure there are plenty of other webdesigners out there who have faced this problem in the past, what's your solution?
This is actually really easily achieved, given that you are using XAMPP, I am not 100% but if you go under /bin/apache2/conf/extras/ you should see a file called httpd-vhosts.conf in this file you can add as many virtual hosts as you want. Make sure you set the ServerName to be something unique. Once that is done, make sure that the Include Vhosts is enabled in the httpd.conf
Now, you just edit your hosts file. I am not sure where this is on OSX, since it is linux based I would say /etc/hosts but google will help you. Add a line for each of your sites like so:
127.0.0.1 site1.dev
127.0.0.1 site2.dev
etc. Now restart apache and in your browser type site1.dev and apache should understand it and take you to that site. Pretty simple.
Brad's solution should work.
If you are on OSX, you might also want to check out MAMP (http://www.mamp.info/en/index.html). There is a free and "Pro" version. I've only used the free version but it's pretty drop dead simple to change the root directory from one project to the other. Only kind of gotcha is the MySQL which uses a socket to connect but if you know what you are doing, this isn't a big deal.
Once you'll understand the virtualHost things, let'say you'll use names based virtualhosts and edit you host file to get all theses names matching your development server IP, once done, you'll see you will have to adjust documentRoot and directory settings on all theses virtualhosts for each new project.
So a generic solution exists: mod_vhost_alias : http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html
All you virtualhosts will be the same, with variables (documentRoot, serverName,etc). If you want specific setting for some projects ensure you have allowed .htaccess files and set the specific things there.
What's the best way to deploy a PHP PDT Eclipse Project on Apache 2.2 on Ubuntu?
I already tried to find an Apache Eclipse server adapter but got no luck. Do you know any?
If not, what's the best way to deploy a PHP Project to Apache? Shell script? Ant script? Other solution?
I could put the project folder inside the Apache's www folder but I would prefer to have the project files on a cloned git repository outside of Apache.
I'm using Eclipse Helios SR1, PDT 2.2.1 and Apache 2.2.16.
Thanks in advance.
I came across this page looking for a Windows solution and found this little workaround in the meantime that might prove useful to someone:
Select Run > External tools > External tools configuration
Add a new configuration, name it Deploy or something
Set the location field to C:\Windows\System32\xcopy.exe
Set the argument field to ${workspace_loc}${project_path}\*.php c:\inetpub\wwwroot\${project_name} /s /y
Create the directory c:\inetpub\wwwroot\${project_name} manually so xcopy doesn't get confused
This will copy all your PHP files over to your webserver content directory in a subfolder with the same name as your project. The nice part is that you can run this deployment shortcut from the Run Tool button, right next to your Debug and Run buttons.
symbolic links!
ln -s /home/pedrosanta/Workspace/myapplication /var/www/myapplication/htdocs
setup your apache virtual hosts accordingly.
Or you could just set your virtual host's document root to your remote location.
DocumentRoot /home/pedrosanta/Workspace/myapplication
I found this question here on SO with a lot of useful answers:
Does anybody have a development/staging/deploying workflow with php/mysql?
I hope it helps!
Save to local, SVN (or other version control via Eclipse) to branch, branch to trunk, trunk to test, test to live. I can't say enough about how important version control and testing is in any sized environment.....even if it IS a colossal pain.
http://andrei.gmxhome.de/filesync + http://code.google.com/p/win-sshfs/ is remarkably good.
I use Apache with eclipe by configuring Apache path to the workspace folder,
in httpd.conf (d:/workspace/php/ is my project location)
Alias /php/ d:/workspace/php/
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
restart Apache and
http://localhost/php/somefolder/somefile.php
Cheers
I would like to build an 'ideal' lamp development stack.
Dual Server (Virtualised, ESX)
Apache / PHP on one, Databases (MySQL, PgSQL, etc) on the other.
User (Developer) Manageable mini environments, or instance.
Each developer instance shares the top level config (available modules and default config etc)
A developer should have control over their apache and php version for each project.
A developer might be able to change minor settings, ie magicquotes on for legacy code.
Each project would determine its database provider in its code
The idea is that it is one administrate-able server that I can control, and provide globally configured things like APC, Memcached, XDebug etc. Then by moving into subsets for each project, i can allow my users to quickly control their environments for various projects.
Essentially I'm proposing the typical system of a developer running their own stack on their own machine, but centralised. In this way I'd hope to avoid problems like Cross OS code problems, database inconsistencies, slightly different installs producing bugs etc.
I'm happy to manage this in custom builds from source, but if at all possible it would be great to have a large portion of it managed with some sort of package management. We typically use CentOS, so yum?
Has anyone ever built anything like this before? Is there something turnkey that is similar to what I have described? Are there any useful guides I should be reading in order to build something like this?
OK, the way we were running development LAMP setup at my previous job, was like this. A single server running both MySQL and Apache. Each developer is assigned an IP address on the server (the machine is running multiple IPs on the same interface, all IPs are on the same subnet), so each developer can have at least one IP-based virtual host and as many name based as they want (our web site used SSL, so we needed separate IPs, wigthout SSL, you can get away with a single IP and name based vhosts). We had local DNS server serving wildcard A records for each developer in this manner *.john.dev.company IN A 10.1.1.123, where 10.1.1.123 was IP address assigned to John. This way John could define as many name based vhosts as he wanted and they would all get resolved correctly as long as they all ended in john.dev.company (like project1.john.dev.company). Each developer had their own apache config file with their virtual hosts in it and we used Include directive to pull all these files into the main Apache config. The permissions were set, so these config files would be editable by respective developers and each developer had a soft link to their config in their home directory. Also, every developer was allowed to use sudo to restart Apache. The downside of this setup was that once in a while a particular dev would crash entire server by screwing up their config file. We used common database, since everyone was working on a single project, but it shouldn't be difficult to setup multiple individual databases.
My take on the issue, i don't think it covers all of your requirements, but it's pretty close:
Have a CentOS server with LAMP stack ( yum install apache2 mysql php etc. ) - or 2 servers one httpd and one mysqld
For n developers have n folders with n virtual hosts www.developer-n.com on the host that runst the Apache server
Each developer mounts it's server folder (say //192.168.0.1/home/developer-n/www) on the local machine via CIFS in the local-station's /etc/fstab and edits the files from local machine yet runs them on the (unique) server
Each developer mini-environment is tweaked via .htaccess
So we are pushing to create good processes in our office. I work in a web shop that has been doing web sites for over a decade. And we don't use version control. I know! It's bad, not my fault. I'm the guy with a SoftE background pushing for this at a minimum.
The tech lead has been looking into it. We all use Mac workstations and mostly use Coda for editing since it is a great IDE. It has SVN support built in but expects it to work on local files. We're trying to explore mounting the web directory as a local network drive with an SFTP tool.
We are a LAMP shop, BTW.
I am wondering what the model is here. I think we have typically would checkout the whole site to our local machine where we have apache running and then test it there? This isn't how we work yet, we do everything on the server. We've looked at checking things in and out, but some files are owned by apache and the ownerships change when I check them in, because I'm not apache.
I just want to know a way to do this that works given my circumstances. Would be nice to not have to run apache locally.
You might want to checkout the Coda mailing list and ask there. Lots of Coda enthusiasts there with specific experience.
If you don't want to have to run locally could make Apache on your server run a copy of the site for every developer, on a different port per person, and then mount those web-roots to the local macs and make that the working directory. If you're a small shop that's not hard to manage. I find that pretty easy to set up and saves a lot of resources on the local machines. The one-site-per-person helps to avoid conflicts with multiple people working on files at the same time.
What I'd additionally recommend is to have a script that gets the latest changes from SVN and deploys the entire site to the production server when you're ready. You could have that script change permissions on appropriate files/folders as needed to be owned by Apache. The idea once you're using source control is to never manually edit the production files -- you should have something that deploys it from SVN for you.
A few notes:
Take a look at MacFuse / MacFusion (the latter is the application, the former is the library behind it) to mount remote directories via SSH / FTP as local ones.
Allow your developers to check out into their local environment (with their own LAMP stack if they're savvy), or look into a shared dev environment with individual jails. This way your developers can run their own LAMP stack (which you could deploy for them on the machine) without interfering with others.
The idea being, let them use a workflow that works best for them, to minimize the pain in adapting to this change (if change management might be an issue!)
Just as an example, we have a shared dev server where jails are created with a single command for new developers. They have a full LAMP stack ready to go, and we can upgrade and re-deploy jails easily to keep software up to date. Developers have individual control to add custom settings / extensions if they need it for work, while the sys admins have the ability to reset everything when someone accidently breaks their environment :)
Those who prefer not to use jails, and are able to, manage their own local environments (typically through Macports or MAMP).