I'm using Apache2 running on Ubuntu-12.04 machine and I run my files through apache2 pointing to my folder in the local file system like
$ cd etc/apache2/
$ vi sites-enabled/000-default
And I change the location pointing to my folders in
DocumentRoot /home/user/foo/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/user/foo/>
What is the default location of Apache2 web root where if I would just copy my files the Apache server would pick it. For running hundreds of files through Apache2 each and every time I keep doing the above steps of changing the location manually. Is there any other best way of doing it.
It would be great if anyone could help me out.
If do an ls -l inside /etc/apache2/sites-enabled/ you'll see that 000-default is a symlink to /etc/apache2/sites-available/. The idea being that you create site definition files in sites-enabled, then symlink to them from sites-available... making it very simple to enable and disable sites as needed.
In fact, Ubuntu provides the a2ensite command to enable sites, and a2dissite to disable sites. This means all you have to do is create the vhost file in sites-available, then run a2ensite to enable it.
Take a look at https://help.ubuntu.com/12.04/serverguide/httpd.html for more details.
Related
I run bash script file through python code. The script is located /home/myscript.sh. The script convert html to pdf and print. If I run the python program in development mode it works fine but if I run in WSGI production mode it give me error "File not found" to print. But if I give access 7777 to home directory it works fine. And I need to do this access step every time whenever machine restarted. Also it not good solution.
I search a lot and change apache2.conf file
<Directory /home/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
But still there is problem. Please help me. I used Apache 2.4.9 version. Advance thanks
Update
In /etc/apache2/apache2.conf file
"User ${APACHE_RUN_USER}" and "Group ${APACHE_RUN_GROUP}"
And in envvars it sets like
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
Still problem exist.
If issue is with directory
Example /home
Move the file from /home to /var/www
sudo chown www-data:www-data /var/www/filename
or
sudo chown www-data:www-data /var/www/filename
If the issue with USB port
Example
ttyUSB0
,
ttyACM0
,
ttyACM1
Write script to change the owner
#!/bin/bash
sudo chown www-data:www-data /dev/ttyACM0
Call this script from your code using subprocess.call
But allow the user www-data to run this file as sudo with out password
sudo visudo
and add the below line in the last
www-data ALL = (ALL) NOPASSWD : /var/www/filename
or
www-data ALL = (ALL) NOPASSWD : ALL
I have a built a small React application with create-react-app, and it runs fine from the local server after running npm start. OK so far.
However, when I run npm run build, the process appears to execute correctly (creates build folder, which contains the bundled js file and the index.html file), but when I open index.html in my browser it renders nothing. What am I missing?
Aside: I also tried uploading it to a remote server and when I went to the URL the browser came back with...
Forbidden: You don't have permission to access / on this server.
...if anyone has any idea how to resolve this I'd also appreciate it.
However, when I run npm run build, the process appears to execute correctly (creates build folder, which contains the bundled js file and the html.index file), but when I open index.html in my browser it renders nothing. What am I missing?
When you run npm run build, it prints the relevant instructions:
You can’t just open index.html because it is supposed to be served with a static file server.
This is because most React apps use client-side routing, and you can’t do that with file:// URLs.
In production, you can use Nginx, Apache, Node (e.g. Express), or any other server to serve static assets. Just make sure that if you use client-side routing, you serve index.html for any unknown request, like /*, and not just for /.
In development, you can use pushstate-server for this. It works with client-side routing well. This is exactly what the printed instructions suggest you to do.
I also tried uploading it to a remote server and when I went to the URL the browser came back with Forbidden: You don't have permission to access / on this server.
You need to upload the contents of the build folder, not the build folder itself. Otherwise the server can’t find your index.html because it is inside build/index.html, and so it fails. If your server doesn’t detect a top-level index.html, please refer to your server’s documentation on configuring files served by default.
you can't run the production build by clicking on index.html, you have to modify your script like bellow.
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"deploy": "serve -s build"
}
after running npm run-script build, run npm run-script deploy, you will get some thing like this, this is where you can load your production build.
npm install -g serve before run npm run-script deploy.
Here You can solve this problem in 2 possible ways.
1.Change the routing history to "hashHistory" instead of browserHistory in the place of
<Router history={hashHistory} >
<Route path="/home" component={Home} />
<Route path="/aboutus" component={AboutUs} />
</Router>
Now build the app using the command
sudo npm run build
Then place the build folder in your var/www/ folder, Now the application is working fine with addition of # tag in each and every url. like
localhost/#/home
localhost/#/aboutus
Solution 2 : Without # tag using browserHistory,
Set your history = {browserHistory} in your Router,Now build it using sudo npm run build.
You need to create the "conf" file to solve the 404 not found page,
the conf file should be like this.
open your terminal type the below commands
cd /etc/apache2/sites-available
ls
nano sample.conf
Add the below content in it.
<VirtualHost *:80>
ServerAdmin admin#0.0.0.0
ServerName 0.0.0.0
ServerAlias 0.0.0.0
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
Now you need to enable the sample.conf file by using the following command
cd /etc/apache2/sites-available
sudo a2ensite sample.conf
then it will ask you to reload the apache server,using
sudo service apache2 reload or restart
then open your localhost/build folder and add the .htaccess file with content of below.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ / [L,QSA]
Now the app is working normally.
Note: change 0.0.0.0 ip to your local ip address.
I hope it is helpful to others.
open index.html file.
scroll near end and you will see
<script src="/static/js/2.b5125f99.chunk.js"></script><script src="/static/js/main.fcdfb32d.chunk.js"></script></body></html>
just add a dot in front of the two src attribute:
<script src="./static/js/2.b5125f99.chunk.js"></script><script src="./static/js/main.fcdfb32d.chunk.js"></script></body></html>
also if you have any styles you must also scroll near beginning where you will see:
<link href="/static/css/main.1eabf3ab.chunk.css" rel="stylesheet">
and also place a dot in front of the href attribute
<link href="./static/css/main.1eabf3ab.chunk.css" rel="stylesheet">
NOTE: filename may/will not be the same for you
also be sure to change this back when using a server or just run npm run build again(i have no idea what happens if you dont)
After building your application through create-react-app create-react-app
Run command npm run build After that run command npm install -g serve & finally serve -s build
More detailed information can be found from here create-react-app-deployment
Just enter these two commands in your terminal:
npm run build
npx serve -s build
After this just go to localhost:5000
'Web Server for Chrome' extension is super easy to use. Install it and set the directory to the ~/my-react-app/build/
cd to your build folder,
python -m SimpleHTTPServer 8080 to start a server on port 8080,
go to address localhost:8080/index.html in your browser.
I tried to run the same command and react app was also showing white screen.
main js file was taking the relative path to the file and showing error when I open js file in new browser "Your file was not found"
I make it to absolute path and its working fine.
https://www.taniarascia.com/getting-started-with-react/ and The final script can be found on the GitHub.
npm run build -> will create a folder build which include the index.html and static folder. By just clicking the index.html will open on a new browser's tab. But it shows only blank page. Why? because it's need a server to make it works.
Solution :
Move the file on other folder. Open the folder using VC Code. Open the index.html and right click -> select : Open with live server. A new tabs opened on your browser with related ip address and port.
Or you can run it on localhost using xampp :
Open the XAMPP server. Place it on localhost. And it must work.
I have following problem:
I would like to give an access for my Apache to index.html which exists on my Virtual Machine created by Vagrant. Directory is mounted by SSHFS with -o allow_other option.
Used tools and versions are:
System: Linux Ubuntu 15.04
Apache: 2.4.12
Mount via SSHFS with -o allow_other
Mount process is correct because directory and file are visible in my system. I can open/modify/etc them.
But when I try to open this file via Apache then I receive
Forbidden
You don't have permission to access / on this server.
Apache/2.4.12 (Ubuntu) Server at xxx.yyy.com Port 443
Configuration for Apache:
<Directory /var/www/interscape-frontend>
Options FollowSymLinks
Order allow,deny
Allow from all
Require all granted
</Directory>
DocumentRoot /var/www/interscape-frontend
Is it possible? If yes then how? :)
Thanks in advance!
What are the permissions on the folder/files? Who owns them?
If you cd /var/www and ls -al what words come up? See an example below.
-rw-rw-r--+ 1 (owner) (group) 277 Mar 16 00:31 build.xml
The left-most stuff is owner / group / all permissions. Following that, the owner and group are indicated. If apache isn't the owner (www-data usually), a part of the group listed, or the file does not permit all to have rw or rwx, then you may encounter the problem you've described.
You can change the owner and group with the following commands, respectively:
sudo chown -R (user) /path/to/directory
sudo chown -R (user):(group) /path/to/directory
Where the -R flag indicates to do it recursively (to all sub-directories).
Also, as per the apache 2.4 upgrade guide you can remove the following from your *.conf:
Order allow,deny
Allow from all
As they only apply to apache 2.2 and under.
I'm completly new to CGI and Apache but I'm trying out a few things. To start I wrote a simple hello CGI in C.
#include <stdio.h>
void main() {
printf("Content-type: text/html\n\n");
printf("<html>\n");
printf("<head><title>CGI Output</title></head>\n");
printf("<body>\n");
printf("<h1>Hello, world.</h1>\n") ;
printf("</body>\n");
printf("</html>\n");
}
compiled it gcc hello.c -o hello.cgi and placed it in /var/www/mycgi
Afterward I modified httpd.conf to add the following
ScriptAlias /mycgi/ "/var/www/mycgi/"
in the IfModule alias_module and
<Directory "/var/www/mycgi">
Options +ExecCGI
AddHandler cgi-script .cgi
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
I have then restarted Apache and when I go to localhost/mycgi/hello.cgi the browser just downloads the file instead of running it. Help will be greatly apreciated!
According to janos's advice, you should make sure apache2 has loaded the cgi_module: LoadModule cgi_module modules/mod_cgi.so. You can do this by:
sudo ln -s /etc/apache2/mods-available/cgi.load /etc/apache2/mods-enabled/cgi.load
then restart apache2 and it will load the cgi.load file this time.
Even if it's an old question, I think many other guys will get the same problem...
First we must tell Apache what kind of files he must "exec" and where are theses files:
Edit etc/apache2/apache2.conf (using nano for example)
Add
<Directory "/home/johnny/public_html">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
In this case Apache will try to exec all files ending with .cgi located in the public_html of user "johnny". You can add more than one extension for exemple:
AddHandler cgi-script .cgi .pif .gloup
and so on.
To compile: cd to the folder where the .c source is and then:
gcc hello.c
This will give a file named "a" (or maybe a.out, it depend on the OS).
To change the name of the result:
gcc hello.c -o ../public_html/my_cgi.gloup
in case of .gloup has been added with AddHandler and of an exec file you want to access via the web.
In many cases, this will give an error. You can try to change the right, exec and so on, it's of no use.
The problem came from the fact in many cases, we run gcc as "root", so the result owner is root. And when we try to exec it from the web, we're not "root".
The solution is to change user. For exemple if your public_html folder owner is "johnny", when you are logged as root, just do:
su - johnny
and now you "are" johnny. Just cd to the folder wih your c fles, compile using gcc and you'll be able to exec from the web.
I have just installed Apache 2.2.17, and I am using it for the first time.
Now when I try to start the server using the command service httpd start it gives me the message:
httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
Now I think I have to set ServerName and the IP address as I search through Google. But I don't know in which file I have to set.
How can I fix this problem?
sudo vim /etc/apache2/httpd.conf
Insert the following line at the httpd.conf: ServerName localhost
Just restart the Apache: sudo /etc/init.d/apache2 restart
Yes, you should set ServerName:
http://wiki.apache.org/httpd/CouldNotDetermineServerName
http://httpd.apache.org/docs/current/mod/core.html#servername
You can find information on the layouts used by the various httpd distributions here:
http://wiki.apache.org/httpd/DistrosDefaultLayout
In your case the file to edit is /etc/httpd/conf/httpd.conf
I was NOT getting the ServerName wrong. Inside your VirtualHost configuration that is causing this warning message, it is the generic one near the top of your httpd.conf which is by default commented out.
Change
#ServerName www.example.com:80
to:
ServerName 127.0.0.1:80
Under Debian Squeeze;
Edit Apache2 conf file : vim /etc/apache2/apache2.conf
Insert the following line at the apache2.conf: ServerName localhost
Restart Apache2: apache2ctl restart or /etc/init.d/apache2 restart
Should work fine (it did solve the problem in my case)
tks noodl for the link on the different layouts. :)
sudo nano /etc/apache2/httpd.conf
search for a text ServerName in nano editor <Ctrl + W>
Insert the following line at the httpd.conf: ServerName localhost
Just restart the Apache: sudo /usr/sbin/apachectl restart
Another option is to ensure that the full qualified host name (FQDN) is listed in /etc/hosts.
This worked for me on Ubuntu v11.10 without having to change the default Apache configuration.
" To solve this problem You need set ServerName.
1: $ vim /etc/apache2/conf.d/name
For example set add ServerName localhost or any other name:
2: ServerName localhost
Restart Apache 2
3: $ service apache restart
For this example I use Ubuntu 11.10.1.125"
FQDN means the resolved name over DNS. It should be like "server-name.search-domain".
The warning you get just provides a notice that httpd can not find a FQDN, so it might not work right to handle a name-based virtual host. So make sure the expected FQDN is registered in your DNS server, or manually add the entry in /etc/hosts which is prior to hitting DNS.
If you are using windows there is something different sort of situation
First open c:/apache24/conf/httpd.conf.
The Apache folder is enough not specifically above path
After that you have to configure httpd.conf file.
Just after few lines there is pattern like:
#Listen _____________:80
Listen 80
Here You have to change for the localhost.
You have to enter ipv4 address for that you can open localhost.
Refer this video link and after that just bit more.
Change your environment variables:
In which you have to enter path:
c:apache24/bin
and
same in the SYSTEM variables
If any query feel free to ask.
Two things seemed to do it for me:
Put all aliases for 127.0.0.1 in /etc/hosts in a single line (e.g. 127.0.0.1 localhost mysite.local myothersite.local
Set ServerName in my httpd.conf to 0.0.0.0 (localhost or 127.0.0.1 didn't work for me)
Editing /etc/hosts got rid of long response times and setting the ServerName got rid of OP's warning for me.
who are still couldnt resolve the problem and using mac then follow this
1.goto the root folder /
cd usr/local/etc/apache2/2.4
3.sudo nano httpd.conf
4.change #servername to ServerName 127.0.0.1:8080 press ctrl+o,+return+ctrl x
5.then restart the server apachectl restart
If you are using windows, remove comment on these lines and set them as:
Line 227 : ServerName 127.0.0.1:80
Line 235 : AllowOverride all
Line 236 : Require all granted
Worked for me!
Here's my two cents. Maybe it's useful for future readers.
I ran into this problem when using Apache within a Docker container. When I started a container from an image of the Apache webserver, this message appeared when I started it with docker run -it -p 80:80 my-apache-container.
However, after starting the container in detached mode, using docker run -d -p 80:80 my-apache-container, I was able to connect through the browser.
I am using ubuntu 22.04
I installed the apache2 at the location '/usr/local/apache2'
I just edited the '/usr/local/apache2/conf/httpd.conf' file.
run the following commands
cd /usr/local/apache2/conf
sudo nano httpd.conf
find this comment
#ServerName www.example.com:80, in my case it is at line 197
after that add this
ServerName localhost
don't modify anything else in this file!
Thank you!