Category Archives: open source

Apache2 website hosting for Linux

when hosting on a Linux variant, you may need a config file that will do proper redirect

create the a file, naming it a meaningful name ending in *.conf.
ie: if your domain is domain.com, create the name:  domain.com.conf
———————————–

<VirtualHost *:80>
ServerAdmin [Email Address here]
ServerName [subdomain].[domain].com
ServerAlias [subdomain].[domain].com
DocumentRoot /var/www/[codeDirectory]/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /var/www/[codeDirectory]/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
———————————–
on the “server Name” line, if it is top level domain, exclude the “subdomain” section.  otherwise insert it in.

if you have any other domains you’d like to redirect here, server alias will be inserted on following line.  for instance:

you want people to go to www.domain.com, the “ServerName” will be www.domain.com, and alias will be domain.com  you can switch them if desired.

when the file is ready, upload to /etc/apache2/sites-available/ location and do the following

1) a2ensite domain.com.conf

2) systemctl restart apache2

changing the domain.com.conf to what you named your file and do a apache2 restart apache.

Linux Apache2 Redirect

if you ever have a problem with Site.com/page/ returning an error, look into your apache file

in /etc/apache2/apache2.conf

either download and edit or navigate there and load via your favorite tool (ie Nano, vi, etc)

Change “AllowOverride” from “None” to “All”.

<Directory />
Options FollowSymLinks
      AllowOverride All
Require all denied
</Directory>

<Directory /var/www/>
Options Indexes FollowSymLinks
      AllowOverride All
Require all granted
</Directory>

 

Reload Apache2 (run the following command in Linux)

systemctl restart apache2

Querying MySQL via PHP

TO Ensure we are able to dynamically call Selects inserts updates and Deletes from functions, see below on one method on how to do it via PHP to MySQL

<?php
//config.php
//echo "hit config 1 <br/>";

function OpenCon()
{
$isLocal = 0;

if($isLocal ==0)
{
$dbhost = "[IP]"; 
$dbuname = "[user name]"; 
$dbpass = "[password]"; 
$dbname = "[database]"; 
$port = "3306";
$charset = 'utf8mb4';
}else{
$dbhost = "localhost"; //need to change this to the eventual remote IP
$dbuname = "[user name]"; 
$dbpass = "[password]"; 
$dbname = "[database]"; 
$port = "3306";
$charset = 'utf8mb4';
}

$conn = mysqli_connect($dbhost, $dbuname, $dbpass,$dbname);
//echo "<br/>$dbhost, $dbuname, $dbpass,$dbname<br/>";
return $conn;

}

function CloseCon($conn)
{
//$conn -> close();
mysqli_close($conn);
}

function SelectCon($queryMe){
$conn = OpenCon();

if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

$result = mysqli_query($conn, $queryMe);// or trigger_error(mysqli_error()); 

return $result;
}

function InsertCon($insertMe){
$conn = OpenCon();
/*
echo "<br/>";
echo $insertMe;
echo "<br/>";
*/
if (!$conn) {
echo "<br/>connection failed<br/>";
die("Connection failed: " . mysqli_connect_error());
}elseif($conn){
$result = mysqli_query($conn, $insertMe);

if($result) {
echo "Records inserted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
CloseCon($conn);
return false;
}
}else{
echo "conn fail success not ran";
}
global $last_id;
$last_id = mysqli_insert_id($conn);
CloseCon($conn);

return true;
}

function UpdateCon($updateMe){
$conn = OpenCon();

if (!$conn) {
echo "<br/>connection failed<br/>";
die("Connection failed: " . mysqli_connect_error());
}elseif($conn){
$result = mysqli_query($conn, $updateMe);

if($result) {
echo "Records updated successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
CloseCon($conn);
return false;
}
}else{
echo "conn fail success not ran";
}

CloseCon($conn);

return true;
}

function DeleteCon($deleteMe){
$conn = OpenCon();

if (!$conn) {
echo "<br/>connection failed<br/>";
die("Connection failed: " . mysqli_connect_error());
}elseif($conn){
$result = mysqli_query($conn, $deleteMe);

if($result) {
echo "Records deleted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
CloseCon($conn);
return false;
}
}else{
echo "conn fail success not ran";
}

CloseCon($conn);

return true;
}
?>

Batch restart MS SQL

if you need to reboot SQL server in Windows server(or local machine) and want to do this quickly on the server, login and create a batch file with the following parameters: (change mssqlserver for the server instance name you have)

 

net stop mssqlserver
net start mssqlserver
net start SQLSERVERAGENT
pause

save the file as “rebootSQLServer.bat”