How do I set up a web.py apache2 server on an amazon linux ubuntu 13.04 server? - apache

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!

Related

Where do you find the interface for phpmyadmin when installed using homebrew

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

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.

Forbidden You don't have permission to access on this server. Centos 6 / Laravel 4

i got a problem after i finish to set up LAMP and installed my laravel 4 application. Everything seem went well, when i go on my ip address url, it show me the first page of my application correctly, but all the rest of the page throw me an 404 error The requested URL was not found on this server.
So I added to my httpd.conf (under the virtual host of my project) -
AllowOverride All
Order allow,deny
<VirtualHost *:80>
ServerName VPS-IP-ADDRESS
DocumentRoot /var/www/html/nextmatch/public_html/public/
<Directory /var/www/html/nextmatch/public_html/public/>
AllowOverride all
Order allow,deny
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
And now when i try to navigate instead the 404 error i got Forbidden
You don't have permission to access this server.
I set up with chmod 775 -R path/laravel/ and the folder storage with 777 but still i got the same error any suggest please? I cannot figure out to this problem i'm getting crazy! Thank you for any help.
The webserver starts as a daemon (service) under a particular user. That user is defined in httpd.conf. By default that user will be apache. Don't confuse the apache user with the httpd process. The latter is a webserver daemon and the former is the user under which it is going to run. If the folder you created belongs to root or a user other than the one defined in httpd.conf then apache won't be able to access it. The way to identify this problem is to go to the folder and do ls -l. If the user define in httpd.conf is apache then in order for it to access the folder, you should see:
drwxr-xr-x. 2 apache apache 4096 Jan 8 2013 public_folder
Note, it says 'apache apache', meaning it belongs to the apache user and group. If you created it via root then you will probably see:
drwxr-xr-x. 2 root root 4096 Jan 8 2013 public_folder
The apache user cannot access the folder defined by root. To solve this problem run the command:
chown -R apache:apache myfolder
The -R option is recursive, so it will update ownership for ALL folders and files within that folder to the apache user.
If your ownership if fine, then trying 'temporarily' turning off selinux. On centos you do:
setenforce 0
Which will turn off selinux till the next restart. Ideally, you will want to leave selinux on for additional security and set a valid context for your apache files and folders.
If turning off selinux does work, then you probably have the wrong security context for your files and folders. run the following command to restore your security contexts:
restorecon -R -v /var/www/
If you're using CentOS it could be an issue with selinux. Check to see if selinux is enabled with 'sestatus'. If it is enabled, you can check to see if that is the issue (temporarily) using 'sudo setenforce 0'. If apache can serve the site, then you just need to change the context of the files recursively using 'sudo chcon -R -t httpd_sys_content_t' (you can check the existing context using 'ls -Z'.
Selinux may not be the issue, but it's worth checking on.
try this inside the folder:
chcon -R -t httpd_sys_content_t *
chcon -R -t httpd_sys_content_t *
did the trick for me.
from php5.conf in /etc/apache2/mods-available
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_value engine Off
# </Directory>
#</IfModule>

.htaccess ErrorDocument 404 not showing up

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

How to boot multiple Rails apps on Apache2 with a shared Passenger gem?

I'm attempting to configure Apache V2 to handle two Rails (3.2.2) applications at the same time using VirtualHost directives. I'm doing this on a local laptop. (Ubuntu, Ruby 1.9.2, and Passenger 3.0.12.)
Used the deployment instructions in "Agile Web Development .... Rails", V4. The first simple application booted up w/o problem.
I then created a 2nd simple app with very similar characteristics. Edited /etc/apache2/apache2.conf with a second VirtualHost directive, and edited /etc/hosts to map the 2nd named URL to the same 127.0.0.1 address.
Restarting Apache blows up as shown below:
apache2: Syntax error on line 240 of /etc/apache2/apache2.conf: Cannot load /home/bubby/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.12/ext/apache2/mod_passenger.so into server: /home/bubby/.rvm/gems/ruby-1.9.2-p180/gems/passenger 3.0.12/ext/apache2/mod_passenger.so: cannot open shared object file: No such file or directory
Both apps were bundled with Passenger. "locate mod_passenger.so" returns the correct location. Is there a better way to do this?
does the file
/home/bubby/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.12/ext/apache2/mod_passenger.so
really exist and it's readable for apache?
This is how i setup multiple virtualhosts with passenger:
user#debian:# cat /etc/apache2/mods-enabled/passenger.conf
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p125/gems/passenger-3.0.11
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p125/ruby
</IfModule>
user#debian:# cat /etc/apache2/mods-enabled/passenger.load
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p125/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
user#debian:# cat /etc/apache2/sites-enabled/site1
<VirtualHost *:80>
ServerName site1
RailsEnv development
DocumentRoot /var/www/site1/public
<Directory /var/www/site1/public>
Options None
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
user#debian:# cat /etc/apache2/sites-enabled/site2
<VirtualHost *:80>
ServerName site2
RailsEnv development
DocumentRoot /var/www/site2/public
<Directory /var/www/site2/public>
Options None
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Surely.
For production, install rvm in system wide mode instead of user mode, by adding sudo to the install command. In development you can stay with user mode.
Install the passenger gem in the global gemset for your specified ruby. Do the same with gems that will be user by more than one application (remember version requirement for each gem)
after running the install apache-passenger-mod command in the server copy the resulting mod loading
Then to get the correct gemset to load add this file to your config folder
# setup_load_path.rb
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
# RVM.use_from_path! File.dirname(File.dirname(__FILE__))
# edit this line according to you ruby version
RVM.use!('1.9.2#YOUR_GEMSET')
rescue LoadError
# RVM is unavailable at this point.
raise "RVM ruby lib is currently unavailable."
end
end
# Select the correct item for which you use below.
# If you're not using bundler, remove it completely.
#
# # If we're using a Bundler 1.0 beta
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
require 'bundler/setup'
#
# # Or Bundler 0.9...
# if File.exist?(".bundle/environment.rb")
# require '.bundle/environment'
# else
# require 'rubygems'
# require 'bundler'
# Bundler.setup
# end
After that just make apache point to the correct public directory
DocumentRoot /var/www/app/public
<Directory /var/www/app/public>