snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
10.95k stars 3.16k forks source link

Issue creating snipeit database when using installer script #227

Closed tomlee129 closed 10 years ago

tomlee129 commented 10 years ago

System information Ubuntu 14.04.1 LTS Server - With all the pre-requisites for snipeit installed except vagrant User level: Noob

Hi,

Tried running through the installation guide and everything runs okay until i get to the following command:

sudo ansible-playbook -i hosts -c local snipeit.yml

It works fine all the way down to Create snipeit database and then the following issue happens

TASK: [snipeit | Create snipeit database] ***** failed: [127.0.0.1] => {"failed": true] msg: unable to connect, check login_user and login_password are correct, or alternatively check ~/.my.cnf contains credentials

FATAL: all hosts have already failed -- aborting

I have checked and made sure that my.cnf has the following credentials. [client] user = same as mysql user password = same as mysql password host = localhost

If i try to use the install script it gives me this error instead.

PLAY [snipeit] ****

GATHERING FACTS *** fatal: [127.0.0.1] => Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in "/tmp". Failed command was: mkdir -p $HOME/.ansible/tmp/ansible-tmp-1408452013.49-43420459319073 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1408452013.49-43420459319073 && echo $HOME/.ansible/tmp/ansible-tmp-1408452013.49-43420459319073, exited with result 1

TASK: [snipeit | Install Requirements] **** FATAL: no hosts matched or all hosts have already failed -- aborting

PLAY RECAP **** 127.0.0.1 : ok=0 changed=0 unreachable=1 failed=0

Tried running the script under sudo so there is no reason that i understand at least why the script is failing.

Can somebody help with my installation problem?

Really really appretiated!

technogenus commented 10 years ago

which installation guide did you 'run through'?

snipe commented 10 years ago

@technogenus - I believe @tomlee129 is referring to the vagrant/ansible install scripts set up by @GR360RY https://github.com/GR360RY/snipeit-ansible, which are mentioned in the readme.

tomlee129 commented 10 years ago

i ran through technogenus guide. Running through the regular guide now (the one hosted on the github documents)

snipe commented 10 years ago

This actually sounds like an issue with the ansible/vagrant config.

msg: unable to connect, check login_user and login_password are correct, or alternatively check ~/.my.cnf contains credentials

Can you connect via command line to the mysql instance using the credentials you put in the config file?

tomlee129 commented 10 years ago

Well i followed the instructions on the github document and it seems to have installed. Just one remaining problem, how do i start and dial into the service? should be running on 192.168.0.19 but all i get is the apache page. Sorry for the dumb question but it doesn't explain on the instructions how to do it.

technogenus commented 10 years ago

Did you (or the installation script) create an apache configuration file? If the Apache welcome page is showing, then it means there were no apache site/directory configurations active and it fell through to the last 'default' apache welcome page.

Unfortunately Debian has the most convoluted and broken-up mish mach for Apache configuration (no one is quite sure why). Basically you will need to create a file in /etc/apache2/sites-enabled/ directory. The file is normally named the full hostname of your site (e.g. server1.localdomain.com) Then run the command a2ensite server1.localdomain.com.

A boiler plate example of the Apache config file for Snipe IT is shown below. You will need to edit your actual Snipe "PUBLIC" directory path and server/host name. More detailed information on the Debian/Apache setup mess is here: http://www.control-escape.com/web/configuring-apache2-debian.html

Apache2 Snipe IT configuration file example:

#*****************************************************************
# SNIPE-IT APACHE SITE CONFIG

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>

# This directory parameter is needed for mod_rewrite to work properly!
<Directory /var/www/snipeit/public>
    AllowOverride All
</Directory>

# Your application-public root folder
DocumentRoot /var/www/snipeit/public

ServerName yourserver.domain.com
ServerAlias yourserver
ServerAlias localhost
#if using a simply/common server short name as well...
ServerAlias commonname
ServerAlias commonname.domain.com

# Other directives here

</VirtualHost>

#*****************************************************************
tomlee129 commented 10 years ago

Right, i have the following config file:
GNU nano 2.2.6 File: server1.localdomain.com

AllowOverride All

Your application-public root folder

DocumentRoot /var/www/snipeit/public

ServerName dev.trackrecordglobal.com ServerAlias dev ServerAlias localhost

if using a simply/common server short name as well...

ServerAlias commonname ServerAlias commonname.domain.com

Other directives here

*****

and i have made sure that the file is called server1.localdomain.com for now. Everything is enabled in /etc/apache2/sites-enabled and /etc/apache2/sites-available as shown below:

