Starting built in Apache server in Mac OS X 10.9 (Mavericks) - apache

I'd like to start my apache server in my Mac OSX Mavericks. Here is what I did:
launch the terminal application
sudo apachectl start
The server started without problem. But I got the following problem when I tried to open the localhost in web browser:
You don't have permission to access / on this server.
Here is my /etc/apache2/httpd.conf: (I didn't change anything here)
DocumentRoot "/Library/WebServer/Documents"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all </Directory>
<Directory "/Library/WebServer/Documents">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Can anybody advise what could be the cause ? Thanks

Easy way to start apanche server in mavrick
execute this command
sudo apachectl start
sudo apachectl stop
sudo apachectl restart

First, point to a file you know is present. By default there is no index.html or similar file (it produces the "It Works!" page from index.html.en
ls /Library/WebServer/Documents
PoweredByMacOSX.gif
PoweredByMacOSXLarge.gif
index.html.en
http://xxx.xxx.xxx.xxx/PoweredByMacOSX.gif
Next, try repairing permissions. If that doesn't work:
sudo chown -R root.wheel /Library/WebServer/Documents
sudo chmod -R a+rX /Library/WebServer/Documents
When in doubt:
sudo tail /var/log/apache2/error_log

Related

Connection Refused after Changing Apache DocumentRoot on OS X El Capitan

I am using OS X El Capitan, and changed the Apache2 config file /etc/apache2/http.conf to relocate the file path.
I modified
DocumentRoot "/Library/WebServer/Documents"
to
DocumentRoot "~/Dropbox/myweb", and
<Directory "Library/WebServer/Documents">
to
<Directory "~/Dropbox/myweb">.
Directory content is
Options FollowSymLinks Multiviews
MultiviewsMatch Any
AllowOverride None
Require all granted
and changed the folder like
sudo chmod 777 ~/Dropbox/myweb
I restarted Apache then I cannot connect to http://localhost anymore. Opera returns me
Opera's connection attempt to localhost was rejected. The website may be down, or your network may not be properly configured.
Chrome returns me
This webpage is not available
ERR_CONNECTION_REFUSED
I am not sure if I missed any step?
Try to run apachectl configtest to figure if your configurations are all OK. Got the same problem here and configtest told me something was wrong in httpd-userdir.conf file.

Change root directory of Apache2

sorry if this is simple but I looked everywhere online I still cannot find a solution.
- I'm running ubuntu 14 and installed Apache2.
- the problem is that I'm trying to change the root directory to my home directory.
the original directory is /var/www/html and checking permission it belongs to root.
I edited two files,
sudo nano /etc/apache2/sites-available/000-default.conf
sudo nano /etc/apache2/apache2.conf
for the latter I changed, /var/www/html to my home/user1/wwww
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
at one point I even changed permssion of my home/user1/www to www-data:webdev ut I keep getting page forbidden. Can anyone help with this? thanks in advance.

How to run cgi script on apache server

This is my program:
[root#localhost cgi-bin]# locate first.pl
/home/Ram/Desktop/work/first.pl
/usr/local/apache2/cgi-bin/first.pl
[root#localhost cgi-bin]# cd /usr/local/apache2/cgi-bin/
[root#localhost cgi-bin]# vi first.pl
#!/usr/bin/perl -w
use warnings;
use warnings;
use CGI;
print "content-type: text/html\n\n";
print "<h2>Hello, World!</h2>\n";
I am calling the script from my browser like this:
http://localhost/usr/local/apache2/cgi-bin/first.pl
I didn't get output, but I'm getting an error:
Not Found
The requested URL /usr/local/apache2/cgi-bin/first.pl was not found on this server.
Apache/2.2.15 (CentOS) Server at localhost Port 80
I checked in web browser whether the Apache web server is working or not by using :
https://localhost
It us showing the welcome page.
How do I resolve this error?
You basically need to change two files after installing apache2 on linux.
Go to terminal and set the following configs:
sudo vim /etc/apache2/sites-enabled/000-default.conf and add the follwing:
<Files ~ "\.(pl|cgi)$">
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options +ExecCGI
PerlSendHeader On
</Files>
sudo vim /etc/apache2/apache2.conf and add the following:
<Directory /var/www/cgi-bin/>
AddHandler cgi-script .cgi .pl
Options FollowSymLinks ExecCGI
AllowOverride None
</Directory>
After adding these two config changes, write a perl script, place it in the cgi-bin directory, and then give it sufficient privileges (sudo chmod 755 <filename>)
Finally, restart apache2: sudo apache2ctl restart
Screenshots:
Yes, the above process works but the easy way is:
Enable the CGI- sudo a2enmod cgi
Restart the Apache and it works -service apache2 restart
Run the cgi file http://localhost/cgi-bin/1.sh
Best Of Luck !!
In your web configuration (httpd.conf or your virtual host configuration file) you should have the following fragment:
ScriptAlias /cgi-bin/ /etc/local/apache2/cgi-bin/
<Directory "/etc/local/apache2/cgi-bin">
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
</Directory>
restart the server, don't forget to chmod +x /usr/local/apache2/cgi-bin/first.pl and then load http://localhost/cgi-bin/first.pl
This assumes that either there are no virtual hosts in your config, or that the virtual host you configured is the default one. See the apache docs if needed.

403 Forbidden You don't have permission to access /folder-name/ on this server

I was looking for an answer to my problem, but I could'nt find any answer which solves my case.
The problem is that I can't access the app folders in my var/www/ folder. When I go to localhost/ i get the message that my server is running and I have access to phpmyadmin too. But when I go to any localhost/folder-name i get the 403 error:
Forbidden
You don't have permission to access /folder-name/ on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
How can I solve it? Btw I'm using Ubuntu 13.04, and thanks for your answers. :)
Solved the problem with:
sudo chown -R $USER:$USER /var/www/folder-name
sudo chmod -R 755 /var/www
Grant permissions
under etc/apache2/apache2.conf, you can find one or more blocks that describe the server directories and permissions
As an example, this is the default configuration
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
you can replicate this but change the directory path /var/www/ with the new directory.
Finally, you need to restart the apache server, you can do that from a terminal with the command: sudo service apache2 restart
if permission issue and you have ssh access in root folder
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
will resolve your error
**403 Forbidden **
You don't have permission to access /Folder-Name/ on this server**
The solution for this problem is:
1.go to etc/apache2/apache2.conf
2.find the below code and change AllowOverride all to AllowOverride none
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all Change this to---> AllowOverride none
Require all granted
</Directory>
It will work fine on your Ubuntu server
Solved issue using below steps :
1) edit file "/etc/apache2/sites-enabled/000-default.conf"
DocumentRoot "dir_name"
ServerName <server_IP>
<Directory "dir_name">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory "dir_name">
AllowOverride None
# Allow open access:
Require all granted
2) change folder permission
sudo chmod -R 777 "dir_name"

You don't have permission to access / on this server

I have CentOS 6.1 server and I installed apache 2.2.15 on it.
Now When I try to access it from another pc (windows 7) from IE (http:/// (=centos ip)) I get the "You don't have permission to access / on this server." error. I even created phpinfo.php file with content of "" on "var/www/html" and when I try to access it by using "http://*/phpinfo.php" in IE, I get not found error. What should I do?
my httpd.conf for directiry is like this:
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Edit httpd.conf file, which is in /etc/httpd/conf/httpd.conf. Add the below code.
<Directory "/">
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Allow from all
</Directory>
<Directory "/home/">
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Allow from all
</Directory>
After the line no. 555 (in my case) . Check for the file permissions and restart the server.
service httpd restart
Now, it will work . Still you are facing the same problem, disable the seLinux in /etc/selinux/config change SELINUX=disabled and restart the server as mentioned above and try it.
Hope this helps
Set SELinux in Permissive Mode using the command below:
setenforce 0;
Check file permissions of the /var/www/html and the ALLOW directive in your apache conf
Make sure all files are readable by the webserver and the allow directive is like
<Directory "/var/www/html">
Order allow,deny
Allow from all
</Directory>
if you can see files then consider sorting the directive to be more restrictive
Fist check that apache is running. service httpd restart for restarting
CentOS 6 comes with SELinux activated, so, either change the policy or disabled it by editing /etc/sysconfig/selinux setting SELINUX=disabled. Then restart
Then check locally (from centos) if apache is working.
Try to use the following:
chmod +rx /home/*
If you set SELinux in permissive mode (command setenforce 0) and it works (worked for me) then you can run restorecon (sudo restorecon -Rv /var/www/html/) which set the correct context to the files in Apache directory permanently because setenforce is temporal. The context for Apache is httpd_sys_content_t and you can verify it running the command ls -Z /var/www/html/ that outputs something like:
-rwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 index.html
In case the file does not have the right context, appear something like this:
drwxr-xr-x. root root unconfined_u:object_r:user_home_t:s0 tests
Hope it can help you.
PD: excuse me my English
Create index.html or index.php file in root directory (in your case - /var/www/html, as #jabaldonedo mentioned)
Right click your www folder and click on properties. Navigate to permissions and change all to read and write then click on "Apply permission to enclosed files" and your are done!!
Maybe its too late but this will definitely help some other person
Check the apache User and Group setting in the httpd.conf. It should default to apache on AMI/RedHat or www-data on Debian.
grep '^Group\|^User' /etc/httpd/conf/httpd.conf
Then add the apache user to the group setting of your site's root directory.
sudo usermod -a -G <your-site-root-dir-group> apache
try to edit httpd.conf
<Directory "/usr/local/www/apache24/cgi-bin">
Options Indexes FollowSymLinks Includes ExecCGI
Require all granted
</Directory>
For CentOS 8 your /etc/httpd/conf.d/awstats.conf file needs to look like this and you need to stick in your IP address and restart your httpd service unless you want to whole world to have access to it!
#
# Directives to add to your Apache conf file to allow use of AWStats as a CGI.
# Note that path "/usr/share/awstats/" must reflect your AWStats install path.
#
Alias /awstatsclasses "/usr/share/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/share/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/share/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/share/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/share/awstats/wwwroot">
Options None
AllowOverride None
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require <Your IP Address here>
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Allow from <Your IP address here>
Allow from ::1
</IfModule>
</Directory>
# Additional Perl modules
<IfModule mod_env.c>
SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins
</IfModule>
Remember that if you IP address changes you need to update the file and restart the httpd server. BTW you can see your ip address as it looks from the outside by simply googling "my ip"
Set required all granted in /etc/httpd/conf/httpd.conf