Apache2 executing php but not executing html codes - apache2

How can I make it execute both html and php i used this code but it wont work
<FilesMatch ".+\.html$>
Sethandler application/x-httpd-php-source
<FilesMatch>

Related

Hosting a React App on an Apache Server using rhel7, but my Javascript does not appear to be executing

I'm attempting to host a react app on an apache server, and I'm running into the classic blank white page issue. I've reviewed every post that I can find on the subject, but they don't appear to be the same issue that I have.
For simplicity's sake, I've removed my css files from the build, just in case they're further complicating matters.
I set my homepage to './' in my package.json, then ran npm run build on the app.
I'm copying the files over into my apache root in /var/www/html (I'm removing them from the build folder for simplicity's sake)
I modify the html to set the javascript calls to look like this
<script type='text/jsx' src='./var/www/html/static/foo.js'>
I've added in a .htaccess file at the same level as index.html per the linked instructions. I've run
restorecon -r /var/www/html'
one level down to ensure the correct connectivity is re-established.
I've updated my .config file with a DocumentRoot of '/var/www/html' and left my DirectoryIndex as index.html. I also added some extra stuff (that should be redundant) from a link in the guide I posted above
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
ServerName localhost
The only relevant "new" thing I added was making the server localhost. Someone on reddit suggested it in another post that I found.
When I check my console, I see one request to http://localhost/ that retrieves my html from index.js. But I don't seem to be loading or executing any of my javascript on the other side, so nothing is loading.
Does anyone have any ideas on what I'm doing wrong? I'm not even sure what's causing the issue at this time.
I finally got the dang thing working! I'm writing this out as much for my own edification as for anyone else's.
I set the homepage of the app to be '.' and removed the servername component from the config file. I modified the html so that instead of having paths that went './foo/bar' they read '/foo/bar.' Then, I moved the script components of the html tag outside of the body (below it) and everything ran.
I have no idea why this was so much of a hassle-- I just sort of assumed React would work out of the box with something like Apache-- but it's finally, finally done!

React.js and folder access denied for user

I don't know if there is any type of post like this one here on StackOverflow but I just wonder how do I make so people who visit my site can't get access to "ip/folder names".
If it for some help I use react.js and I know some people use the .htaccess file but it doesn't work for me or maybe because I do it wrong. I am kind of new of this sort of things.
Error page
I want actually do so if people visit some page/folder or file they come to a page it says "404 page error"
To be able to use .htaccess files depends on how the apache configuration is done on your server. A .htaccess file needs permission to be able to override standard web configurations. If you want to set that up and use them you can try:
sudo vim /etc/apache2/sites-available/default
Then make sure the line AllowOverride has the value All. That means local .htaccees files are allowed to override.
<Directory /var/www/>
...
AllowOverride All
...
</Directory>
Save and restart the service
sudo service apache2 restart
In your .htaccess file you can add following for creating an custom error page
ErrorDocument 404 /my_custom_error_page.html
Here you can read more about writing .htaccess files
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file
Hope that helped a bit.

When does apache2 execute a .wsgi script when using daemon process groups?

Given a simple apache2 conf as below, when will django.wsgi execute? It seems like it executes only the first time a query arrives and never again. I was expecting it to execute on apache startup and then never again. Can anybody shed some light on how this works?
WSGIDaemonProcess site-1 user=user-1 group=user-1 threads=25
WSGIProcessGroup site-1
WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi
<Directory /usr/local/django/mysite/apache>
Order deny,allow
Allow from all
</Directory>
WSGI script files are technically not executed but are imported. Thus they are like any other module in Python, they are loaded once. In this case it occurs when the request first arrives and the application mapped by that WSGI script file is required.
Once loaded, the WSGI application object is executed once per request.
There are some exceptions to that as far as reloading of the WSGI script file in certain circumstances. For an explanation of that read:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
Now although it is loaded the first a request requires it to be, you can force that it be loaded on process startup using the WSGIImportScript directive:
http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIImportScript
or the use of process-group and application-group options together with the WSGIScriptAlias directive. The latter was introduced in mod_wsgi 3.o.
http://code.google.com/p/modwsgi/wiki/ChangesInVersion0300

