Sunday, May 29, 2016

Installing Cachet on CentOS 7

For a recent pet project, I wanted to create a website for my company which would allow us to visualize what websites and services we host which were up or down. I did some research, and found a few options. I love OSS, so I found myself looking at what I thought was the best option, CachetHQ.

Fancy... and it doesn't cost $400 per month! (cough, cough statuspage.io)

As you probably know, OSS sometimes can be a little tricky to install. The documentation was spartan, and 3rd party tutorials seemed to leave out some essential steps. So, for the first entry of the sysadmin collective, I'm going to show you how to install Cachet on a Centos 7 server. You'll want a vanilla, fresh install of the OS. Once you've got that up and ready for good times, let's get started. :-)

Update server
Start the whole process off with updates.
 yum update -y  
Install needed packages
We'll get started by installing the needed repositories, packages, enabling our database and server to start automatically with the following.
 rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm  
 sudo rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm  
 sudo rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi  
 sudo yum --enablerepo=remi-php56 install php php-mysql php-mbstring php-gd php56w-cli php56w-process php56w-mcrypt php56w-mbstring php56w-common php56w-fpm php56w-xml php56w-opcache php56w-pecl-apcu php56w-pdo php56w-mysqlnd httpd mariadb-server mariadb git curl  
 sudo systemctl enable httpd.service; sudo systemctl start httpd.service  
 sudo systemctl enable mariadb.service; sudo systemctl start mariadb.service  
Follow the MySql secure installation procedure
This is just a typical setup. Just follow the prompts, say yes to everything and set the root password here.
 sudo mysql_secure_installation  
Setup our MySQL database for CachetHQ
Now we need to set up the database. We'll first log in as the MySQL root user, then create the cachet database, then grant all to a user we're creating to allow the application to access the database.
 mysql -u root -p  
   
 CREATE DATABASE cachet;  
 GRANT ALL PRIVILEGES ON cachet.* TO 'cachetuser'@'localhost' IDENTIFIED BY 'secretPASSWORD';  
 FLUSH PRIVILEGES;  
 \q  
Install Composer
With the databases out of the way, we'll need Composer, it's a prereq for Cachet which will help us install some PHP plugins.
 curl -sS https://getcomposer.org/installer | php  
 sudo mv composer.phar /usr/local/bin/composer  
Download CacheHQ
Time to download the application! We're going to change over to /var/www, and clone the CachetHQ repo.
 cd /var/www/  
 git clone https://github.com/cachethq/Cachet.git  
 cd Cachet/   
Copy the configuration example
 cp .env.example .env  
Install the PHP plugins with composer.
 php /usr/local/bin/composer install --no-dev -o  
EDIT the .env file
Unless you're using an external database (which you're not if you've been following this tutorial so far) you'll just want to edit these three lines in the .env file with your favorite text editor. Make sure they match the values we set when we created the database, user, and password with MySQL.
 DB_DATABASE=cachet  
 DB_USERNAME=cachetuser  
 DB_PASSWORD=secretPASSWORD  
Use php artisan to apply env file settings.
If you're prompted here, just say yes to any prompts.
 php artisan key:generate  
 php artisan migrate  
 php artisan db:seed  
 php artisan app:install   
Modify some permissions in the Cachet directory
We'll want to make sure apache owns Cachet, and that we have 777 set on storage so we can install Cachet on the first run.
 chmod -R 777 storage  
 chown -R apache:apache /var/www/Cachet/  
Create a virtual hosts entry
With your favorite text editor, create the following file:
 /etc/httpd/conf.d/cachet.conf   
Now populate the file with the following information:
 <VirtualHost *:80>  
   ServerName server  
   ServerAlias server  
   DocumentRoot "/var/www/Cachet/public"  
   <Directory "/var/www/Cachet/public">  
     Require all granted  
     Options Indexes FollowSymLinks  
     AllowOverride All  
     Order allow,deny  
     Allow from all  
   </Directory>  
 </VirtualHost>  
Edit your hosts file.
In your /etc/hosts file ensure that you have an entry with your ip address and hostname of the server at the top. It should look like something like this.
 8.8.8.8 server.com  
Restart httpd
Now we just need to restart the apache web service to finish up the install.
 systemctl restart httpd  
Whew, now that's done we can run the Cachet installer. Navigate with a browser to the IP or FQDN of the cachet server. If all goes well, we should see this:

Success! Let's select file for both of the options and press next.

Enter your site name, domain, location, timezone and language. 

Setup your first admin user.

Wow, and now we're done!


Now we can set this thing up! If you have any questions about this or run into any problems at all, just let me know and I'll try to help you out. :-)
-B




3 comments:

  1. "I very much enjoyed this article.Nice article thanks for given this information. i hope it useful to many pepole.php jobs in hyderabad.
    "

    ReplyDelete
  2. Replies
    1. i had to reinstall the vps 20 times and i just giving up bc i have no clue if this even works

      Delete