Category Archives: Ubuntu Server

MTConnect FANUC Adapter on Ubuntu Linux

 

The FANUC FOCAS shared library from the FANUC FOCAS CD A02B-0207-K737 version 4.1 or higher  must first be installed and registered in Ubuntu 14.04 LTS.

$ sudo cp libfwlib32.so.1.0.0 /usr/local/lib/libfwlib32.so.1.0.0
$ sudo ldconfig
$ sudo ln -s /usr/local/lib/libfwlib32.so.1.0.0 /usr/local/lib/libfwlib32.so

Next up we need to get the MTConnect adapter from GitHub.

$ cd ~ 
$ git clone https://github.com/mtconnect/adapter.git

We only actually need a limited subset of files from the adapter downloaded from GitHub.  For convenience in building the binary we will copy all the needed files to the same directory. (Note, so wildcards can be used more than the needed files are copied.)

$ mkdir fanuc
$ cp ~/adapter/fanuc/adapter.ini ~/fanuc/adapter.ini
$ cp ~/adapter/fanuc/fanuc.xml ~/fanuc/fanuc.xml
$ cp ~/adapter/fanuc/*.cpp ~/fanuc/
$ cp ~/adapter/fanuc/*.hpp ~/fanuc/
$ cp ~/adapter/src/*.cpp ~/fanuc/
$ cp ~/adapter/src/*.hpp ~/fanuc/
$ cp ~/adapter/minIni_07/*.c ~/fanuc/
$ cp ~/adapter/minIni_07/*.h ~/fanuc/

Once the files are in the ~/fanuc/ directory, we need to modify the source code.  The GitHub adapter was meant for Windows, and their are several functions that need to be modified.

$ sudo nano ~/fanuc/fanuc_adapter.cpp
  
    Remove: #include <excpt.h>
    Change: __try and __exception to try/catch(...)

    Change: Sleep(5000) to sleep(5)

    Change: _strnicmp() to strncasecmp()

    Add Before : short ret = :: cnc_allclibhndl3...

    long level = 3;
    std::string filename = "focas.log";
    const char * c =  filename.c_str();
    short log = ::cnc_startupprocess(level, c);

    Add After: cnc_freelibhndl....

    cnc_exitprocess();

Finally the header file for Linux from the FOCAS cd is copied to the directory.  Note the name change required as the source files refer to to Fwlib32.h.

$ sudo cp fwlib32.h ~/fanuc/Fwlib32.h

With the source code modified, its time to compile the binary.  Sorry for the sloppy g++ command, this could be cleaned up with a nice CMakeLists.txt.

$ cd ~/fanuc/
$ g++ minIni.c device_datum.cpp fanuc_axis.cpp fanuc_path.cpp service.cpp condition.cpp cutting_tool.cpp string_buffer.cpp logger.cpp client.cpp server.cpp adapter.cpp fanuc_adapter.cpp FanucAdapter.cpp -lfwlib32 -lpthread -o adapter

Finally setup the adapter.ini file with the appropriate settings for your machine and run the binary.

$ ./adapter debug adapter.ini

Conclusion I’m certain one day the source code for the Linux FANUC adapter will be available from GitHub as the code is just a slight adaptation from the Windows version.  Until then, I hope you enjoyed this tutorial!

Installing WordPress in Ubuntu 14.04 LTS

Installing WordPress

Assuming your LAMP is up and running we start with downloading WordPress to the home directory.  It is unzipped, modified before being moved to our /www/html/ site.

$ cd ~$ wget http://wordpress.org/latest.tar.gz
$ tar -xzvf latest.tar.gz

From the mysql shell we will create a structure WordPress can use.

$ mysql -u root –p
> CREATE DATABASE wordpress;> CREATE USER wordpress@localhost;

> SET PASSWORD FOR wordpress@localhost= PASSWORD(“password”);

> GRANT ALL PRIVILEGES ONwordpress.* TOwordpress@localhost IDENTIFIED BY 'password';

> FLUSH PRIVILEGES;

> exit;

Now that the MySQL database is ready for the WordPress installer, a few items need to be set so WordPress knows how to reach the database.  This is done in the wp-config.php file.  Make sure to set the username, password, database and security salts.

$ cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php 
$ sudo nano ~/wordpress/wp-config.php

Lets copy all the WordPress files so they are served by Apache.

$ sudo rsync –avP ~/wordpress /var/www/html/
$ cd /var/www/html$ sudo chown www-data:www-data * -R 
$ sudo usermod -a -G www-datausername

Finally, open your browser and setup WordPress!

 

References:

How To Install WordPress on Debian 7

 

 

Setting up an Ubuntu 14.04 LTS Server

This blog is a reference for my current Ubuntu 14.04 setup.  I struggled to find correct information on-line especially with mysql setup.  This ensures its available in the future.  Digital Ocean servered as a great resource for the setup.

 

Setup a User

Add a user account for yourself. This is easy with the adduser command. Just follow the prompts to update set a password and any other information.

# adduser someuser

Since this is your account, you need to give all sudo privileges to the new account. Open up the list of sudoers with the visudo command and add your username below root with all privileges.

# visudo
   # User privilege specification
   root  ALL=(ALL:ALL) ALL
   someuser ALL=(ALL:ALL) ALL

Final switch from the root user to the sudo account you’ve created.

# su someuser

 

Updating packages

Several packages will be out of date and need to be updated. This is done with two commands. The update command retrieves a list of all packages and dependencies for updating purposes. Finally the

$ sudo apt-get update
$ sudo apt-get dist-upgrade

 

Add a Swapfile

How about adding a swapfile to decrease any chance of a memory overflow error. Use the fallocate command. The 2G is the size, 2 gigabytes. Finally check its OK using ls to confirm the size is 2GB.

$ sudo fallocate –l 2G /swapfile
$ ls –lh /swapfile

Enable the swapfile

$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile

The swapfile is now up and running, however, to have it permanently on the fstab file has to be edited. The swapfile is put at the bottom of the file.

$ sudo nano /etc/fstab
     /swapfile   none   swap   defaults   0   0

 

Install Apache Web Server

Next up the webserver apache2 is installed. After the server is installed the ServerName will need to be set to eliminate the “Could not reliably determine the server’s fully qualified domain name” nag. Finally restart apache2 to confirm the setting is correct.

$ sudo apt-get install apache2
$ sudo nano /etc/apache2/apache2.conf
      # Default ServerName
      ServerName www.mysite.com
$ sudo service apache2 restart

 

Install MYSQL Server

Time to setup MYSQL. Install the package and then secure it by running my_sql_install_db

$ sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql php5-gd
$ sudo mysql_install_db

 

Install PHP5 for Apache

Finally we need PHP in our LAMP. Once the packages are downloaded and installed, the extension .php has to be moved up the default order of extensions apache will search for when an extension is omitted. This is done by editing the dir.conf file.

$ sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
$ sudo nano /etc/apache2/mods-enabled/dir.conf
$ sudo service apache2 restart


Reference
How To Install Linux, Apache, MySQL, PHP (LAMP)stack on Ubuntu

How To Add Swap on Ubuntu 14.04