Dart webdev server and PHP files - dart

I'm developing a web project with Google Dart SDK version 2.2 and using PhpStorm as my IDE. The project is intended to start with a index.php file which does some preliminary server side work at the end of which is a call to include('project1.html'); which downloads the html file to the client and includes <script defer src="project1.dart.js"></script> at the end. I'm trying to figure out the best setup for development. I have php installed on the development machine and included in the path.
I have found that calling webdev serve from the terminal serves the project to http://localhost:8080 but displays Could not find web/index.html instead of the expected rendering of project1.html. So I guess the webdev server does not handle .php files?
Another approach is to right click the index.php file and select run in browser. This brings up a Chrome page displaying the text of the index.php file. So again php not processed I guess.
Another approach is to set up a javascript debug configuration with default settings and clicking the green debug icon. This does produces the correct project1.index output and the index.php has been correctly processed. However, I cannot get breakpoints to work and errors in the Chrome Dev Console refer to the project1.dart.js file in the build directory.
Another approach I tried is using an Xampp server to serve the files. In this case I had a number of projects and set each up under xampp/htdocs i.e. xampp/htdcos/project1 etc. In PhpStorm I set up a local or mounted server with:
folder C:\xampp\htdocs\project1,
webserver root url http://localhost/project1,
local path pointing to the web subdirectory of my project, and
deployment and webpaths both set to \.
PhpStorm seems to work ok but again breakpoints did not work and debug error messages did not refer to the dart files.
Any help would be most welcome. Is what I am trying to do even possible with this setup i.e. starting with an index.php file?
** EDIT **
Following advice below, I added following to my httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/project1"
ServerName localhost
ProxyPreserveHost On
ProxyRequests Off
ProxyPassMatch ^/(.*\.js)$ http://localhost:8080/$1
</VirtualHost>
Then I keep my .php files and MySql on Xampp and javascript is served by webdev serve.
However, I have the same problem i.e. breakpoints in PhpStorm or Chrome dev tools source Dart files don't trigger and Chrome dev tools console refers to javascript files instead of Dart source.

You need to run a reverse proxy on the apache/php server and redirect js requests to webdev server, then you just run your application testing using the apache/php server and any browser. When you go to deploy, use dart2js to generate the js files and copy the whole build directory where it can be read by a normal apache/php server (i.e. no reverse proxy).

Related

Change webdev serve directory

prentend that I have a file in .../web/main.dart and when I'm serving the app ( webdev serve web:8080) it will be located in localhost:8080/main.dart.js and the packages in localhost:8080/packages/ is there anyway to move them to localhost:8080/foo/main.dart and localhost/foo/packages/ ?
Basically add /foo/ to all dartdevc generated dictories.
No, that is not supported by the default dev server (and is unlikely ever to be).
The typical way to do this would be to set up a separate server, which delegates all things under the /foo route to the dev server, and strips out /foo from the path.

Capistrano and XSendFile configuration

I am trying to configure Rails production server with Apache 2.2, Passenger 4.0.59 and XSendFile 0.12. Application is deployed via Capistrano.
Deployed application produces (maybe large) PDF to #{Rails.root}/tmp and serves this file using send_file.
The problem is that Capistrano uses symlinks to point to currently deployed version of application. XSendFile on the other hand dereferences symlinks and refuses to serve a file if its real location is outside document root even if it is allowed by XSendFilePath. Apache's error.log states:
(20023)The given path was above the root path: xsendfile: unable to find file: /resolved/path/to/file.pdf
Everything works well when I set PassengerAppRoot and XSendFilePath to the real location of current version of application, without symlinks on the path. But it's OK until next deploy, which requires apache reconfiguration. Not very useful.
How should I configure Capistrano deploy and XSendFile parameters to make it work together?
I tried solutions with ln -nFs described in Capistrano & X-Sendfile and in mod_xsendfile with symbolic links but none works.
I finally managed to make it work. A few tips for the ones who will have problems with XSendFile
I set XSendFilePath to user's $HOME, there are no symlinks on the path to $HOME, so it works. I can accept this from functional and security point of view, but it is obviously a workaround.
Be aware that XSendFilePath is sensitive to paths containing multiple slashes /like//this. I am using apache macros and while concatenatingXSendFilePath parameter from a few macro parameters I put some obsolete slashes. This caused XSendFile to refuse to send files.
Good luck!

