Archive

Archive for the ‘apache’ Category

Apache file negotiation error: Negotiation: discovered file(s) matching request: /var/www/mysite/mypage (None could be negotiated).

December 4, 2015 1 comment

I rescued this post from my Drafts, I forgot to post it on time! Here is the original post.

Today I’ve been struggling with an annoying message in Apache’s error log:


[Wed Oct 02 19:18:36 2013] [notice] Apache/2.2.22 (Ubuntu) PHP/5.4.9-4ubuntu2.3 configured -- resuming normal operations
[Wed Oct 02 19:18:43 2013] [error] [client 127.0.0.1] Negotiation: discovered file(s) matching request: /var/www/mysite/view (None could be negotiated).
[Wed Oct 02 19:18:43 2013] [error] [client 127.0.0.1] Negotiation: discovered file(s) matching request: /var/www/mysite/404 (None could be negotiated).

I have two Ubuntu boxes, one with Ubuntu 12.04 LTS 64 bits  and another with Ubuntu 13.04 64 bits recently installed. I usually export projects from one box to another, and when I imported the project to my Ubuntu 13.04 box I got this problem. The website works fine in my 12.04 machine, so, I pressumed it’s an Apache configuration issue between my two boxes.

I want to redirect http://www.mysite.local/home to http://www.mysite.local/view.php?page=home.

My .htaccess works right on the other machine, so I’ve checked for mod_rewrite status and it’s also enabled in the 13.04 box.

This is my VirtualHost :


<Directory /var/www/myotragus.net>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 allow from all
 </Directory>

I adjusted the RewriteLogLevel to 9 but I can’t understand the final redirection from view to -> view:


