- Joined
- Dec 1, 2018
- Messages
- 3,119
After having some trouble with Kintura over the past few months, I decided to start looking for another tracker which I could use alongside it and possibly switch completely if it performs well and the mood takes me. I looked at a few other cloud options but in the end decided I'd give CPVLab another go, I used to use this quite a bit back in the day as it was self-hosted and I preferred the flexibility (not to mention cost) of it over cloud-based trackers.
This led me to thinking why not post a guide on building a VPS and deploying CPVLab on to it, I could share some of my scripts and hopefully help save everyone a bunch of time deploying a new server, so here you are
I will be using Vultr as my VPS provider, but you can use DigitalOcean or any other provider, they're all much of a muchness, if you want to follow along you will need the following:
If there is enough interest, I may do another guide on building a VPS using Ubuntu, but we'll see what kind of interest there is for that later.
I will try to make it easy to follow but you can just upload the scripts and run them rather than creating files, copy and pasting etc. but it’s always good to get a feel for what you are doing and not just running scripts as if something goes wrong you won’t have a clue.
IMPORTANT – if you want to run the scripts be sure to follow through Step 2 FIRST, otherwise they will not work properly, and things will not be all sunshine and roses but and
Right let's get building this bad boy then
As mentioned, I will be using CentOS v8 (NOT CentOS Stream, it’s a dev platform!)
Select the $5 option
You don't need to worry about additional features or SSH keys just make sure you remember to enter a server hostname and label, i like to use the domain i'm using and a short prefix, so something like srv.yourdomain.com.
Then click deploy to let the magic begin, once it has been deployed you will need to setup the DNS for the domain before we can continue. Once its starts deploying click on the server name and then copy the IP, we’ll need to add that to the DNS entry.
Now you need to click on products again on the left, then DNS and the the circle with the + and select Add domain, then you enter the domain name and paste the IP of the server you just created.
Now I would suggest you take a little break here while the internet does its thang and updates to DNS happen, so go grab a coffee or beer and chillax for a bit before continuing.
You can test this by either doing an nslookup or ping from your computer or using an online tool like https://www.nslookup.io/
Once the domain is pointed at the IP we can continue with the build.
Next, we need to make sure the hostname if set correctly as we will us that later on in the script, so run the following command to set the hostname. I set the hostname to be the name I used in the deploy stage, so if you have called your server go.domain.com then command would be
You can check the hostname by running the hostname command to make sure you have set it correctly, remember this needs to be right BEFORE running the script as it will fail otherwise!
Now since Letsencrypt has moved to snapd I have had a some issues with SELinux so I tend to disable it for now, I will suss this at some point but for now let's disable it so we can finish our server without any issues.
After disabling SELinux you will need to reboot the server
One the server has rebooted double check that SELinux is disabled by running this command
That’s the pre-config sorted for the VPS now can create the setup script and finish off the initial build, I prefer Nginx over Apache as it has a smaller memory footprint and when dealing with small VPS's this is a big thing. Also, I feel its faster, especially if you're serving static content.
We will be needing the epel repo, in addition I like to use nginx and mariadb repos for the latest versions, but I have created a block of commands that you can copy and paste into a script to run that will configure and install all that is needed. I have used this many times and update it as and when required so the script it solid and will give you a working server in just a few clicks.
If you are NOT following along and plan on just running the scripts make sure you have completed Step 2 and skip to Step 4
Firstly, create a new file and open it for editing
You need to then hit the i key to enable insert mode, you will know if its enabled as it will say -- INSERT -- at the bottom
Once that is enabled copy the code below and click the right mouse button to paste it into the file then hit ESC and :wq enter to save the file, that’s our setup script created.
Code to copy for script, remember you need to follow the steps above to change the hostname and disable SELinux or it will fail.
To run it enter the following command
Once the script has completed you will have a VPS all setup with PHP, MariaDB, nginx and SSL installed ready to go, if you browse to your domain you should see the PHP info page displayed.
Skip to database creation if you are running the scripts.
Create another file like we did previously
Enter insert mode and past the code below into the new file
You can check its installed correctly by looking at the Zend engine section of the PHP Info page.
Before install
After the install
I already have an account so will go with that, login to https://users.cpvlab.pro/index.php then click the Install CPVLab Pro button to download the install package.
Once you have downloaded this you need to extract the files and upload them to the server using your favorite SFTP software, I use WinSCP on my PC and CyberDuck on my MacBook.
NOTE: Before uploading the files make sure you delete the index.php file we created earlier to test the server!
Now the files are uploaded head over to the install wizard page
https://yourdomain.com/install-wizard.php
It should look like this
Now enter the email address you setup your CPVLab account with and click the download install package button.
This will download the CPVLab setup files to your computer, you will need to extract and upload these like you did before for the install wizard.
After the files are uploaded you need to check the permissions and adjust them accordingly, so click the check permission button in Step 3, this will tell you what permissions you will need to set.
I have attached a script which will do this for you just double check to ensure that it captures all the files/folders mentioned and run it from the CPVLab install folder.
After running the perms script (or setting via your SFTP software) click the check permissions button again, this time it should be all green
We have already created a database perviously so you can skip Step 4 and go straight to Step 5 and enter the details from the database creation, your email should already be filled in but if not enter that then click Finish the Install.
It will only take a minute or so then you will be redirected to the login page, however, it will have a warning that you need to delete some files and set permissions again but I have attached a script that will do that for you as well, I’m nice like that. As before upload the file to the CPVLab install folder and run, the script will remove the perms script and itself once complete.
Now you have a fully installed and working copy of CPVLab, login using admin as username and admin as the password, make sure you change these immediatley!
Once logged in go to Settings -> General Settings to change the default admin password
That’s it, we have setup and installed CPVLab ready to accept some traffic and help us bank.
Hope you found this guide useful, please do let me know how you get on with it or if you find any mistakes etc.
If you have any questions, please post and I’ll try to answer the best I can.
This led me to thinking why not post a guide on building a VPS and deploying CPVLab on to it, I could share some of my scripts and hopefully help save everyone a bunch of time deploying a new server, so here you are
I will be using Vultr as my VPS provider, but you can use DigitalOcean or any other provider, they're all much of a muchness, if you want to follow along you will need the following:
- Domain name (anything TLD will do)
- A Vultr account (if you don't have one you can use my referral link and get $100 FREE - https://www.vultr.com/?ref=8400333-6G)
- Putty (or your favorite SSH program)
- WinSCP/Cyberduck or ftp program to upload files
- A little time and patience
If there is enough interest, I may do another guide on building a VPS using Ubuntu, but we'll see what kind of interest there is for that later.
I will try to make it easy to follow but you can just upload the scripts and run them rather than creating files, copy and pasting etc. but it’s always good to get a feel for what you are doing and not just running scripts as if something goes wrong you won’t have a clue.
IMPORTANT – if you want to run the scripts be sure to follow through Step 2 FIRST, otherwise they will not work properly, and things will not be all sunshine and roses but and
Right let's get building this bad boy then
Step 1 - Deploying a VPS
Login to your vultr account and click products then on the right hover over the blue circle with a + and select deploy new server, I will choose NYC for this you can choose whichever location suits you best. Initially i always deploy with a $5 VPS, you may find you need to bump this up later but generally I find it to be sufficient for most projects.As mentioned, I will be using CentOS v8 (NOT CentOS Stream, it’s a dev platform!)
Select the $5 option
You don't need to worry about additional features or SSH keys just make sure you remember to enter a server hostname and label, i like to use the domain i'm using and a short prefix, so something like srv.yourdomain.com.
Then click deploy to let the magic begin, once it has been deployed you will need to setup the DNS for the domain before we can continue. Once its starts deploying click on the server name and then copy the IP, we’ll need to add that to the DNS entry.
Now you need to click on products again on the left, then DNS and the the circle with the + and select Add domain, then you enter the domain name and paste the IP of the server you just created.
Now I would suggest you take a little break here while the internet does its thang and updates to DNS happen, so go grab a coffee or beer and chillax for a bit before continuing.
You can test this by either doing an nslookup or ping from your computer or using an online tool like https://www.nslookup.io/
Once the domain is pointed at the IP we can continue with the build.
Step 2 - Important config and Updates
Now we have a shiny new VPS we have a couple of configuration things we need to do before we can get to the main script, firstly we need to make sure the server is up to date with all the latest patches and kernel's.
Bash:
dnf -y update
Next, we need to make sure the hostname if set correctly as we will us that later on in the script, so run the following command to set the hostname. I set the hostname to be the name I used in the deploy stage, so if you have called your server go.domain.com then command would be
Bash:
hostnamectl set-hostname go.domain.com
You can check the hostname by running the hostname command to make sure you have set it correctly, remember this needs to be right BEFORE running the script as it will fail otherwise!
Bash:
hostname
Now since Letsencrypt has moved to snapd I have had a some issues with SELinux so I tend to disable it for now, I will suss this at some point but for now let's disable it so we can finish our server without any issues.
Bash:
sed -i -e 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
After disabling SELinux you will need to reboot the server
Bash:
reboot
One the server has rebooted double check that SELinux is disabled by running this command
Bash:
sestatus
That’s the pre-config sorted for the VPS now can create the setup script and finish off the initial build, I prefer Nginx over Apache as it has a smaller memory footprint and when dealing with small VPS's this is a big thing. Also, I feel its faster, especially if you're serving static content.
Step 3 – Installing PHP, MariaDB, nginx and SSL
You can follow along here copying and pasting the commands to get a feel for what you’re doing or you can just upload the scripts I have shared, however you really need to pay attention to what you are doing and not just blindly run these scripts!We will be needing the epel repo, in addition I like to use nginx and mariadb repos for the latest versions, but I have created a block of commands that you can copy and paste into a script to run that will configure and install all that is needed. I have used this many times and update it as and when required so the script it solid and will give you a working server in just a few clicks.
If you are NOT following along and plan on just running the scripts make sure you have completed Step 2 and skip to Step 4
Firstly, create a new file and open it for editing
Bash:
vi setup.sh
You need to then hit the i key to enable insert mode, you will know if its enabled as it will say -- INSERT -- at the bottom
Once that is enabled copy the code below and click the right mouse button to paste it into the file then hit ESC and :wq enter to save the file, that’s our setup script created.
Code to copy for script, remember you need to follow the steps above to change the hostname and disable SELinux or it will fail.
Bash:
dnf -y install epel-release
cat <<EOF > /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx repo
baseurl=https://nginx.org/packages/mainline/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
rpm --import https://nginx.org/keys/nginx_signing.key
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf -y module enable php:remi-7.4
dnf -y install nginx mariadb-server php php-cli php-common php-zip php-mysqlnd php-intl
mkdir -p /var/www/html/$HOSTNAME/public_html
cat <<EOF > /var/www/html/$HOSTNAME/public_html/index.php
<?php echo phpinfo(); ?>
EOF
cat <<EOF > /etc/nginx/conf.d/$HOSTNAME.conf
server {
listen 80;
server_name $HOSTNAME;
root /var/www/html/$HOSTNAME/public_html;
index index.php;
location / { try_files \$uri \$uri/ =404; }
location ~ \.php\$ {
fastcgi_split_path_info ^(.+\.php)(/.+)\$;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
# caching settings
include globals/caching.conf;
}
EOF
mkdir -p /etc/nginx/globals
cat <<EOF > /etc/nginx/globals/caching.conf
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)\$ {
access_log off; log_not_found off; expires max;
}
# enable caching
location ~* \.(txt|xml|js)\$ {
expires 8d;
}
location ~* \.(css)\$ {
expires 8d;
}
location ~* \.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)\$ {
expires 8d;
}
location ~* \.(jpg|jpeg|png|gif|swf|webp|svg)\$ {
expires 8d;
}
EOF
cat <<EOF > /etc/nginx/globals/gzip.conf
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
server_tokens off;
EOF
systemctl enable --now mariadb
systemctl enable --now nginx
systemctl enable --now php-fpm
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
dnf -y install snapd
systemctl enable --now snapd.socket
ln -s /var/lib/snapd/snap /snap
snap install core; snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot
certbot --nginx -d $HOSTNAME -m admin@$HOSTNAME --agree-tos -n
sed -i -e 's/ssl;/ssl http2;/' /etc/nginx/conf.d/$HOSTNAME.conf
nginx -s reload
To run it enter the following command
Bash:
bash setup.sh
Once the script has completed you will have a VPS all setup with PHP, MariaDB, nginx and SSL installed ready to go, if you browse to your domain you should see the PHP info page displayed.
Step 4 – Ioncube install, create database and user
CPVLab requires Ioncube installed and working before you can start to install it, so now we need to install that but like before I have shared a script to make this easier if you prefer but you will still need to setup a database.Skip to database creation if you are running the scripts.
Create another file like we did previously
Code:
vi inocube.sh
Enter insert mode and past the code below into the new file
Code:
cd /tmp
curl -O https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
tar xfz ioncube_loaders_lin_x86-64.tar.gz
phpver=$(php-fpm -i | grep -Po "(?<=PHP Version => ).*" -m 1 | grep -oE '[0-9]{1}\.[0-9]{1}')
cp /tmp/ioncube/ioncube_loader_lin_$phpver.so /usr/lib64/php/modules/
sed -i -e "/\[PHP\]/azend_extension = /usr/lib64/php/modules/ioncube_loader_lin_"$phpver".so" /etc/php.ini
rm -rf /tmp/ioncube*
systemctl restart php-fpm
You can check its installed correctly by looking at the Zend engine section of the PHP Info page.
Before install
After the install
Database creation
Now we just have to create a database to hold our CPVLab data in, this is actually pretty easy to do just run a few mysql commands but remember to change the password to something secure! You can also change the database name and username to something else to if you wanted to.
Code:
mysql -u root -e "CREATE DATABASE cpvlab_db;"
mysql -u root -e "GRANT ALL PRIVILEGES ON cpvlab_db.* TO 'cpvlab_usr'@'localhost' IDENTIFIED BY 'password';"
mysql -u root -e "FLUSH PRIVILEGES;"
Step 5 – Installing CPVLab
Now we are ready to start installing CPVLab itself, you will obviously need a copy of CVPLab so head over to https://cpvlab.pro/ and get you copy now. They have a free starter plan so you can get up and running for free and upgrade later on if you feel you need more.I already have an account so will go with that, login to https://users.cpvlab.pro/index.php then click the Install CPVLab Pro button to download the install package.
Once you have downloaded this you need to extract the files and upload them to the server using your favorite SFTP software, I use WinSCP on my PC and CyberDuck on my MacBook.
NOTE: Before uploading the files make sure you delete the index.php file we created earlier to test the server!
Now the files are uploaded head over to the install wizard page
https://yourdomain.com/install-wizard.php
It should look like this
Now enter the email address you setup your CPVLab account with and click the download install package button.
This will download the CPVLab setup files to your computer, you will need to extract and upload these like you did before for the install wizard.
After the files are uploaded you need to check the permissions and adjust them accordingly, so click the check permission button in Step 3, this will tell you what permissions you will need to set.
I have attached a script which will do this for you just double check to ensure that it captures all the files/folders mentioned and run it from the CPVLab install folder.
Code:
# set permissions for database and license files
chmod 666 lib/db_params.php
chmod 666 license/license.php
# set permissions on folders
chmod 777 -R mobiledata/cache
chmod 777 -R smarty/templates_c
chmod 777 -R phpbrowscap/BrowserCache
chmod 777 -R WURFLres
After running the perms script (or setting via your SFTP software) click the check permissions button again, this time it should be all green
We have already created a database perviously so you can skip Step 4 and go straight to Step 5 and enter the details from the database creation, your email should already be filled in but if not enter that then click Finish the Install.
It will only take a minute or so then you will be redirected to the login page, however, it will have a warning that you need to delete some files and set permissions again but I have attached a script that will do that for you as well, I’m nice like that. As before upload the file to the CPVLab install folder and run, the script will remove the perms script and itself once complete.
Code:
# remove the install wizard files
rm -f install-wizard.php
rm -f install-db.php
rm -f install-utils.php
rm -f cpvlabpro-db.sql
rm -f cpvlabpro-carriers.sql
rm -f built-install.min.css
rm -f built-install-body.min.js
rm -f built-install-head.min.js
# set permissions for database and license files
chmod 644 lib/db_params.php
chmod 644 license/license.php
Now you have a fully installed and working copy of CPVLab, login using admin as username and admin as the password, make sure you change these immediatley!
Once logged in go to Settings -> General Settings to change the default admin password
That’s it, we have setup and installed CPVLab ready to accept some traffic and help us bank.
Hope you found this guide useful, please do let me know how you get on with it or if you find any mistakes etc.
If you have any questions, please post and I’ll try to answer the best I can.