Wamp server 2.5 wrong page redirection

I installed wamp server 2.5 with PHP 5.5. Now, when i try to access my project pages from the front page(wamp home page), it redirect to a wrong url and shows google cannot find this page.
The problem definition is
I enter to wamp using http://localhost
There I have many project. Suppose I click on sample_project
Then the page redirects to sample_projects/
And Google Chrome displays the error chrome cannot find this webpage
There are two fields are swown red marks in my wamp PHP extensions area. They are php_enchant and php_opcache
What is the problem with my wamp??am I missing something? Help please
Honestly I think its highly inefficient to create Virtual Host for every.. single.. project. So after investigating I found a key variable in:
wamp/www/index.php.
After quick analysis, the variable's obvious purpose is to remove the 'localhost' in projects links.
Change this line:
$suppress_localhost = true;
To this:
$suppress_localhost = false;
WAMPServer 2.5 Homepage the Your Projects Menu and Virtual Hosts
There has been a change of concept in WampServer 2.5 and there is a good reason for this change!
In WampServer 2.5 it is now STRONGLY encouraged to create a Virtual Host for each of your projects, even if you hold then in a \wamp\www\subfolder structure.
Virtual Hosts Documentation
Virtual Host Examples
The WampServer home page ( \wamp\www\index.php ) now expects you to have created a Virtual Host for all your projects and will therefore work properly only if you do so.
History
In order to make life easier for beginners using WampServer to learn PHP Apache and MySQL it was suggested that you create subfolders under the \wamp\www\ folder.
wamp
|-- www
|-- Chapter1
|-- Chapter2
|-- etc
These subfolders would then show as links in the WampServer Homepage under a menu called 'Your Projects' and these links would contain a link to localhost/subfoldername.
Acceptable only for simple tutorials
This made life easy for the complete beginner, and was perfectly acceptable for example for those following tutorials to learn PHP coding.
However it was never intended for use when developing a real web site that you would later want to copy to your live hosted server.
In fact if you did use this mechanism it often caused problems as the live sites configuration would not match your development configuration.
The Problem for real website development.
The reason for this is of course that the default DocumentRoot setting for wamp is
DocumentRoot "c:/wamp/www/"
regardless of what your subfolder was called.
This ment that often used PHP code that queried the structure or your site received different information when running on your development WampServer to what it would receive when running on a live hosted server, where the DocumentRoot configuration points to the folder at the top of the website file hierarchy.
This kind of code exists in many frameworks and CMS's for example WordPress and Joomla etc.
For Example
Lets say we have a project called project1 held in wamp\www\project1 and run incorrectly as localhost/project1/index.php
This is what would be reported by some of the PHP command in question:
$_SERVER['HTTP_HOST'] = localhost
$_SERVER['SERVER_NAME'] = localhost
$_SERVER['DOCUMENT_ROOT'] = c:/wamp/www
Now if we had correctly defined that site using a Virtual Host definition and ran it as http://project1 the results on the WAMPServer devlopment site will match those received when on a live hosted environment.
$_SERVER['HTTP_HOST'] = project1
$_SERVER['SERVER_NAME'] = project1
$_SERVER['DOCUMENT_ROOT'] = c:/wamp/www/project1
Now this difference may seem trivial at first but if you were to use a framework like WordPress or one of the CMS's like Joomla for example, this can and does cause problems when you move your site to a live server.
How to create a Virtual Host in WampServer
Actually this should work basically the same for any wndows Apache server, with differences only in where you may find the Apache config files.
There are 3 steps to create your first Virtual Host in Apache, and only 2 if you already have one defined.
Create the Virtual Host definition(s)
Add your new domain name to the HOSTS file.
Uncomment the line in httpd.conf that includes the Virtual Hosts definition file.
Step 1, Create the Virtual Host definition(s)
Edit the file called httpd-hosts.conf which for WampServer lives in
\wamp\bin\apache\apache2.4.9\conf\extra\httpd-hosts.conf
(Apache version numbers may differ, engage brain before continuing)
If this is the first time you edit this file, remove the default example code, it is of no use.
I am assuming we want to create a definition for a site called project1 that lives in
\wamp\www\project1
Very important, first we must make sure that localhost still works so that is the first VHOST definition we will put in this file.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
Now we define our project: and this of course you do for each of your projects as you start a new one.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/project1"
ServerName project1
<Directory "c:/wamp/www/project1">
AllowOverride All
Require local
</Directory>
</VirtualHost>
NOTE: That each Virtual Host as its own DocumentRoot defined. There are also many other parameters you can add to a Virtual Hosts definition, check the Apache documentation.
Small aside
The way virtual hosts work in Apache: The first definition in this file will also be the default site, so should the domain name used in the browser not match any actually defined virtually hosted domain, making localhost the first domain in the file will therefore make it the site that is loaded if a hack attempt just uses your IP Address.
So if we ensure that the Apache security for this domain is ALWAYS SET TO
Require local
any casual hack from an external address will receive an error and not get into your PC, but should you misspell a domain you will be shown the WampServer homepage, because you are on the same PC as WampServer and therfore local.
Setp 2:
Add your new domain name to the HOSTS file.
Now we need to add the domain name that we have used in the Virtual Host definition to the HOSTS file so that windows knows where to find it. This is similiar to creating a DNS A record, but it is only visible in this case on this specific PC.
Edit C:\windows\system32\drivers\etc\hosts
The file has no extension and should remain that way. Watch out for notepad, as it may try and add a .txt extension if you have no better editor.
I suggest you download Notepad++, its free and a very good editor.
Also this is a protected file so you must edit it with administrator privileges, so launch you editor using the Run as Administrator menu option.
The hosts file should look like this when you have completed these edits
127.0.0.1 localhost
127.0.0.1 project1
::1 localhost
::1 project1
Note that you should have definitions in here for the IPV4 loopback address 127.0.0.1 and also the IPV6 loopback address ::1 as Apache is now IPV6 aware and the browser will use either IPV4 or IPV6 or both. I have no idea how it decides which to use, but it can use either if you have the IPV6 stack turned on, and most window OS's do as of XP SP3.
Now we must tell windows to refresh its domain name cache, so launch a command window again using the Run as Administrator menu option again, and do the following.
net stop dnscache
net start dnscache
This forces windows to clear its domain name cache and reload it, in reloading it will re-read the HOSTS file so now it knows about the domain project1.
Step 3: Uncomment the line in httpd.conf that includes the Virtual Hosts definition file.
Edit your httpd.conf, use the wampmanager.exe menus to make sure you edit the correct file.
Find this line in httpd.conf
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
And just remove the # to uncomment that line.
To activate this change in you running Apache we must now stop and restart the Apache service.
wampmanager.exe -> Apache -> Service -> Restart Service
Now if the WAMP icon in the system tray does not go GREEN again, it means you have probably done something wrong in the \wamp\bin\apache\apache2.4.9\conf\extra\httpd-hosts.conf file.
If so here is a useful mechanism to find out what is wrong. It uses a feature of the Apache exe (httpd.exe) to check its config files and report errors by filename and line numbers.
Launch a command window.
cd \wamp\bin\apache\apache2.4.9\bin
httpd -t
So fix the errors and retest again until you get the output
Syntax OK
Now there is one more thing.
There are actually 2 new menu items on the wampmanager menu system. One called [b]'My Projects'[/b] which is turned on by default.
And a second one, called [b]'My Virtual Hosts'[/b], which is not activated by default.
'My Projects' will list any sub directory of the \wamp\www directory and provide a link to launch the site in that sub directory.
As I said earlier, it launches 'project1` and not 'localhost/project1' so to make the link work we must create a Virtual Host definition to make this link actually launch that site in your browser, without the Virtual Host definition it's likely to launch a web search for the site name as a keyword or just return a site not found condition.
The 'My Virtual Hosts' menu item is a little different. It searches the file that is used to define Virtual Hosts ( we will get to that in a minute ) and creates menu links for each ServerName parameter it finds and creates a menu item for each one.
This may seem a little confusing as once we create a Virtual Host definition for the sub directories of the \wamp\www folder some items will appear on both of the 'My Projects' menu and the 'My Virtual Hosts' menu's.
How do I turn this other 'My Virtual Hosts' menu on?
Make a backup of the \wamp\wampmanager.tpl file, just in case you make a mistake, its a very important file.
Edit the \wamp\wampmanager.tpl
Find this parameter ;WAMPPROJECTSUBMENU, its in the '[Menu.Left]' section.
Add this new parameter ;WAMPVHOSTSUBMENU either before or after the ;WAMPPROJECTSUBMENU parameter.
Save the file.
Now right click the wampmanager icon, and select 'Refresh'. If this does not add the menu, 'exit' and restart wampmanager.
Big Note
The new menu will only appear if you already have some Virtual Hosts defined! Otherwise you will see no difference until you define a VHOST.
I can't believe that Wampserver now expects everyone to create a virtual host for every project under development offline on their laptops?
Your instructions seem to be very good but probably much too complicated for beginners (also, I suspect that the file path in your instructions for step2: adding the new domain to the HOSTS file only applies to 32-bit Windows)?
The solution from Rogue above (change $suppress_localhost="true"; to $suppress_localhost="false"; in c:/wamp/www/index.php) will work perfectly for 99% of the users who develop more than one website on their laptops.
Also uploading a completed website to an online server should not cause any real problems.
BUt perhaps Wampserver had another reason for adding the $suppress_localhost code?

