Category Archives: apache

Protocol concerning connections with Apache Derby with Java

I am building an application that needs to regularly access an internal Apache Derby database.

I am wondering if I should be closing the applications connection after every set of statements is complete or if I can leave the connection open.

The application will only be used and accessed by one user at any given time.

Would your answer change if I was using an external database?

Thanks.

Ubuntu 18.04 apache and Certbot

Attempting to install Certbot for LetsEncrpyt on Ubuntu 18.04 running apache and receive the following:

sudo add-apt-repository ppa:certbot/certbot Cannot add PPA: 'ppa:~certbot/ubuntu/certbot' The team named '~certbot' has no PPA named 'ubuntu/cerbot' Please choose from the following available PPAs: * 'cerbot': Certbot PPA * 'certbot-build':

A bit new to Ubuntu but am I missing something here. The PPA is there but it's not available?

Ubuntu 18.04 apache and Certbot

Attempting to install Certbot for LetsEncrpyt on Ubuntu 18.04 running apache and receive the following:

sudo add-apt-repository ppa:certbot/certbot Cannot add PPA: 'ppa:~certbot/ubuntu/certbot' The team named '~certbot' has no PPA named 'ubuntu/cerbot' Please choose from the following available PPAs: * 'cerbot': Certbot PPA * 'certbot-build':

A bit new to Ubuntu but am I missing something here. The PPA is there but it's not available?

Login-only root (no links) with a directory hidden (via apache2.conf) to keep crawlers or bots from the hidden dirs?

The hidden content is not super-sensitive but I don't want it indexed anywhere or easily found.

I'm trying to avoid .htaccess after reading somewhere? that it complicates API use.

I'm hesitant to use robots.txt considering these concerns.

In other words, if "example.com/index.html" does not expose links to the rest of the directory (and no other external links lead to them either) are "hidden" parts of the directory unable to be indexed?

Oscommerce to OpenCart Redirects

The way that Oscommerce SEO Friendly URLs work, is that they are generated from a product or category title followed by a p for product and c for category, then the product or category ID. For categories, each parent directory ID is also used. for example:

https://example.com/jeep-pinion-gears-c-284_845.html

over the course of many years, products and categories get edited and moved therefore changing the URL. However, all the old URL's still resolved because pages are served strictly based off of the last part of the URL. It looks for the c or p and the ID's. SEO is still able to be maintained. For Example:

https://example.com/jeep-pinion-gears-c-284_845.html
https://example.com/jeep-pinion-gears-and-accessories-c-284_845.html
https://example.com/jeep-pinion-gears-c-284_1234_845.html
https://example.com/ring-pinion-gears-c-845.html

Would all load the same content.

I've recently changed over to OpenCart where I used the latest URL for each product and category from the OsCommerce store. However, all the of Old Oscommerce URL's don't work.

I was originally writing some regex redirects to match the ID's but I'm running into redirect loop issues.

Does anyone any any ideas on a different approach?

Apache Cordova $.ajax not working( using Web.APİ)

im making an mobile app using API but ajax not working. i take breakpoint on ajax but not see. and my other project is work and they are exactly the same .and the jquery codes in this project are working

This inside onDeviceReady

$.ajax({

            method: "post",
            url: "http://localhost:53407/api/kullanici/kullanicikayit",
            data: yeniKullanici,
            success: function () {
                alert("Kayıt Başarılı");
                window.location.href = "index.html";
            },
            error: function () {
                alert("Lütfen bilgilerinizi kontrol ederek tekrar deneyiniz.");
            },
        });

and this is my APİ Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Cors;
using BitirmeProjesi.Server.Models;

namespace BitirmeProjesi.Server
{
    [EnableCors("*","*","*")]
    public class KullaniciController : ApiController
    {
        [HttpPost]
        public void KullaniciKayit(Kullanicilar kullanici)
        {
            Kullanicilar yeniKullanici = new Kullanicilar();
            
            yeniKullanici.KullaniciAdi = kullanici.KullaniciAdi;
            yeniKullanici.Mail = kullanici.Mail;
            yeniKullanici.RoleId = 1;
            yeniKullanici.Sifre = kullanici.Sifre;
            yeniKullanici.Soyad = kullanici.Soyad;
            yeniKullanici.Ad = kullanici.Ad;
            db.Kullanicilar.Add(yeniKullanici);
            db.SaveChanges();
        }

    }
}