tom@WincombeServer2:/etc/apache2/sites-available$ ls -l /etc/apache2/sites-available/ total 16 -rw-r--r-- 1 root root 1332 Jan 7 2014 000-default.conf -rw-r--r-- 1 root root 6437 Jan 7 2014 default-ssl.conf -rw-r--r-- 1 root root 711 Aug 20 10:30 server1.localdomain.com

so what's next?

technogenus commented 10 years ago

is the directory '/var/www/snipeit/public' the actual location of your Snipe IT web application files? Does your server respond to the DNS name dev.trackrecordglobal.com, or dev - i.e. can you "ping" either of these host names and get reply from the debian server?

If both the above are true, then just open a browser and navigate to http://dev or http://dev.trackrecordglobal.com or http://ipaddress

technogenus commented 10 years ago

did you run the a2ensite command in Debian? this should copy some symbolic link files to other apache config folders...

tomlee129 commented 10 years ago

Only one word to describe it, DOH!

Changed the directory to /home/tom/snipeit

and running the command a2ensite brings up the following issue:

tom@WincombeServer2:/etc/apache2/sites-available$ a2ensite server1.localdomain.com ERROR: Site server1.localdomain.com does not exist!

technogenus commented 10 years ago

Sorry... there was a recent change in Debian Apache2 to start 'somewhat' conforming to the Linux standards...

you will need to change the apache configuration file you made to "something.conf" naming convention - try changing the file name of /etc/apache2/sites-available/server1.localdomain.com to snipeit.conf then run "a2ensite snipeit" or "a2ensite snipeit.conf"

tomlee129 commented 10 years ago

Cool. In doing that i have 403'd Forbidden my server so i'm going to have to sort that out. Must be some configuration file i must of missed somewhere.

technogenus commented 10 years ago

you might just need to change the permissions of your app folder to give the apache user group proper access...

try running these commands :

chgrp -R apache /home/tom/snipeit
chmod -R 754 /home/tom/snipeit
chmod -R 774 /home/tom/snipeit/app/storage/
technogenus commented 10 years ago

sorry - Debian uses a different user/group account for Apache2...

chgrp -R www-data /home/tom/snipeit
chmod -R 754 /home/tom/snipeit
chmod -R 774 /home/tom/snipeit/app/storage/
tomlee129 commented 10 years ago

Well that did something. Still hasn't fixed the issue but no doubt were heading in the right direction.

Thanks again for your help, i'm going to keep working on it at my end

technogenus commented 10 years ago

You might want to consider using CentOS instead of Debian...
a LOT easier and more support. Snipe IT works perfectly on CentOS 6.4, 6.5 and 7.0

tomlee129 commented 10 years ago

Depends what my boss allows. As you may have guessed i'm a very junior programmer set to get this up and going. I'll speak to him and see what i can do

tomlee129 commented 10 years ago

Gotten somewhere. Sifting through the apache logs it couldn't access the document directory. So now that's remedied i just have access to the Index of/ and all the files. No snipeit service.

I take it that means i have gone very very wrong

technogenus commented 10 years ago

Double "DOH!"...

"Only one word to describe it, DOH!
Changed the directory to /home/tom/snipeit"

your root directory for apache has to be the "public" folder... change the snipeit.conf file you made in Apache to "/home/tom/snipeit/public"

tomlee129 commented 10 years ago

Just to make sure it's right, here's the snipeit.conf file

*****

SNIPE-IT APACHE SITE CONFIG

Listen for virtual host requests on all IP addresses

NameVirtualHost *:80

<VirtualHost *:80>

This directory parameter is needed for mod_rewrite to work properly!

<Directory /home/tom/snipeit/public> AllowOverride All Allow from all Require all granted

Your application-public root folder

DocumentRoot /home/tom/snipeit

ServerName dev.trackrecordglobal.com ServerAlias dev ServerAlias localhost

if using a simply/common server short name as well...

ServerAlias commonname ServerAlias commonname.domain.com

Other directives here

*****

If i change the document root to /home/tom/snipeit/public then i get the 403 forbidden error again

technogenus commented 10 years ago

it basically looks correct... but because you have put the folder of you snipe web app in your logon "tom" home folder (home/tom/snipeit)... there is probably going to be lots of (unwelcome) permissions changes required...

the correct place to put your snipeit web application directory would be at /var/www/snipeit since this folder already has all the correct permissions for Apache user.

Remember to run:

chgrp -R www-data /var/www/snipeit
chmod -R 754 /var/www/snipeit
chmod -R 774 /var/www/snipeit/app/storage/

As per Apache docs:

For the new doc root to be accessible by Apache, the Apache users must be able to access all directories in the path leading up to /home/../www. So even though /home/../www is accessible to everyone, /home/.. and /home must also be executable by the Apache user. 
tomlee129 commented 10 years ago

