Category: Website developer

 

mongodb won’t start after rebooting the server

mongodb won’t start after rebooting the server

Mongodb, Sails, angular and Nginx were running smoothly after rebooting system, that was on Ubuntu on AWS amazon.
1- Mongodb, trying to run mongo, here is the


ubuntu@ip-172-0-0-1:~$ mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
2019-10-17T07:20:34.919+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2019-10-17T07:20:34.919+0000 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

Mongo won’t work unless you delete the mongod.lock, on
a) On windows it could be c:\data\db\monogod.lock
b) On Ubuntu(linux) is located on /var/lib/mongodb, you can check the path of mongo on file configuration mongod.conf:


...
# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
  mmapv1:
    smallFiles: true
#  wiredTiger:
.... 

So to delete mongod.lock


ubuntu@ip-127-0-0-1:/var/lib/mongodb$ rm mongod.lock
rm: remove write-protected regular empty file 'mongod.lock'? 

After deleting the mongod.lock, mongo should be able to work again, you start it by
ubuntu@ip-127-0-0-1:/var/lib/mongodb$ service mongod start

How to recover an Google Analytics Tracking Code, when you changed the website without it?

How to recover an Google Analytics Tracking Code, when you changed the website without it?

Google cached the website to view web pages cached in Google Search Results
Use the https://webcache.googleusercontent.com/search?q=cache:your-domain-url

Example:
1- https://webcache.googleusercontent.com/search?q=cache:https://ukgoodbye.co.uk

2- Step 2, Right click, and select “View source page” and search for Google tracking code on cached page.
Example it should look like:


 

.....
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-79894830-1');
....

Now check if the Google Analytic and the site can be crawl by the robots
You can use third parties website as http://www.gachecker.com/, to Check your entire site for missing Google Analytics or Google AdWords code with one click

Where the mongodb default database folder on linux, check the mongod.conf

Where the mongodb default database folder on linux, check the mongod.conf


cd /etc/mongod.conf
And it will say, Where and how to store data:
/var/lib/monogo

Example of monogo.conf default mongodb on linux(Ubuntu):


# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
  mmapv1:
    smallFiles: true
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

#processManagement:

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:


On Windows: example c:\data\db

Restore mongodb database from folder directly, mongorestore

Restore mongodb database from folder directly, mongorestore

1- Double check that mongod is runing
2- Use mongosrestore to import the mongodb from the folder, here is the example.


C:\data\db>mongorestore -d YourDatabase C:\sails\ukgoodbye_web\database\YourDatabase 

Solution of ,ng serve –host ukgoodbye.co.uk –port 8080, angular not detected

Solution of ,ng serve –host ukgoodbye.co.uk –port 8080, angular not detected

1- Solution tried to npm start…


npm start

> clean-ui@2.1.0 start /home/ukgoodbye/public_html/Theme/cleanui-admin-template-angular
> ng serve -w --port 1355 --host 0.0.0.0 --disable-host-check

You are running version v10.5.0 of Node.js, which is not supported by Angular CLI 8.0+.
The official Node.js version that is supported is 10.9 or greater.

Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.
npm ERR! code ELIFECYCLE
npm ERR! errno 3
npm ERR! clean-ui@2.1.0 start: `ng serve -w --port 1355 --host 0.0.0.0 --disable-host-check`
npm ERR! Exit status 3
npm ERR!
npm ERR! Failed at the clean-ui@2.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Angular 2 Remove Hash (#) from the URL,use theme cleanui-admin-template-angular

Angular 2 Remove Hash (#) from the URL,use theme cleanui-admin-template-angular

Example from the localhost, http://localhost:4200/#
Step 1: Modify the on Theme\cleanui-admin-template-angular\src\app\app.routing.ts, to next line

export const routing: ModuleWithProviders = RouterModule.forRoot(routes, { useHash: true });

to

export const routing: ModuleWithProviders = RouterModule.forRoot(routes);

Step 2: Add this code to index.html
Add this on file Theme\cleanui-admin-template-angular\src\index.html
….

<base href=”/”>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>

….

Connect via SSH, and download files and folders

Connect via SSH, and download files and folders

1- Connection via SSH(Secure Shell) using pem(Privacy Enhanced Mail is a Base64 encoded DER certificate.) file


ssh -l ubuntu -i ukgoodbye.pem ukgoodbye.co.uk

-l to indicate your user name -i to indicare you pem file
2 To download a file using scp:


scp  -i ukgoodbye.pem ubuntu@ukgoodbye.co.uk:/home/ubuntu/project/backup/13072019_backup.tar.gz /Users/macuser1/ukgoodbyeonline

3 To download a folders and files , you will need to add -r


scp -r -i ukgoodbye.pem ubuntu@ukgoodbye.co.uk:/home/ubuntu/project/ukgoodbye_web /Users/macuser1/ukgoodbyeonline/online/

Note:
Replace this with you details
ubuntu@ukgoodbye.co.uk by username@yourdomain
/home/ubuntu/project/backup/13072019_backup.tar.gz by your remote folder and file to download

Http error, uploading SVG on WP, solution

Http error, uploading SVG, solution

To upload SVG on backend on WordPress, you should  install a plugin to do so like SVG support by

1- Download and install the plugin

SVG Support plugin

2- Now, you should be able to upload SVG files.  If you are able to upload other types files like PNG, JPG but not SVG that could be the case your hosting provider do not allow to so like on Godady,

Access Denied – GoDaddy Website Firewall
If you are the site owner (or you manage this site), please whitelist your IP or if you think this block is an error please open a support ticket and make sure to include the block details (displayed in the box below), so we can assist you in troubleshooting the issue.
for information check on the next picture:

Access Denied Godady

 

Vimeo embed won’t autoplay, what to do?

Vimeo embed won’t autoplay, what to do?

If you are using ACF, you need to choose field type “oEmbed”

You will need to add

and your php code


$video=$row['video'] ;
      
preg_match('/src="(.+?)"/', $video, $matches);
$src = $matches[1];


// add extra params to iframe src
$params = array(
    'playsinline' => 1,
				'controls'    => 0,
				'hd'  => 1,
				'autoplay' => 1,
				'background' => 1,
				'loop' => 1,
				'byline' => 0,
				'title' => 0,
                                'muted' => 1
);

$new_src = add_query_arg($params, $src);

$video = str_replace($src, $new_src, $video);


// add extra attributes to iframe html
$attributes = 'frameborder="0"';

$video = str_replace('>', ' ' . $attributes . '>', $video);
echo $video;

So it is important to set up autoplay to 1, loop to 1

WordPress, why ACF won’t appear on menu my WP dashboard?

WordPress, why ACF won’t appear on menu my WP dashboard?

There are many reasons Advanced Custom Fields, doesn’t appear in dashboard menu. The custom fields menu item can be hidden like on the next example:
Check on the wp-content/theme/your-active-theme/functions.php



....
add_filter('acf/settings/show_admin', '__return_false');
....

 

By removing this line the ACF should appear back to the dashboard.
"Custom Fields" doesn't appear in dashboard menu

 

 

 

 

You can try to  access to ACF menu, by type you browser

http://your-domain/wp-admin/edit.php?post_type=acf-field-group,