127.0.0.1 - - [02/Oct/2013:19:00:54 +0200] [www.mysite.local/sid#7f10f7002670][rid#7f10f143c880/initial/redir#3] (2) [perdir /var/www/mysite/] rewrite 'view' -> 'view?page=view'

After googling a while, I tried different things, but none worked:

  • Disabling Multiviews in my VirtualHost did’nt worked
  • Disabling mod_negotiation neither worked for me.

Finally, I found this post at serverfault.com that hit the nail on the head: I have to edit the /etc/apache2/mods-available/mime.conf to add this line:

AddType application/x-httpd-php .php

As Lorenzo said in his answer, the negotiation was failing because mod_negotiation only looks for known file types.

Just restarted apache and all worked again as intended.

Please, leave your comments below.

Categories: apache, linux, php, ubuntu Tags: ,

PHPMyAdmin – Error – Cannot start session without errors

September 19, 2012 Leave a comment

When I access to PHPMyAdmin I get this error:


phpMyAdmin - Error

Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.

My Apache error log shows nothing about PHP errors.

I’ve cleaned up the cookies and not it works.

Categories: apache, MySQL, php Tags: , ,

Install Symfony 2 on Ubuntu 11.10 64 bits

July 20, 2012 2 comments

Let’s install Symfony 2.01.16 on Ubuntu 11.10 64 bits.

  • Download Symfony Standard Edition from http://symfony.com/download
  • Extract the contents to the web root (/var/www/)
  • Check the system configuration:

$ cd /var/www/Symfony

$ php app/check.php

********************************
* *
* Symfony requirements check *
* *
********************************

php.ini used by PHP: /etc/php5/cli/php.ini

** WARNING **
* The PHP CLI can use a different php.ini file
* than the one used with your web server.
* If this is the case, please ALSO launch this
* utility from your web server.
** WARNING **

** Mandatory requirements **

OK Checking that PHP version is at least 5.3.2 (5.3.6-13ubuntu3.8 installed)
[[ ERROR ]] Checking that the "date.timezone" setting is set: FAILED
 *** Set the "date.timezone" setting in php.ini (like Europe/Paris) ***
You must fix this problem before resuming the check.


$ php app/check.php
********************************
* *
* Symfony requirements check *
* *
********************************

php.ini used by PHP: /etc/php5/cli/php.ini

** WARNING **
* The PHP CLI can use a different php.ini file
* than the one used with your web server.
* If this is the case, please ALSO launch this
* utility from your web server.
** WARNING **

** Mandatory requirements **

OK Checking that PHP version is at least 5.3.2 (5.3.6-13ubuntu3.8 installed)
 OK Checking that the "date.timezone" setting is set
 OK Checking that app/cache/ directory is writable
 OK Checking that the app/logs/ directory is writable
 OK Checking that the json_encode() is available
[[ ERROR ]] Checking that the SQLite3 or PDO_<a class="zem_slink" title="SQLite" href="http://sqlite.org" rel="homepage" target="_blank">SQLite</a> extension is available: FAILED
 *** Install and enable the SQLite3 or PDO_SQLite extension. ***
You must fix this problem before resuming the check.

  • All you need is to install and enable the SQLite extension for Apache:

$ sudo apt-get install php5-sqlite

$ sudo /etc/init.d/apache2 restart

  • Recheck again, now I’m getting some warnings:

$ php app/check.php
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/sqlite.so' - /usr/lib/php5/20090626/sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0
********************************
* *
* Symfony requirements check *
* *
********************************

php.ini used by PHP: /etc/php5/cli/php.ini

** WARNING **
* The PHP CLI can use a different php.ini file
* than the one used with your web server.
* If this is the case, please ALSO launch this
* utility from your web server.
** WARNING **

** Mandatory requirements **

OK Checking that PHP version is at least 5.3.2 (5.3.6-13ubuntu3.8 installed)
 OK Checking that the "date.timezone" setting is set
 OK Checking that app/cache/ directory is writable
 OK Checking that the app/logs/ directory is writable
 OK Checking that the json_encode() is available
 OK Checking that the SQLite3 or PDO_SQLite extension is available
 OK Checking that the session_start() is available
 OK Checking that the ctype_alpha() is available
 OK Checking that the token_get_all() is available
 OK Checking that the APC version is at least 3.0.17

** Optional checks **

OK Checking that the PHP-XML module is installed
 OK Checking that the token_get_all() function is available
 OK Checking that the mb_strlen() function is available
 OK Checking that the iconv() function is available
 OK Checking that the utf8_decode() is available
 OK Checking that the posix_isatty() is available
[[WARNING]] Checking that the intl extension is available: FAILED
 *** Install and enable the intl extension (used for validators) ***
[[WARNING]] Checking that a PHP accelerator is installed: FAILED
 *** Install a PHP accelerator like APC (highly recommended) ***
[[WARNING]] Checking that php.ini has short_open_tag set to off: FAILED
 *** Set short_open_tag to off in php.ini ***
 OK Checking that php.ini has magic_quotes_gpc set to off
 OK Checking that php.ini has register_globals set to off
 OK Checking that php.ini has session.auto_start set to off

** Optional checks (Doctrine) **

OK Checking that PDO is installed
 OK Checking that PDO has some drivers installed: mysql, sqlite

Let’s see the warnings one by one:

  • [PHP Warning] – Unable to load dynamic library ‘/usr/lib/php5/20090626/sqlite.so’: sqlite.so library relates to SQLite 2, which support was dropped via bug https://bugs.launchpad.net/ubuntu/+source/sqlite/+bug/747325. First ensure you have sqlite3.so in /usr/lib/php5/20090626 folder and then remove (or move) the sqlite.ini in /etc/php5/conf.d (ensure that you have also sqlite3.ini in the same folder):

$ cd /usr/lib/php5/20090626

$ ll sqlite*

-rw-r--r-- 1 root root 48480 2012-06-13 20:18 sqlite3.so

$ cd /etc/php5/conf.d

$ sudo mv sqlite.ini sqlite.ini_rm_20120720

  • [WARNING] Checking that the intl extension is available: install intl extension for php:

$ sudo apt-get install php5-intl

  • [WARNING] Checking that a PHP accelerator is installed: FAILED: Install a PHP Accelerator (you need pecl, so if you don’t have it installed, install php-pear package):

$ sudo pecl install APC

If you get this error:


/usr/include/php5/ext/pcre/php_pcre.h:29:18: fatal error: pcre.h: No such file or directory
compilation terminated.
make: *** [apc.lo] Error 1
ERROR: `make' failed

Install this package and reinstall APC [updated 2012/08/17: install this package if you don’t find libpcre: libpcre3-dev]:


$ sudo apt-get install libpcre

$ sudo pecl install APC

Once installed, you have to add this line to /etc/php5/cli/php.ini (at the end of the file):


extension=apc.so

  • [WARNING] Checking that php.ini has short_open_tag set to off: just edit /etc/php5/cli/php.ini and modify this line:

short_open_tag = Off

  • Now let’s see this warning: The PHP CLI can use a different php.ini file than the one used with your web server. If this is the case, please ALSO launch this utility from your web server. So, open your broser and launch the check:

http://localhost/Symfony/web/config.php [recommended]

or

http://localhost/Symfony/app/check

  • I’ve had to modify the /etc/php5/apache2/php.ini file to add the correct timezone, add the extension=apc.so at the end of the file and modify open_short_tag to Off. Restart apache and recheck until you see no errors.

Once everything it’s fine, click on “Bypass configuration and go to the Welcome page”.

Categories: apache, linux, php, symfony, ubuntu Tags: , ,

How to trace .htaccess’ RewriteRule

Recently I’ve have had to debug the RewriteRules of my .htaccess (using Apache 2.2.20 version).

For me, the easisest way I’ve found to debug the RewriteRule is to edit /etc/apache2/sites-available/default and add this lines:


RewriteLog "/var/log/apache2/rewrite.log"
 RewriteLogLevel 2

This lines can also be added to apache2.conf.

Now I can adjust RewriteLogLevel from 0 (no log) to 9 (logs almost everything). Don’t forget to read the Apache 2.2 documentation, as this may affect the server’s performance. To disable the rewrite log, adjust RewriteLogLevel to 0 instead of redirecting the RewriteLog to /dev/null, as the log is still created.

In my case, setting the RewriteLogLevel to 2 is enough to debug the rewrite rules, with this command:


tail -f /var/log/apache2/rewrite.log | grep rewrite

Plus sign in URL get parameter is received as a space

I’ve an URL like this:

http://www.example.com/example.php?page=one+two

My PHP script reads the page with $_GET([‘page’]), and the result is this, the plus sign is converted to an space:

one two

My server uses Apache/2.2.3 (CentOS) & PHP Version 5.2.14.
There’s an easy workaround using the [B] flag (escape backreferences) for mod_rewrite, as stated in the apache documentation:
http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_b
If I put the B flag to my RewriteRule I get this error:

RewriteRule: unknown flag 'B'

Because the B flag is available from apache version 2.2.7 onwards, so it’s the turn to update the apache server version!

Categories: apache, php Tags: , ,

Apache error log: Invalid command ‘RewriteEngine’

March 20, 2012 5 comments

After adding the “RewriteEngine on”  on an .htaccess file, I got the following error in apache’s error.log:


.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

To fix it, I’ve added the rewrite module to apache:


$ sudo a2enmod rewrite

$ sudo /etc/init.d/apache2 restart

 

Categories: apache Tags: , ,

Install MySQL on Ubuntu

September 5, 2011 Leave a comment
  1. Install the requiered packages
$ sudo apt-get install mysql-server mysql-client mysql-query-browser

To connect to MySQL via command line:

$ mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 42
Server version: 5.1.54-1ubuntu4 (Ubuntu)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

As an alternative to MySQL Query Browser, you can install PHPMyAdmin, that is widely used in ISP web hostings:

$ sudo apt-get install phpmyadmin

During the installation, you can automatically configure it to run with Apache, if you have already installed (https://myotragusbalearicus.wordpress.com/2011/08/31/install-apache-on-ubuntu/).