`

The utlimate way to make a single entry point (front controller) working with the most common web server setups

That's not gonna be easy, thanks to all reading this! :)

;TL;DR;

How can we know what is the 'DOCUMENT_ROOT' regardless the webserver (nginx/apache/apache with hattacces) setup.

Introduction

I'll try to be as descriptive as possible :)

It's all about forwarding all the requests to a single index.php file (excluding existing files). Yes, a pretty common tasks.

Project lives in: /var/www/html/point/point1

This might be both dev or prod env.

I want all the requests to go to "index.php" with the information about what actually was requested.

Details

Assuming the the project's host is 'point1" and it lives in /var/www/html/point/point1 -

When user enters http://point1/foo/bar - I want the webserver to run /var/www/html/point/index.php and send the info about requested URL to it (in this case /foo/bar).

I want to know the 'foo' and 'bar';

It's quite with vhosts on both apache and nginx Like in apache :

<directory /var/www/html/point/point1>
      RewriteEngine On
      RewriteCond %{SCRIPT_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^.*$ index.php
</directory>  

And nginx:

location /{
    server_name point1;
    root /var/www/html/point/point1;
    try_files $uri $uri/ /index.php$is_args$args
}
location ~ \.php$ {
 #...handle php
}

It's easy because what we can easily get the "remaining part" in the

 var_dump($_SERVER['REQUEST_URI']); 

The "REQUEST_URI" var tells us what is after the 'host'.

Fine.

Now the .htaccess comes in. Assuming the user has no access to the webserver settings, here is the typical way:

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Or just RewriteRule ^(.*)$ index.php Yeah, I know there is a difference.

Problem

I want my script to handle all these situations. It's easy if we limited it to 'vhosts'. In this case the 'document root' is known. This why this works:

$request = $_SERVER['REQUEST_URI']);
$file =  $_SERVER['REQUEST_URI'][1];
$method =  $_SERVER['REQUEST_URI'][2];

We know that $file is now relative to $_SERVER['DOCUMENT_ROOT'];

Except that when I want to support .htaccess it isn't that easy. Because I don't know the "document_root".

What I get in "$_SERVER['REQUEST_URI']" is "/point/point1/foo/bar" and I don't really know what is the part responsible for "foo" and "bar";

It seems that in Symfony this part of code deals with it:

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L1826

But I'm not really sure.

What I have done so far is that I put into .htaccess this:

Hi.

Introduction

I'll try to be as descriptive as possible :)

It's all about forwarding all the requests to a single index.php file (excluding existing files). Yes, a pretty common tasks.

Project lives in: /var/www/html/point/point1

This might be both dev or prod env.

I want all the requests to go to "index.php" with the information about what actually was requested.

Details

Assuming the the project's host is 'point1" and it lives in /var/www/html/point/point1 -

When user enters http://point1/foo/bar - I want the webserver to run /var/www/html/point/index.php and send the info about requested URL to it (in this case /foo/bar).

I want to know the 'foo' and 'bar';

It's quite with vhosts on both apache and nginx Like in apache :

<directory /var/www/html/point/point1>
      RewriteEngine On
      RewriteCond %{SCRIPT_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^.*$ index.php
</directory>  

And nginx:

location /{
    server_name point1;
    root /var/www/html/point/point1;
    try_files $uri $uri/ /index.php$is_args$args
}
location ~ \.php$ {
 #...handle php
}

It's easy because what we can easily get the "remaining part" in the

 var_dump($_SERVER['REQUEST_URI']); 

The "REQUEST_URI" var tells us what is after the 'host'.

Fine.

Now the .htaccess comes in. Assuming the user has no access to the webserver settings, here is the typical way:

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Or just RewriteRule ^(.*)$ index.php Yeah, I know there is a difference.

Problem

I want my script to handle all these situations. It's easy if we limited it to 'vhosts'. In this case the 'document root' is known. This why this works:

$request = $_SERVER['REQUEST_URI']);
$file =  $_SERVER['REQUEST_URI'][1];
$method =  $_SERVER['REQUEST_URI'][2];

We know that $file is now relative to $_SERVER['DOCUMENT_ROOT'];

Except that when I want to support .htaccess it isn't that easy. Because I don't know the "document_root".

What I get in "$_SERVER['REQUEST_URI']" is "/point/point1/foo/bar" and I don't really know what is the part responsible for "foo" and "bar";

It seems that in Symfony this part of code deals with it:

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L1826

But I'm not really sure.

What I have done so far is this, in .htaccess:

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
SetEnv USE_URI_PROTOCOL PATH_INFO

As you can see I am setting an environment var so I can use it later in my php single entry point:

$uriProtocol = getenv('USE_URI_PROTOCOL')?:'REQUEST_URI';
    $request = isset($_SERVER[$uriProtocol])?$_SERVER[$uriProtocol]:'';

    //getting only what's before ? (uri query string) if it exists 
    if (($pos = strpos($request, '?')) !== false){
        $request = substr($request, 0, $pos);
    } 

    //trimming slashes
    $request = trim($request, '/');
    $requestArray  = empty($request)? [] : explode('/', $request);

    var_dump('controller',$requestArray[0] ?? 'undefined');
    var_dump('method',$requestArray[1] ?? 'undefined');

It works. But something tells me it's not very cool.

I hope I'm clear here? It's about one-single-easy-solution-to-do-the-front-controller.

Web application could not be started by the Phusion Passenger application server – Redmine installation

I've installed a redmine web application on a centOs 7, with postgresql 9.1 and using passenger. When I access the redmine application, the following error appears:

We're sorry, but something went wrong.
The issue has been logged for investigation. Please try again later.

Error ID: f4adae6a Details:

Web application could not be started by the Phusion Passenger application server.

Please read the Passenger log file (search for the Error ID) to find the details of the error.

When I access the erro_log file at /var/log/httpd/ it is like this:

[ E 2018-05-25 16:28:01.7581 24316/Td age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /opt/redmine: An operating system error occurred while preparing to spawn an application process: Cannot create FIFO file /tmp/passenger.spawn.XXXXCTqsz4/response/finish: Permission denied (errno=13)
  Error ID: f4adae6a
  Error details saved to: /tmp/passenger-error-H1zmwo.html

[ E 2018-05-25 16:28:01.7609 24316/T6 age/Cor/Con/CheckoutSession.cpp:276 ]: [Client 1-2] Cannot checkout session because a spawning error occurred. The identifier of the error is f4adae6a. Please see earlier logs for details about the error.

It seems that, first of all, apache is not logging the error at /tmp/passenger-error-H1zmwo.html as it was supposed to do.

I've already tried to loossing the permissions to the /opt/redmine using the following guide HERE

I'm on redmine 3.4.3, ruby 2.3.1 and rails 4.2.8. Passenger 5.3.1

Do'nt know what to do anymore. Appreciate a little help. Any more info please ask me.

Apache port forward to subdomain not working (tried various SO solutions)

I want to run an app on port 5000 and access it at app.mydomain.com.

I've tried the solutions I've found (basically identical), but still not working for me. How to diagnose?

https://serverfault.com/questions/195611/how-do-i-redirect-subdomains-to-a-different-port-on-the-same-server?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

https://serverfault.com/questions/857680/port-to-subdomain-in-apache/864748?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

https://askubuntu.com/questions/786564/redirect-port-5000-osrm-a-subdomain-in-apache2/786565?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

https://freedif.org/how-to-redirect-a-port-to-a-sub-domain-proxypass

[email protected]:/etc/apache2/sites-available$ cat 000-default.conf

ServerAdmin [email protected]
ServerName www.balterbox.space
DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /var/www/html>
        AllowOverride None
        Order allow,deny
        allow from all
        Options +ExecCGI
        AddHandler cgi-script .pl .php .py .p1 .p2 .sh
</Directory>

<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName flask.balterbox.space
        ServerAlias flask.balterbox.space
        ProxyRequests Off

        #ProxyPass / http://localhost:5000/
        <Location />
                ProxyPreserveHost On
                ProxyPass http://localhost:5000/
                ProxyPassReverse http://localhost:5000/
        </Location>
     # Uncomment the line below if your site uses SSL.
     #SSLProxyEngine On
</VirtualHost>
[email protected]:/etc/apache2/sites-available$ sudo apachectl restart
[email protected]:/etc/apache2/sites-available$ curl localhost:5000
Hello [email protected]:/etc/apache2/sites-available$ curl flask.localhost
Hello [email protected]:/etc/apache2/sites-available$ curl balterbox.space:5000
curl: (7) Failed to connect to balterbox.space port 5000: Connection refused
[email protected]:/etc/apache2/sites-available$ curl flask.balterbox.space
curl: (6) Could not resolve host: flask.balterbox.space

Also, if I put the virtual host in a separate file such as flask.conf and a2ensite flask and restart apache, then even curl flask.localhost fails.

EDIT

I just tried adding

138.197.205.133 balterbox.space
138.197.205.133 flask.balterbox.space

to /etc/hosts and now curl works as expected:

[email protected]:/etc/apache2/sites-available$ curl flask.balterbox.space
Hello [email protected]:/etc/apache2/sites-available$

but I still get a name server error when visiting flask.balterbox.space.

Edit 2

I did update the DNS entry on DigitalOcean

digital ocean dns entry for flask.balterbox.space