I am building a website which uses Apache + PHP on port 80 for the frontend, and Node.js + Socket.IO for dynamic updates on port 3000. There are quite a few shared Javascript resources between the two and I'd like to know how I can share them.
Here's my project layout:
project/
www/ // Apache DocumentRoot
index.php
js/ // Javascript files for the HTML pages
css/
app/
App.php // All the PHP files
node/
node_modules/ // Node modules installed by NPM
app.js // Node.js application
When my PHP application generates HTML code, it needs to put some <script> tags in <head> for things like underscore.js, backbone.js, socket.io.js, etcerea. But these scripts are all somewhere in de node_modules directory.
I have seen various examples but most use Node.js to serve the HTML page as well (usually using the express framework). So, they generate script includes like /socket.io/socket.io.js. But in my case I have two servers running on two ports.
So, how can I load the proper Javascript files without manually copying things from the node_modules directory to the js directory under the DocumentRoot?
There are 2 options:
Create a symlink (pointing from www/js to node_modules)
Create an Apache2 alias in you Apache configuration file (see here)
If you have access to your Apache2 configuration, the 2nd solution is probably the better one. When going for the symlink solution, make sure you double-check the ownership of the folders if you experience problems.
Related
Following an audit, I've been tasked to remove extraneous files from the Twig 1.x vendor directory in one of our sites. Planning on removing /twig/twig/doc, /twig/twig/test and see if anything breaks.
What about /twig/twig/ext/twig/run-tests.php, or the entire "ext" directory?
Does anyone have prior experience weeding a default Twig 1.x installation for production environments? Any assistance or advice gratefully welcomed.
The correct action would be to update your site's layout so that these files are outside your web server's document root -- then you don't have to worry about what to delete and what to leave. You probably have something like this, where your web server's document root is pointing directly at /path/to/project:
/path/to/project
/lib
foo.php
bar.php
/twig
/twig
/doc
/test
index.php
This means anybody can directly request http://yourdomain.com/twig/twig/test/some_file.php
What you want is more like this:
/path/to/project
/public
index.php
/lib
foo.php
bar.php
/twig
/twig
/doc
/test
Then configure your web server so that its document root is /path/to/project/public. Then your application code can still include() things in /twig and /lib, but your web server won't directly serve them.
If your removing files from the vendor directory they'll come back the next time you do a composer install so this seems kind of pointless.
The files you mention (docs and test) are causing no harm other than taking up space as they are not directly called, but that's just a downside to any package management system. Like #Alex said as long as they are not publicly accessible there is no need to worry.
If you really want Twig without the extra files you could fork the project, move it into your own Git repo then reference that in your composer.json instead of the official one - but you will miss out on any updates from Twig.
We're running on Apache, so the easiest solution was to simply add a .htaccess file to the top vendor directory:
# Prevent non-local access to the vendor directory.
Order deny,allow
Deny from all
Directory structure:
/root
/vendor
.htaccess
/twig
...
/includes
...
Now the PHP scripts continue to have access, but external attempts to view anything inside the vendor directory return a 403 error.
I have two different Symfony2.8 applications. During development they are accessible via two separated domains (virtual hosts): www.app1.local and www.app2.local. And everything works fine. But finally both applications should be deployed to the one server with one domain. Therefore I created two folders for each application.
Document root is /httpdocs, so file /httpdocs/test.php is accessible via www.domain.com/test.php. Two folders are /httpdocs/app1 and /httpdocs/app2. Each contains different installation of Symfony2.8 with own bundles etc.
And what is the problem? The web in URL. The URL to application looks like www.domain.com/app1/web/index.php instead of www.domain.com/app2/web/index.php. I'm trying to hide this web from URL but I don't have idea how to do this.
In general, it should be configurated via web-server itself. But if you don't have any access to configuration of web-server (Apache, nginx), you can do the following.
Put in your /httpdocs/app1 copy of app1/web, and in /httpdocs/app2 copy of app1/web
Applications themselves put in some other place.
So it will look, for example, like this:
app1/
app/
bin/
... # <--no web among these folders
composer.json
...
app2/
app/
bin/
... # <--no web among these folders
composer.json
...
httpdocs/
app1/
bundles/
....
index.php
app2/
bundles/
....
index.php
And then in your index.php fix paths to application
$loader = require __DIR__.'/../../app1/app/autoload.php';
include_once __DIR__.'/../../app1/var/bootstrap.php.cache';
(and same for app2, but with app2).
Also, fix both composer.json
"symfony-web-dir": "../httpdocs/app1",
I logged into openshift application using filezilla.
Earlier for normal website i just drag and drop files at www directory its works pretty fine but in at this case i found some other folders and i am unable to get an idea where should i drop my php app in at this particular machine. I am unable to locate where the index file is located also. if I am using git for the deployment of application it works pretty fine.
Openshift makes it easy to upload program changes by checking out the container. Adding the code and the pushing it.
see How to git-checkout first application created on OpenShift? on how to do that.
I'm not sure about the structure when you use filezilla to connect to the Openshift container, but it should be similar to the checked out structure
index.php Template PHP index page
.openshift/ Location for OpenShift specific files
action_hooks/ See the Action Hooks documentation
markers/ See the Markers section below
pear.txt List of pears to install
Depending on what cartridge you are using:
php/ # for backward compatibility with OpenShift Origin v1/v2
public/ # Zend Framework v1/v2, Laravel, FuelPHP, Surebert etc.
public_html/ # Apache per-user web directories, Slim Framework etc.
web/ # Symfony etc.
www/ # Nette etc.
./ # Drupal, Wordpress, CakePHP, CodeIgniter, Joomla, Kohana, PIP etc.
See https://developers.openshift.com/en/php-repository-layout.html for more details.
try this:
goto app-root > repo
put your files in this folder. if you put a index.php, it will be accessible through the web.
but there's a more convenient method.
create a folder name php inside the repo folder and openshift will use it as a document root. which means all other files will be unaccessible from the public.
conclusion
put all other files in app-root>repo. put the index.php in the php folder and link other files accordingly.
optional:
use GIT. its easy and way more convenient than sftp. you need to learn only 4 commands.
git add
git commit
git push
git clone
that's it!
edit1
IF php/ dir exists THEN DocumentRoot=php/
ELSE IF public/ dir exists THEN DocumentRoot=public/
ELSE IF public_html/ dir exists THEN DocumentRoot=public_html/
ELSE IF web/ dir exists THEN DocumentRoot=web/
ELSE IF www/ dir exists THEN DocumentRoot=www/
ELSE DocumentRoot=/
above is the priority of document roots in openshift. use whatever you like.
Had the same problem. You need to turn off APC cache. This can be done via an .htaccess file:
php_flag apc.cache_by_default Off
The directory structure of my project is like this:-
/var/www/includes/
/var/www/classes/
/var/www/public/css/
/var/www/public/js/
/var/www/public/index.php
The webroot is /var/www/public, so accessing the test domain localhost.dev would serve the files inside the public directory and hence would run /var/www/public/index.php. No need to access like localhost.dev/public/index.php
The problem is when I create the project in Netbeans, I have to set the index file so that the project can be debugged using xdebug and Netbeans.
So when adding the project I provided /var/www as Project source folder (Sources Folder) as the includes and classes are in this folder. In the next project configuration screen (Choose Project > Name and Location > file path is taken as Run Configuration), I'm asked for the Project URL and the index file. Since the index.php file is actually under the /var/www/public/, when I browse the file and select it, the url to index page is taken as localhost.dev/public/index.php instead of just localhost.dev/index.php. This is preventing me from debugging the project.
Can anyone please point out how to add projects to Netbeans when all the source files are not in web root and the project is to be debugged using xdebug.
I think its a bad practice to put all the project files directly in /var/www.
I think you will never see that in real deployed projects. So my first recommendation will be to change the way you are structuring your project. If that's not possible, in Netbeans select /var/www/public as the Project folder.
If Netbeans need references to the folders in /var/www, create symbolic folders inside public pointing to those in /var/www.
The last resource you have is to create a rewrite rule in Apache to make localhost.dev/public be the same as localhost.dev. You can look for this in Apache documentation.
I have a similar set up with one minor difference: my setup uses a remote site on my local development server. On the "Run Configuration" window of the project properties, I set "Run As" to "Remote Web Site (FTP, SFTP)". I don't think this affects the information in my answer, but I'm mentioning it just in case.
Go to the "Sources" window of your project properties, find the entry for "Web Root", click "Browse" and select the /var/www/public directory. That should cause xDebug to use localhost.dev/index.php. You'll notice when you go to the "Run Configuration" window and browse for the Index File that the browse window will start in "public" rather than "www".
An important note about this type of configuration that caused me a great deal of frustration.
When using xDebug, you'll want to be able to set breakpoints in and work with the files outside of the web root (public) directory. Because you've set the web root to /var/www/public, you won't be able to work with the files in /var/www/includes or /var/www/classes.
The thing you need to do is to add the files outside of your web root to the Global Include Path.
There are two methods for adding directories to your Global Include Path, which one you use depends on how you've configured your project.
In your case, the external directories are included in your project, so you need to add them via the "Options" interface. Go to Tools->Options and select the "PHP" tab, then add the /var/www/includes and /var/www/classes folders to the Global Include Path.
The other method for adding files to the Global Include Path is for files that are located outside of your project source folder. For directories like /var/folder_outside_www/, you use the "PHP Include Path" window in the project properties.
I haven't found a better way but I use this steps:
Menu:Project Properties -> Link:Run Configuration -> Button:Advanced
Debug URL, choose: Ask Every Time
Path Mapping, Server Path: http://localhost.dev/ ,Project Path: /var/www/public/
Now, when you start Debugging process, Netbeans will display Specify URL pop-up which you can change from http://localhost.dev/public/index.php into http://localhost.dev/index.php
Set /var/www/public as project folder (contain netbeans project folder) and include in project properties /var/www/includes/ and /var/www/classes/ as global include directories. Or best way use PHPStorm.
I'm trying to deploy an PHP application which is written with Zend Framework to a shared cPanel server.
There are not many tutorials available on this area online, however, I followed several of them. It is successful to run the test page which proves the zend framework is installed correctly.
However, since cPanel server has a default root directory called public_html/, it is impossible to simply rename it to the Zend Server's default public/.
As a result, I had two options in mind: (Say the project name is AAA)
1) upload my projects under the /public_html/ directory, then the project will be like /public_html/AAA/public, and etc.
However, this one simply fails to work.
My thought would be something wrong here with the baseUrl setting, however, no matter I comment ( which is to remove the baseUrl) or set to the root page, ( in this case /public_html/AAA) both failed.
2) I tried to follow the way listed in this article: http://blog.motane.lu/2009/11/24/zend-framework-and-web-hosting-services/. Still failed.
Can anyone suggest how to do it?
Really appreciate your help!
Just symlink it:
ln -s public public_html
then this structure will work:
htdocs/
myvhost.com/
public/
application/
library/
public_html # this is actually a symlink pointing to public
Whatever you do, dont just throw everything in the publicly accessible area... its just bad form :-)
I don't think ZF cares what you name your "public" directory. It's just the convention that's typically used.
I can't think of any ZF component or common use case where anything explicitly points at "public/...".
A project structure like this should work:
myproject/
application/
library/
public_html/ # this used to be public until you renamed it.