Is it possible to use ng-include without web server?

I'm running an AngularJS app which merely include a file
<div ng-include src="'sample.html'"></div>
That works when run under web server. But if the web app is run from merely double clicking from file explorer (i.e. not from web server), it doesn't include the file
Does ng-include works outside of web server? I checked the Network status on Chrome, it says OPTIONS on Method, and Load cancelled on Status
One workaround is to inline your templates:
<script type="text/ng-template" id="sample.html">
<div>This is my sample template</div>
</script>
Fiddle.
This puts your template into Angular's template cache. When an ng-include directive is processed, Angular checks the cache first.
The problem is because of file:// protocol. Mostly all browsers disallow XHR requests when file is been served from file://. That is why AJAX requests are failing. And ng-include use them to download files.
You can launch Chrome with --allow-file-access-from-files parameter to disable checks for file://.
FireFox should load files if they are in same folder (check this for more info).
But personally prefer to start simplest NodeJS script to serve files, that could be found at angular-seed project. It require just node binary and gives a feeling of a normal web server.
I had a similar problem and I solved it by running a simple nodejs server to serve static files - http-server. Make sure you have nodejs installed, then:
Install:
$ sudo npm install http-server -g
Then from your project directory:
$ http-server
Now you can access your files from:
localhost:8080/whatever-file-you-have-in-your-directory.html
You can use Grunt along with the grunt-html plug to precompile your templates along with your Angular code.
Using virtual Host on your xampp is the best solution , and give custom name like yourProject.dev
update httpd-vhosts file in C:\xampp\apache\conf\extra\httpd-vhosts
<VirtualHost *:80>
ServerName yourProject.dev
ServerAlias www.yourProject.dev yourProject.com www.yourProject.com
DocumentRoot "C:\Users\customFolder/yourProject"
<Directory "C:\Users\customFolder/yourProject">
DirectoryIndex index.html index.php
ServerSignature Off
Options Indexes FollowSymLinks IncludesNoExec
AllowOverride All
Allow from all
Require all granted
</Directory>
</VirtualHost>
then update your hosts file to 127.0.0.1 yourProject.dev
in Windows : c:\Windows\System32\Drivers\etc\hosts
in Mac : /private/etc/hosts
don't forget to rest your xampp/wampp

How to install cakephp on localhost?

I wanna to know how to install cakephp on localhost?
Please explain me.
I usually make an apache and mysql installation on a linuxbox. I can use windows too, however I do not recommend it ;)
So, I usually make a new entry into the /etc/hosts file to make a sitename available to cakephp.
127.0.0.1 localhost caketest.local
next step to copy all cakephp files into a subdirectory inside /home/myusername/public_html/caketest
app
cake
index.php
plugins
README
vendors
.htaccess
then I set up the site to apache (not neccessary),
<VirtualHost *:80>
DocumentRoot "/home/myusername/public_html/caketest"
ServerName caketest.local
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/home/myusername/public_html/caketest">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
restart apache. you also need to edit the .htaccess files and place a RewriteBase directive with hte path to the actual directory, e.g.
RewriteBase /~myusername/caketest
create a database, set the db connection in cake config files and that's all.
you can point your browser to http://caketest.local
if you do not want a test site url you can skip hosts, and apache vhost creation, but the url to use should be http:/localhost/~myusername/caketest
another important thing is to enable userdir modul in apache, and also check if using php is enabled in userdirs too.
If you're on windows, get WAMP. Install it, then download CakePHP in C:\wamp\www\. Extract CakePHP in that folder so you have a folder kind of like this: C:\wamp\www\cakephp\. Now you can access the installation by going to localhost/cakephp/.
An old article of mine but still quite relevant:
Installing CakePHP
Assuming you have a *AMP setup (Apache+MySQL+PHP), just copy the files to your htdocs folder. On Ubuntu, it's /var/www, so you would create /var/www/myApp and copy the whole Cake structure into there, ending up with something like:
/var/www/myApp/app/
/var/www/myApp/cake/
/var/www/myApp/vendors/
/var/www/myApp/index.php
/var/www/myApp/.htaccess
Then you can access your app by the url: http://localhost/myApp

Resources