Ubuntu: Restrict Access to PHPMyAdmin

Add this directives if you want to allow only 8.8.8.8 to view your phpmyadmin
Order Deny,Allow
Deny from All
Allow from 8.8.8.8

to
/etc/phpmyadmin/apache.conf

<Directory /usr/share/phpmyadmin>
        Options FollowSymLinks
        DirectoryIndex index.php
        #allow access to specific IP
        Order Deny,Allow
        Deny from All
        Allow from 8.8.8.8

        <IfModule mod_php5.c>
                AddType application/x-httpd-php .php

                php_flag magic_quotes_gpc Off
                php_flag track_vars On
                php_flag register_globals Off
                php_admin_flag allow_url_fopen Off
                php_value include_path .
                php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
                php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/javascript/
        </IfModule>

</Directory>

then restart apache
sudo service apache2 restart

tsc.exe exited with code 1

Visual Studio 2015 build error after adding typscripts
tsc.exe exited with code 1
Open project ____.csproj in text editor and remove 2.0
you can search for TypeScriptToolsVersion

Also since I was practicing typescript that time, I also removed all .ts to clean my project.

Asp.net Web API 2

1. Create new folder.
2. Right click on the newly created folder, select Add > Controller > Web API 2 Controller – Empty

A readme.txt will open containing the instruction.

Visual Studio has added the full set of dependencies for ASP.NET Web API 2 to project .

The Global.asax.cs file in the project may require additional changes to enable ASP.NET Web API.

1. Add the following namespace references:

using System.Web.Http;
using System.Web.Routing;

2. If the code does not already define an Application_Start method, add the following method:

protected void Application_Start()
{
}

3. Add the following lines to the beginning of the Application_Start method:

GlobalConfiguration.Configure(WebApiConfig.Register);

Protecting WordPress Login

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# Stop Apache from serving .ht* files
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>

# Protect wp-login
<Files wp-login.php>
AuthUserFile ~/.htpasswd
AuthName "Private access"
AuthType Basic
AuthUserFile /absolute-path-to-htpsswd/.htpasswd
Require valid-user
</Files>

https://codex.wordpress.org/Brute_Force_Attacks

Backlinks

-One of Googles top criteria for ranking pages
-Quality over quantity
–small number of backlinks from quality sites are better than more but from spammy sites
-Check you competitors links including total count, quality and sources

Facebook Page Promotion

The estimated likes per day can greatly vary as reported. One marketing I had on a local city initially reports only 2 ~ 9 likes per day but on actual it yields to 27 for the first 8 hours of the campaign. So just launch the campaign and observe.

There are many factors the affects the yield of your campaign, make sure it is visually appealing, interesting, suggests something to do and always know your clients first to yield better results.

Improving Database Response Time Using Index

I had an experience when our web application has taken time to load a page the gets data from database. It’s around 6 seconds before the user can see the page. When it was new, less records, everything was fast.

I did an audit to the code checking the time of every process looking for the part that is taking a lot of time. The problem was some queries are joining tables with large rows.

The solution was to create column indexes.

From around 6 seconds it is able to load around 0.200 ms now.

Consider query below:
SELECT users.* FROM users
JOIN addresses ON addresses.user_id = users.id
JOIN cities ON cities.id = addresses.city_id
JOIN provinces ON provinces.id = addresses.province_id

If it takes time to load you could consider indexing address table
ALTER TABLE addresses ADD INDEX(user_id,city_id,province_id)

Note, the order of column index in addresses table is important. First is user_id, followed by city_id then province_id as also shown in the query.

While indexing speeds the read of query, it also has negative impact on write query as indexes needs to be updated when a new row is added or modified.

Combine indexing and cache technology to further increase response time.

Unify www and non-www site

Create .htaccess inside document root and add
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The first RewriteRule does permanent redirect (301) to traffics if it starts with www to https://example.com

The second RerwiteRule does permanent redirect (301) to traffics if it’s an http request to https://example.com

Www, non-www, https and non-https are treated different site by search engines.
So it’s important to unify them for SEO purposes.

Reference: https://moz.com/community/q/302-or-301-redirect-to-https

Serving web content from user’s home directory.

I had a problem getting "Forbidden You don't have permission to access /index.php on this server." after confirming all virtual host settings and folder permission are correct.

I’ve set $ sudo chown -R apache.apache /home/anthony/example.com and $ sudo chmod -R 755 /home/anthony/example.com but I still get the error.

When I looked /home, $ cd /home $ ls -l I saw the problem, anthony has 700 permission,
drwx------ 3 anthony anthony 115 Feb 7 22:54 anthony
so apache can’t get through anthony directory. My solution is to make anthony directory 750 sudo chmod 750 /home/anthony and add apache user to anthony group sudo usermod -a -G anthony apache

Then restart apache
sudo service httpd restart

That solved the problem and I can now see my website.

Below is my VirtualHost Config

<VirtualHost *:80>
    ServerAdmin email@example.com
    ServerName example.com
    DocumentRoot /home/anthony/example.com/public_html
    
    <Directory “/home/anthony/example.com”>
        AllowOverride None
        # Allow open access:
        Require all granted
    </Directory>
    
    <Directory “/home/anthony/example.com/public_html”>
        AllowOverride All
        Options Indexes FollowSymLinks
        Require all granted
    </Directory>

</VirtualHost>

Integrate Laravel and Chat Server using WebSocket

Create a file chat-server.php
<?php
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use App\Http\Chat;
require 'vendor/autoload.php';
//load laravel framework
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
)
),
9090,
'0.0.0.0' //allow none-localhost ip
);
$server->run();

App\Http\Chat.php is a class that implements Ratchet\MessageComponentInterface. Detailed implementation is found here http://socketo.me/docs/hello-world

To run, open commandline and type $ php chat-server.php If you update the file and related to it make sure to restart the chat server using Ctrl+C then running the command again.

If you encounter “Could not find driver” while using chat-server.php that means there is no enabled mysql driver in php terminal. You can find solutions here http://codes.anthonyaraneta.com/php/could-not-find-driver-in-ubuntu-cli