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.
Related
I installed phpmyadmin using homebrew
brew install phpmyadmin
The output came back as follows:
Note that this formula will NOT install mysql. It is not
required since you might want to get connected to a remote
database server.
Webserver configuration example (add this at the end of
your /etc/apache2/httpd.conf for instance) :
Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
Then, open http://localhost/phpmyadmin
More documentation : file:///usr/local/Cellar/phpmyadmin/4.3.11.1/share/phpmyadmin/doc/
Configuration has been copied to /usr/local/etc/phpmyadmin.config.inc.php
Don't forget to:
- change your secret blowfish
- uncomment the configuration lines (pma, pmapass ...)
==> Summary
🍺 /usr/local/Cellar/phpmyadmin/4.3.11.1: 1,898 files, 55.2M, built in 2 seconds
I updated httpd.conf with that block of details. I also updated my blowfish and uncommented the configuration lines as it states.
When I go to localhost/phpmyadmin i get a 404 error.
Any ideas where I would find the interface so I can more easily build/update my database(s).
I experienced this problem, too.
In order to use phpMyAdmin in your apache, you have to make symbolic link in /usr/local/var/www/htdocs with this command. (If you didn't changed your DocumentRoot)
cd /usr/local/var/www/htdocs
ln -s /usr/local/Cellar/phpmyadmin/4.3.11.1/share/phpmyadmin ./phpmyadmin
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
Web.py is free and lightweight. Amazon also provides you with a free web service for a year. How do I set up apache2 onto my server?
*EDIT: Formatting this is impossible. I'll try to do it later. I have such a beautifully written .txt file with fantastic formatting.
I apologize if this isn't thorough. I worked through how to set it up for my very specific setup. However, some of the annoying tricks are solved and may help you on your journey to set it up!!!
I won't walk you through signing up for amazon. There are a million tutorials out there.
Make sure you have an amazon ec2 instance up and running for ubuntu 13.04. Once you're logged in and have your instance launched, get the following going
*I've omitted some numbers as they are specific to our application and don't help.
Give yourself root access
sudo su (if you do this you dont need to sudo anything)
Get Apache 2
apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
Get Pip
apt-get install python-pip
Get web.py
pip install web.py
Get MySQL
apt-get install python-mysql.connector python-mysqldb mysql-client-core-5.5 mysql-server
set password to: whatever password you want
Get mod_wsgi
apt-get install libapache2-mod-wsgi
6.1 Check to see its working
service apache2 restart
put ip address in web browser to see if it works
enable mod_rewrite
a2enmod rewrite
SFTP (filezilla)
8.1 Giving permissions to allow filezilla in
cd /var/www
mkdir legal #this is our main directory. Name it whatever you want
chown -R ubuntu /var/www/
chmod -R 755 /var/www/
8.2 Connecting in Filezilla
Open Site manager
host: some ip like 54.213.173.233
Port: 22
Protocol: SFTP
Login Type: Normal
User: Ubuntu
Pass: empty
Edit -> Setting -> SFTP: add your key
8.3 Add all of your code Using Filezilla
9 Modifying your code:
go to your main.py
9.1 Wsgifunc()
#add these somewhere in your main file
app = web.application(urls, globals(),autoreload=False)
application = app.wsgifunc()
web.config.debug = True # Change to False
db = web.database(dbn='mysql', host='127.0.0.1', port=3306, user='user goes here', pw='pas goes here', db='')
9.2 Ensure python can find all of your files
AT THE TOP OF YOUR FILE
import os
import sys
root = os.path.join(os.path.dirname(file)+"/")
sys.path.insert(0, root)
modules = os.path.join(os.path.dirname(file)+"/server/")
sys.path.insert(1, modules)
os.chdir(root)
os.environ["SCRIPT_NAME"] =''
os.environ["REAL_SCRIPT_NAME"] = ''
Configuration of apache
cd /etc/apache2/sites-available
10.1 Changing the default file
vim default
change everything to:
*our main folder is called /legal. In it we have our icons and favicons and such in /static. Change these accordingly
ServerAdmin webmaster#localhost
DocumentRoot /var/www/legal/
DirectoryIndex main.py
WSGIScriptAlias / /var/www/legal/
Alias /static /var/www/legal/static/
Options FollowSymLinks
AllowOverride None
Options +Indexes +FollowSymLinks +MultiViews
#changed from non to FileInfo
AllowOverride FileInfo Options
Order allow,deny
allow from all
#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
#
# AllowOverride None
# Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
# Order allow,deny
# Allow from all
#
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access.log combined
10.2 Test to see if there are errors
apachectl configtest
10.3 Monitor For errors when messing with config files (optional)
tail -f /var/log/apache2/error.log
and
11 Creating a .htaccess file
cd /var/www/legal #this is where our main file is located
vim .htaccess
Then add:
SetHandler wsgi-script
Options +ExecCGI +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^favicon.ico$
RewriteCond %{REQUEST_URI} !^(/.*)+main.py/
RewriteCond %{REQUEST_URI} !^(/.)+.(css|png|js|jpg|ttf|otf|gif|ico)$
RewriteRule ^(.)$ main.py/$1 [PT]
#for reals, it never copies correctly... just a heads up
12 Setting up the database
cd /var/www/legal/server/subapplications
mysql -u root -p'whatever password you want'
12.1 create the database in sql
create database intravires;
###do whatever you need to do here
quit
13 Restart
service apache2 restart
13.1 If broken,Check the logs:
tail -f /var/log/apache2/error.log
14 Profit!
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
I have a server from AWS EC2 service running on Linux ubuntu and I have installed apache, php, and mysql.
I have added a .htaccess file in my document root /var/www/html.
I entered this code in it:
ErrorDocument 404 /var/www/html/404.php and it is still not showing up.
I kept entered this command multiple times: sudo service httpd restart to restart the server but no changes displayed...
How can I fix this... Did I do something wrong?
First, note that restarting httpd is not necessary for .htaccess files. .htaccess files are specifically for people who don't have root - ie, don't have access to the httpd server config file, and can't restart the server. As you're able to restart the server, you don't need .htaccess files and can use the main server config directly.
Secondly, if .htaccess files are being ignored, you need to check to see that AllowOverride is set correctly. See http://httpd.apache.org/docs/2.4/mod/core.html#allowoverride for details. You need to also ensure that it is set in the correct scope - ie, in the right block in your configuration. Be sure you're NOT editing the one in the block, for example.
Third, if you want to ensure that a .htaccess file is in fact being read, put garbage in it.
An invalid line, such as "INVALID LINE HERE", in your .htaccess file, will result in a 500 Server Error when you point your browser at the directory containing that file. If it doesn't, then you don't have AllowOverride configured correctly.
Enable Apache mod_rewrite module
a2enmod rewrite
add the following code to /etc/apache2/sites-available/default
AllowOverride All
Restart apache
/etc/init.d/apache2 restart
If you have tried all of the above, which are all valid and good answers, and your htaccess file is not working or being read change the directive in the apache2.conf file. Under Ubuntu the path is /etc/apache2/apache2.conf
Change the <Directory> directive pointing to your public web pages, where the htaccess file resides. Change from AllowOverride None to AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
I had the same problem and found the answer and explanation on the Ubuntu Ask! forum https://askubuntu.com/questions/421233/enabling-htaccess-file-to-rewrite-path-not-working
For Ubuntu,
First, run this command :-
sudo a2enmod rewrite
Then, edit the file /etc/apache2/sites-available/000-default.conf using nano or vim using this command :-
sudo nano /etc/apache2/sites-available/000-default.conf
Then in the 000-default.conf file, add this after the line DocumentRoot /var/www/html. If your root html directory is something other, then write that :-
<Directory "/var/www/html">
AllowOverride All
</Directory>
After doing everything, restart apache using the command sudo service apache2 restart
Most probably, AllowOverride is set to None. in Directory section of apache2.conf located in /etc/apache2 folder
Try setting it to AllowOverride All
Just follow 3 steps
Enable mode_rewrite using following command
sudo a2enmod rewrite
Password will be asked. So enter your password
Update your 000-default.conf or default.conf file located at /etc/apache2/sites-available/ directory. you can not edit it directly. so use following command to open
sudo gedit /etc/apache2/sites-available/000-default.conf
Or
sudo gedit /etc/apache2/sites-available/default.conf
you will get
DocumentRoot /var/www/html
OR
DocumentRoot /var/www
line. Add following code after it.
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Make user the directory tag path is same as shown in your file.
Restart your apache server using following command
sudo service apache2 restart
In my experience, /var/www/ directory directive prevents subfolder virtualhost directives. So if you had tried all suggestions and still not working and you are using virtualhosts try this ;
1 - Be sure that you have
AllowOverride All directive in
/etc/apache2/sites-available/example.com.conf
2 - Check /var/www/ Directory directives in /etc/apache2/apache2.conf (possibly at line 164), which looks like ;
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
If there is an AllowOverride None directive change it to
AllowOverride All or just escape line
By default, Apache prohibits using an .htaccess file to apply rewrite rules, so
Step 1 — Enabling mod_rewrite (if not Enabled)
First, we need to activate mod_rewrite. It's available but not enabled with a clean Apache 2 installation.
$ sudo a2enmod rewrite
This will activate the module or alert you that the module is already enabled. To put these changes into effect, restart Apache.
$ sudo systemctl restart apache2
mod_rewrite is now fully enabled. In the next step we will set up an .htaccess file that we'll use to define rewrite rules for redirects.
Step 2 — Setting Up .htaccess
Open the default Apache configuration file using nano or your favorite text editor.
$ sudo nano /etc/apache2/sites-available/000-default.conf
Inside that file, you will find a block starting on the first line. Inside of that block, add the following new block so your configuration file looks like the following. Make sure that all blocks are properly indented.
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
. . .
</VirtualHost>
Save and close the file. To put these changes into effect, restart Apache.
$ sudo systemctl restart apache2
Done. Your .htacess should work.
This link may actually help somebody https://www.digitalocean.com/community/tutorials/how-to-rewrite-urls-with-mod_rewrite-for-apache-on-ubuntu-16-04
I cleared this use. By using this site click Here , follow the steps, the same steps follows upto the ubuntu version 18.04
Go to /etc/apache2/apache2.conf
You have to edit that file (you should have root permission). Change directory text as bellow:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Now you have to restart apache.
service apache2 restart
In WampServer Open WampServer Tray icon ----> Apache ---> Apache Modules --->rewrite_module
For completeness, if "AllowOverride All" doesn't fix your problem, you could debug this problem using:
Run apachectl -S and see if you have more than one namevhost. It might be that httpd is looking for .htaccess of another DocumentRoot.
Use strace -f apachectl -X and look for where it's loading (or not loading) .htaccess from.
i have a lot of sites on my virtual machine,
and i solved it only by changing config of the site in which i needed .htaccess
what i did:
sudo a2enmod rewrite
next i changed only config for particular site, not for every site "example.com"
sudo nano /etc/apache2/sites-enable/example.com.conf
inside of it i added
<Directory /var/www/example.com>
AllowOverride All
</Directory>
service apache2 restart
so it only applies for 1 site, because when i tried to apply changes to entire server it crashed, don't know why, but this solved my problem