Done that and changed the snipeit.conf and apache2.conf files to match the new location. Ran your permissions as well and now have the following issue on the apache error log

[Wed Aug 20 12:53:06.279501 2014] [core:error] pid 32242Permission denied: [client 192.168.0.3:53270] AH00035: access to /index.htm denied (filesystem path '/var/www/snipeit/index.htm') because search permissions are missing on a component of the path

So i presume that's a permission thing i need to sort out. Hopefully i can work this one out

technogenus commented 10 years ago

do you have PHP 5.4+ installed?

Part of PHP install should have been some PHP modules for Apache and also added .php as a default document in the Apache php.conf file it drops into the Apache config files. Apache shouldnt even be trying to server a htm file from here... the start file in the application is index.php

tomlee129 commented 10 years ago

Should be installed. I followed the installation guide from here: https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu

So presumably that would have installed the latest version of php on my system. Running php --version shows i have php 5.5.9-1ubuntu installed.

technogenus commented 10 years ago

did you follow exactly all of step THREE to config PHP in Apache, create a PHP test file and ensure you can access/see it?

tomlee129 commented 10 years ago

Yep. Created a test file in php using the phpinfo() function and could see it.

What i just reolised much to my dismay is that the permisions wernt setting. I hadn't noticed. so sudo'd that and that ran through fine. Now its still saying search permisions are missing on a component or path but this time its for index.php.

[Wed Aug 20 13:10:06.153618 2014] [core:error] pid 32354Permission denied: [client 192.168.0.3:53941] AH00035: access to /info.php denied (filesystem path '/var/www') because search permissions are missing on a component of the path

technogenus commented 10 years ago

If this is not a production server, and not directly accessible from the Internet... try this...

chgrp -R www-data /var/www/snipeit
chmod -R 775 /var/www/
technogenus commented 10 years ago

Sorry... this: (make sure to run as root)

chgrp -R www-data /var/www/
chmod -R 775 /var/www/
tomlee129 commented 10 years ago

WHEY! i have a page. It's another index page but i can click on server.php and get a 500 server error. But i have a page! examplepage

technogenus commented 10 years ago

Your document root is still wrong. The document root "/" should be starting in the "public/" folder. Check your snipeit.conf file again and make sure to restart Apache so it can re-read the conf files...

$ sudo /etc/init.d/apache2 restart
tomlee129 commented 10 years ago

Done, and that has removed the document directory and created the home page. Still server error 500 (internal server error) but were getting there. Going to crawl aroud the other issue pages and see if there is a solution already for this

tomlee129 commented 10 years ago

Here is the error.log line

[Wed Aug 20 13:29:53.097795 2014] [:error] [pid 32479] [client 192.168.0.3:54149] PHP Fatal error: Class 'Illuminate\Foundation\Application' not found in /var/www/snipeit/bootstrap/start.php on line 14, referer: http://192.168.0.19/bootstrap/

technogenus commented 10 years ago

did you follow the instructions to run all these setup/install commands from your /var/www/snipeit directory (after using 'git' to pull the source code)?

there should be no errors - and it should prompt you for a user first, last, email, password to enter... (run as sudo)

curl -sS https://getcomposer.org/installer | php
php composer.phar install
php composer.phar update
php artisan app:install
tomlee129 commented 10 years ago

All works fine until i get to the last one. Then i get a database [] not configured. Which is odd as i created the database yesterday, snipeit_laravel.

technogenus commented 10 years ago

did you create a mysql user, set a password for the user, and give the user access to the database, then edit the /var/www/snipeit/config/production/database.php (you have to make a copy of the example file) with the user and password information?

tomlee129 commented 10 years ago

Yep. Did all that. Just checked the database.php file to make sure. Here's the output

'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'snipeit_laravel', 'username' => 'root', 'password' => 'redacted', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ),

Obviously there is a password, i just changed the password posted to something different.

technogenus commented 10 years ago

can you connect to and access the database from the command line using this username and password... and your REALLY should not use root for the db access

mysql -u root -p
mysql> use snipeit_laravel;
tomlee129 commented 10 years ago

Done that, still with no joy. snipeit_laravel is set as default in my.cnf as-well. And i checked the database is populated with all the tables already: asset_logs asset_uploads assets categories depreciations etc etc

so it's definately set as default.

snipe commented 10 years ago

Try moving the database.php file into app/config

tomlee129 commented 10 years ago

And its all working now. Thanks ever so much you two. I owe you a beer at some point when your in the UK. Make that several beers!

snipe commented 10 years ago

Glad you got it sorted, @tomlee129!