Ruby Passenger displays content from public instead of the app

I have a server in the cloud. I've set up a Linux machine with Apache2 + Passenger(with the apache module installed).
I've configured by the book, set up the VirtualHost as the Passenger instructions tell me to.
I've created a default Ruby on Rails project in "RubyMine"(on the local machine), synchronized it with the server.
Here is the project file hierarchy:
Since the instructions ask me to point in the configuration file to /projectFolder/public, I did so. If there is no index.html in the public folder, it throws me an error, if I create one it displays it when I access the link.
But when on the local machine I deploy it, it instead launches the app from app->views->layouts.
How to make it run on the remote server my ruby code? My ruby "app"?
First try:
sudo passenger-status
This should show you if passenger is loaded and the applications group. If that is all good, delete the index.html from /public and restart apache.

Is it a bad idea to put apache conf files in my rails app's config directory?

I have a dedicated CentOS server. I manage all my users, apps, and virtual hosts manually. I'm using Apache 2.2.3 and Passenger 3.0.7 to serve my apps. I have a typical httpd.conf file in /etc/httpd/conf/ that includes all *.conf files in my /etc/httpd/conf/vhosts/ directory. Normally for each app I create a new sample-domain.com.conf file in the vhosts directory.
However, I have a particular app that needs frequent apache configuration changes, and I'd like it to be more a part of my app and its version control. So I've moved my apache configuration file into the apps config directory. I added a script to my Capistrano deploy.rb that sets the permissions on the apache conf file in the app to 755. I added an include line in my vhosts that includes the symlinked current version of the apache conf file from the app.
Which brings me to my simple question: is this safe or a bad idea?
For frequent config changes in Apache, consider using a .htaccess file instead. Changing .conf files requires bouncing/hupping the server, and if a .conf file has an error, that'll kill the whole server and take down all sites. A .htaccess error will take down just the one site/directory where the file is.

Resources