I develop a pure front-end app with an index-file called index.html. Everytime I push to heroku, i need to rename it index.php, in order to tell heroku to use php. Is there another way to declare what type of server I want? So that I get to keep my file as an html-file?
You can also just drop an empty composer.json into your project to make Heroku treat your project as a PHP project.
The preference of index.php over index.html comes from the default DirectoryIndex directive that Apache uses on Heroku; it has nothing to do with your browser. To change it, you could drop a .htaccess with DirectoryIndex index.html into your application.
If you just want raw performance for your static site, it's also probably a good idea to use Nginx. The default configuration should be reasonable for your purposes so add a Procfile with web: vendor/bin/heroku-php-nginx to your project along with an empty composer.json (and no index.php) and you're good to go.
Also see https://devcenter.heroku.com/articles/php-support and https://devcenter.heroku.com/articles/custom-php-settings for more details.
You can do that simple node.js app with ExpressJS;
Let say your project folder has a sub folder called public,
var express = require('express');
var app = express();
app.use('/', express.static(__dirname + '/public'));
var port = Number(process.env.PORT || 5000);
app.listen(port, function() {
console.log('Your files will be served through this web server')
});
Save this code in app.js, put your static files under public folder, and prepare your Procfile
Final folder structure will be;
yourproject
--public/
----your staticfiles
--app.js
--Procfile
Procfile will be;
web: node app.js
And deploy your project. When you request your static files like; .../index.html, index.html will be served under public folder
Add a empty file called index.php, this will be used by heroku, though, index.html will be prioritised by browsers.
Related
I created a vue/cli 3 project and its in my documents/project folder. Im running it on port 3000 with "npm run serve" command. Now, i want to have a backend folder somewhere to serve PHP files. But i want both the frontend and backend to be in the same folder structure.
Currently, my vue is in my documents folder and my php is in my xampp folder. The problem im having with this is managing 2 folders and git for the same application. Also, this causes my ajax calls from my vue projet to use a silly url such a "http://localhost:80/project/file.php". Id like to use relative paths like "backend/clients/getClient.php" that would be somewhere within my vue project.
This is what i would like:
myProject
frontend
my vue stuff like public and src folders
backend
my php files
It doesnt have to be exactly that way but the point is that now i have a single folder and git for a single project.
thank you.
The way I do this is as follows:
1)
I put the php files in a subfolder the public/ folder in the vue/cli project structure.
That way, these files will get copied to the dist folder on building the project.
For example: I have the file /public/api/endpoint.php, this will end up in dist/api/endpoint.php.
For testing locally I now copy the php files to the xampp/htdocs dir whenever I change them. But I guess you could skip this step by setting up a xampp alias directory. (But I haven't tried this myself yet)
2)
The ajax urls still differ between local development mode and production. To solve this I define a webpack plugin in my vue.config.js:
const webpack = require('webpack')
const API_URL = {
production: JSON.stringify('https://www.project.com/api/endpoint.php'),
development: JSON.stringify('http://localhost/project/api/endpoint.php')
}
// check environment mode
const environment =
process.env.NODE_ENV === 'production' ? 'production' : 'development'
module.exports = {
...
configureWebpack: {
plugins: [
new webpack.DefinePlugin({
API_URL: API_URL[environment]
})
]
},
...
}
Then use this in a vue/js file like:
const apiUrl = API_URL // eslint-disable-line
(the eslint directive is only needed If you have linting turned on with eslint, it will throw an error that API_URL is not defined.)
We use CakePHP 2.7.9 and Minify plugin on a CentOS server running Apache 2.2.
https://github.com/maurymmarques/minify-cakephp
The plugin works fine and now we can minify css files like this.
echo $this->Minify->css(array('default', 'global'));
The code above generates URL like this.
http://example.com/min-css?f=default.css,global.css
And now we want to deny access to original files under webroot/css. How can it be done in CakePHP? We want to return 404 or 401 or something like that for direct URL access like this.
http://example.com/css/default.css
And now we want to deny access to original files under webroot/css
Simply don't but non public code and files into the public webroot. It's not recommended in any case. Point your minifier to the files and set its output folder to webroot.
We use task runners and keep the minification code outside of the actual app. This is stuff that doesn't belong into the application itself - IMHO.
We use php Robo and on the JS side Gulp for minification and automatically trigger the tasks on deployment. All our SCSS and JS files are outside of the webroot. We have just a few asset includes in our app code and they almost never change. Robo and Gulp have watchers that rewrite the asset files as we change them on when the app is deployed it automatically generates minified files.
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
I'm too newbie to Laravel...I have written this route to echo "Hello World", but It errors NotFoundHttpException
This is my routes.php (no other code is in the file but the following):
Route::get('/', function(){
return "HELLO WORLD";
});
I have also enable mode_rewrite, and also set AlloOverride to 'all' in apache module.
This is also the URL is use to access the page:
http://localhost/laravel/public/mostafa
Do:
php artisan serve
Use that URL to visit your website.
You will see that you get some output like:
Laravel development server started on http://localhost:8000
When you have no clue what Artisan is take a look at this;
http://laravel.com/docs/artisan
Navigate into your project directory with your command prompt and run there the serve command from above.
Example:
Sometimes the default .htaccess file located in public folder doesn't work in apache. Try altering the .htacess as mentioned here. Alternatively renaming your laravel project folder would work especially in XAMPP.
Some other frameworks treat route definitions as relative to the project web root so a path defined as /foo/bar will match http://example.com/additional/levels/laravel/public/foo/bar and will work without changes even if you move the project tree somewhere else in your public web hierarchy. Laravel, however, considers routes as absolute paths so /foo/bar will only match http://example.com/foo/bar.
The simplest solution is probably to move your code into a separate virtual host and point its document root to laravel/public/. (In this case it seems that's actually the intended set-up.)
(I suppose there's a way to make the framework assume an implicit prefix but I've only been using Laravel for 10 minutes.)
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.