Create Self-Signed Certificate With Nginx On Ubuntu 16.04

Ref: https://www.humankode.com/ssl/create-a-selfsigned-certificate-for-nginx-in-5-minutes
https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-nginx-in-ubuntu-16-04

In this tutorial, I’m going to show you how you can create a self-signed SSL/TLS certificate and use it on Nginx in 5 minutes or less. I’m using Ubuntu for this tutorial, but if you’re on Mac OSX you can follow along as the syntax and commands are nearly identical.

Why Create a Self-Signed Certificate?
Self-signed certificates are useful for local development where you want to simulate an HTTPS environment. Take note that self-signed certificates are not meant for production, but they are ideal for localhost development.

An Overview of Creating a Self-Signed Certificate
Before continuing, let’s take a step back and look at the steps involved in generating a self-signed certificate for Nginx:

Generate a self-signed certificate using OpenSSL
Copy the certificate to the certificates folder on Ubuntu
Update the Nginx configuration file to load the certificate
Copy the certificate’s public key to the CA trusted root database to prevent Google Chrome from showing the site as insecure

Step 1: Generate a Self-Signed Certificate using OpenSSL
I’ll use OpenSSL to generate the certificate on Ubuntu. OpenSSL is installed on Mac OSX by default and the commands are exactly the same.

OpenSSL will generate 2 files which consist of a private key and a public key. Even though most people refer to an SSL/TLS certificate in the singular sense, it is the combination of the private key and the public key that makes a certificate.

Before running the OpenSSL command to generate a self-signed certificate, I’m going to create a certificate configuration file that will specify the certificate bits and the Subject Alternative Names. The Subject Alt Names are required in Google Chrome 58 and later, and is used to match the domain name and the certificate. If the domain name is not listed in the certificate’s Subject Alternative Names list, you’ll get a NET::ERR_CERT_COMMON_NAME_INVALID error message.

Create the Certificate Configuration File

I want to make a self-signed certificate for my local magento 2 site. The site is fontaineind.test
Here is the content of fontaineind.test.conf file:

Create the Certificate using OpenSSL

Here is the terminal output. For the inputs on the terminal asking like country name, etc, just click enter key to accept the default values:

It’ll create two new files. There are fontaineind.test.crt and fontaineind.test.key:

Step 2: Copy the Certificate Key Pair to the Certificates folder on Ubuntu
Copy the public key to the /etc/ssl/certs directory

Copy the private key to the /etc/ssl/private directory

Step 3: Update the Nginx Configuration File to Load the Certificate Key Pair

Change it like this:

Reload the Nginx configuration changes

Then don’t forget to change the secure url on the database. Just find it :

Change ‘http’ to ‘https’ for ‘web/secure/base_url’ and ‘web/secure/base_link_url’

NOTE: It’d be better to change to https also for ‘unsecure’ url
Open up the Google Chrome to Verify that Nginx Loads the Site Over HTTP and HTTPS
Since I haven’t added the self-signed certificate to Chrome’s CA Root store, Chrome shows the site as insecure. Click proceed to fontaineind.test to verify that Nginx is correctly configured
open: https://fontaineind.test/Step 4: Configure Chrome to Trust the Certificate and to Show the Site as Secure
Add the certificate to the trusted CA root store but need to check if ‘certutil’ if exist. If not install it with sudo apt install libnss3-tools:

Then run this on the terminal:

Close all the Google Chrome windows and reopen. Chrome is now showing the site as secure.Now I want to redirect all connection from http to https.
Make sure you changed the ‘unsecure’ url on the database to use https instead. Then modify the nginx setting for fontaineind.test

Then change like this:

Reload the nginx server. But if you check the nginx config setting, it’d show error like this:

It shows error about the certificate. Probably because it’s a self-signed certificate. Anyway we can ignore it on the development stage. If you open http://fontaineind.test:8080, it’d be redirected to https://fontaineind.test
So all good.

Install and Configure Varnish for Nginx and Magento 2 on Ubuntu 16.04

Ref:https://blog.pusher.com/speeding-up-your-website-using-varnish/
https://www.cyberciti.biz/faq/how-to-install-and-configure-varnish-cache-on-ubuntu-linux-16-04-lts/
https://www.howtoforge.com/tutorial/ubuntu-nginx-varnish/
https://amasty.com/blog/use-varnish-with-magento-2-for-better-end-user-experience/

Install Varnish:

Start/stop/restart the varnish service:

Check the varnish status (when active):

Varnish installed and it is a default configured to listen on port 6081 and 6082 for varnish admin:

When we open on the browser: http://localhost:6081/, we’d get a varnish error pageHowever http://localhost:6082/ will show page error.
We will be changing this so it listens on port 80 (fontaineind use the default port 6081 for varnish)  and Nginx listens on port 8080. To do this, edit your site’s Nginx configuration file. In our case, this file is /etc/nginx/sites-available/fontaineind.test.

modify

Save the file. Then restart nginx server:

When you open your website with the port 8080, http://fontaineind.test:8080, It’d show the website but the css seems missing! I think I need to clear the cache and rebuild the cache. but it show an expected error.

Another error when trying to show the magento 2 command:

Solution: THIS IS BECAUSE I USE PHP 7.2. CHANGE IT TO PHP 7.0

Then the magento 2 command is running well back.

also probably I need to change the base url to include the port 8080? –> NO NEED. we will take it later. Let’s continue.

Now that port 80 is free (NO. I NEED TO CHECK IT VIA sudo netstat -plntu | grep ‘:80’), let’s configure Varnish to be the one that responds. Open the file /etc/default/varnish for editing. Here is the default content.

Look for the line below:

change ‘-a :6081’ to ‘-a :80’:

Save the file.
NOTE: I also can change the malloc. malloc is RAM usage for Varnish. Default is 256m. I can change it to (for example) 1024m (1G)

Next, open the file /etc/varnish/default.vcl and check that the default backend is set to port 8080, because this is where Nginx serves from now. Look for the line below and make sure the .port is 8080. Here is the default content:

NOTE: For the explanation of vcl_recv, vcl_backend_response and vcl_deliver, pls read https://amasty.com/blog/use-varnish-with-magento-2-for-better-end-user-experience/
make sure the backend port is 8080

Once you have confirmed this, the next thing will be to copy the varnish.service file to our systemd directory. This will enable systemd to start varnish on port 80. Run the command below:

This will copy the varnish service file, and then open an editor with the contents.

Look for the ExecStart line:

Now change the -F -a :6081 to -F -a :80. Leave the localhost:6082 on the same line as it is. Now save and exit the file. Run the commands below to reload everything you have just configured:

The commands above will reload the system daemon, reload varnish, restart the varnish service, and restart Nginx.
NOTE: I need to check the varnish status as well. Varnish can’t start because port 80 already is use:

Check who is using port 80:

it seems nginx with pid 19110 is using both port 80 and 8080. or here is the complete list:

Solution: nginx use both ports 80 and 8080 because in sites-enabled directory there are many nginx setting for different websites that it still use port 80.

SO. REPLACE THE PORT 80 TO 8080 FOR ALL WEBSITE IN SITES-ENABLES DIRECTORY!!!
AFTER I CHANGED THE PORT IN ALL THE WEBSITE, NO MORE APPLICATION USE PORT 80 ANYMORE

OR

Nginx is using port 8080 now. I can start varnish and check the status:

NOTE: TO RUN THE OTHERS RUNNING WEBSITE (WITHOUT VARNISH RUINNING) THAT IT HAD BEEN WORKING PREVIOUSLY, I NEED TO ADD THE PORT 8080 AT THE END OF THE URL. FOR EXAMPLE:
http://localhost:8080/phpinfo.php
http://notarisfemira.test:8080/
http://phpmyadmin.test:8080

Now visit the IP of your web page and you should see nothing has changed. However, when you run it through the HTTP checker we used before, you should see that the headers have changed.
http://fontaineind.test/ –> First time run about 20 seconds

The second run (refresh) about 9 seconds

NOTE: I can see some variables like X-Varnish and Age. But why Age still 0 on the refresh page? It means it miss the cache.
In magento, I already enabled Page Cache and Block HTML cache.

Configure Magento to use Varnish
To configure Magento to use Varnish:

Log in to the Magento Admin as an administrator.
Click STORES > Configuration > ADVANCED > System > Full Page Cache.
From the Caching Application list, click Varnish Cache (recommended).
Enter a value in the TTL for public content field.
Expand Varnish Configuration and enter the following information:
Access list: localhost   –> 172.31.31.224 for fontaineind.com.au
Backend host: localhost   –> 172.31.31.224 for fontaineind.com.au
Backend port: 8080
Then click a button ‘Export VCL for Varnish 4’ -> It’d create a file ‘varnish.vcl’ and download it.
Here is the file content:

SO I need to modify the content of /etc/varnish/default.vcl according to this varnish.vcl.

Just copy and paste all content of varnish.vcl to all content in /etc/varnish/default.vcl. Then restart varnish: sudo service varnish restart
NOTE: IN THE DEV SERVER, I PREFER TO DISPLAY THE X-VARNISH AND AGE VARIABLES. SO I MODIFIED /etc/varnish/default.vcl LIKE THIS:

I also modified /home/teddy/Documents/works/fontaineind/app/etc/env.php to include the varnish setting:

clear and flush the cache. BUT Age still 0 !!!! EVEN WEIRDS, WHEN I CHANGED IN THE MAGENTO ADMIN THAT CACHE APPLICATION IS VARNISH THEN REFRESH THE WEBSITE (ALSO RESTART VARNISH), I GOT THE PAGE LOAD SLOWER!!! WHY?? –> SOLUTION: I NEED TO EXPORT VCL FILE LIKE ABOVE AND COPY THE CONTENT INTO /etc/varnish/default.vcl

NOW THE VARNISH IS WORKING!!!
THE SECOND AND MORE REFRESH WOULD MAKE THE PAGE LOAD FASTER. HERE IS THE RESPONSE:

SEE THE AGE = 42 AND X-Varnish: 131131 3

Compile OpenCV 3.1 And Python 2.7 With CUDA 7.5 On Ubuntu 14.04

COMPILE OPENCV 3.1 AND PYTHON 2.7 WITH CUDA
ref:http://rolflussi.blogspot.co.id/2015/09/opencv-with-cuda-on-ubuntu-1404.html
1. Create a new virtualenv with python parameter point to python2.7.

2. Check python version:

3. Check pip version:

4. Install numpy:

CHECK numpy VERSION:

IMPORTANT: I FOUND AN ERROR ‘The data should normally be NULL! in function allocate’ WHEN TRY TO TEST SIFT Holography Feature Matching (flann.knnMatch). PLS FIX THIS FIRST (SEE SOLUTION IN /media/data/MASTER/opencv/github_list_fish_rec.txt) BEFORE BUILD OPENCV AT STEP #5 BELOW! — OKAY. THIS IS ALREADY FIXED ON THE LAST COMPILE (OPENCV 3.1 WITH PYTHON 2.7)

5. We already cloned opencv 3.1.0 and opencv_contrib 3.1.0. so now, go to the build WITH CUDA and do setup:
<OLD>
THIS IS THE INITIAL CMAKE COMMAND: (DONT USE IT!)

</OLD>

<OLD>
THIS IS THE CMAKE COMMAND WITH CUDA I GOT FROM http://rolflussi.blogspot.co.id/2015/09/opencv-with-cuda-on-ubuntu-1404.html: (DONT USE IT! ‘WITH_QT’ COMMAND GAVE ME AN ERROR! MAY BE I DONT HAVE QT INSTALLED)

THIS IS THE ERROR:

</OLD>

<NEW>
THIS IS THE CMAKE COMMAND WITH CUDA AND REMOVE ‘WITH_QT’ COMMAND. THIS IS WORK!!! BUT MAKE SURE ‘build’ directory EMPTY FIRST!
NOTE: I USE ‘INSTALL_C_EXAMPLES=ON’ INSTEAD OF ‘OFF’ LIKE PREVIOUS BUILD. LET ME KNOW IF EVERYTHING WORKS (ITS CONFIRMED!!!)

</NEW>

NOTE:
PLS SEE THE NVIDIA CUDA PART ON THE ABOVE RESULT IS INCLUDED! BUILD WITH CUDA IS FAST (A FEW MINUTES)!

6. Compile opencv:
NOTE: BEFORE EXECUTING THIS, CONSIDER TO EDIT THIS FILE:

SEE BELOW HOW TO MODIFY IT!!!

NOTE:
AFTER WAITING FOR MORE THAN 1 hour AND 25 MINUTES (91% COMPLETED), THE COMPILATION IS STOPPED WITH THESE ERRORS STACK:

SOLUTION:
ref:https://github.com/Itseez/opencv/issues/5859
I USED A TEMPORARY SOLUTION: EDIT /home/teddy/opencv/build/samples/gpu/CMakeFiles/example_gpu_opengl.dir/link.txt. THEN ADD THIS: -lGL -lGLU AT THE END OF THE LINE (IN SINGLE LINE! DONT ADD AT THE NEW LINE!). SO THE FILE WOULD BE LIKE THIS:

SAVE THE FILE THEN RE-MAKE (BUT I SUGGEST TO REMOVE ‘build’ DIRECTORY, CREATE IT AGAIN LIKE STEP #5. BUT BEFORE EXECUTING STEP #6, EDIT link.txt FILE LIKE THE ABOVE! ). THIS SOLUTION IS WORKING!!!
ACTUALLY THERE IS A PERMANENT SOLUTION IS SUGGESTED IN THE SAME URL, BUT I DONT KNOW HOW TO DO IT!!! LEARN IT

OK. HERE IS THE SUCCESFULL COMPILE (MAKE)

NOTE:
SEE THE MORE COMPLETE COMPILATION (MAKE) PROCESS IN THIS FILE: /media/data/MASTER/opencv/make_opencv_cuda.txt
ITS NOT FULL COMPLETED BECAUSE I MISSED SOME DATA BUT IT WORTHS TO SEE (THERE ARE SOME WARNING!!!)
THIS COMPILATION TOOK MORE THAN 1 hour AND 30 MINUTES. COMPILATION WITH CUDA (MAY BE ALSO WITH OPENGL) MAKE IT SLOWER!!!

WARNINGS:
1.

2.

7. Assuming OpenCV 3.1 compiled without error, you can now install it on your system:
NOTE: BEFORE EXECUTING THIS COMMAND, MODIFY AGAIN THE ABOVE FILE: /home/teddy/opencv/build/samples/gpu/CMakeFiles/example_gpu_opengl.dir/link.txt OR WE’D GET THE SAME ERROR (PLS SEE THE ERROR HERE: /media/data/MASTER/opencv/opencv_cuda_make_install_error.txt ):

THIS TIME WE MUST USE SUDO BECAUSE THE FILE IS LOCKED:

THEN ADD THIS AT THE END OF THE SINGLE LINE LIKE ABOVE: -lGL -lGLU
THEN SAVE AND CLOSE
INSTALL AGAIN:

NOTE:
FOR COMPLETE PROCESS RESULT, SEE THIS FILE: /media/data/MASTER/opencv/opencv_cuda_make_install_success.txt

8.

9. If you’ve reached this step without an error, OpenCV should now be installed in /usr/local/lib/python2.7/site-packages
However, our ‘opencv_p27_cuda’ virtual environment is located in our home directory — thus to use OpenCV within our cv environment, we first need to sym-link OpenCV into the site-packages directory of the ‘opencv_p27_cuda’ virtual environment:

10. Check the installation opencv version:

11. EXECUTE SOME OPENCV EXAMPLES in /home/teddy/opencv/build/bin/ DIRECTORY:
a. Run this example (image grain):

b. Test Cuda Codec:

 

Installation of CUDA Toolkit 7.5 On Ubuntu 14.04

CONSIDER USING CUDA???
FROM THIS: https://en.wikipedia.org/wiki/CUDA, MY GPU Nvidia GeForce GT 520M IS SUPPORTED!!! Micro Architecture Fermi (https://en.wikipedia.org/wiki/Fermi_(microarchitecture)) version 2.1
CHECK CUDA FROM TERMINAL:
ref:http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/#axzz44a7lZNcT

INSTALLING CUDA TOOLKIT 7.5 ON UBUNTU 14.04
ref:http://www.r-tutor.com/gpu-computing/cuda-installation/cuda7.5-ubuntu
https://www.quantstart.com/articles/Installing-Nvidia-cuda-on-Ubuntu-14-04-for-Linux-GPU-Computing
https://developer.nvidia.com/cuda-downloads -> Linux -> x86_64 -> Ubuntu -> 14.04 -> deb(local)
http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda-repo-ubuntu1404-7-5-local_7.5-18_amd64.deb
(1.9 GB)
1. The first task is to make sure that you have the GNU compiler collection (GCC) tools installed. This is carried out by installing the build-essential package:

2. Download the latest Cuda toolkit:
Manually FROM:
http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda-repo-ubuntu1404-7-5-local_7.5-18_amd64.deb
OR:

3. PREPARE THE PACKAGE:

OK

4. Update

5. INSTALL CUDA:

SOLUTION:
ref:http://askubuntu.com/questions/672047/anyone-has-successfully-installed-cuda-7-5-on-ubuntu-14-04-3-lts-x86-64

RUN AGAIN:

6. REBOOT

7. MODIFY ENVIRONMENT VARIABLES:
As part of the CUDA environment, you should add the following in the .bashrc file of your home folder.

ADD THESE LINES AT THE BOTTOM:

THEN SAVE AND CLOSE!

8. Remember to make sure that the terminal has access to these variables:

9. Before proceeding to test the GPU cards we will ensure that the drivers are correctly installed. The following line will provide us with the driver version:

10. Check the version of the Nvidia CUDA compiler:

TRY THE CUDA 7.5 SAMPLES:
1. Copy the samples into /home/teddy/Documents/

2. GO to the samples directory:

3. Go to the deviceQuery directory THEN make:

4. run the deviceQuery script to test if we can communicate with the GPU:

 

5. Go to the bandwidthTest directory THEN make:

 

6. run bandwidthTest:

 

Installation of OpenCV, Keras and Tensorflow On Ubuntu 14.04

Reference: http://www.pyimagesearch.com/2016/11/14/installing-keras-with-tensorflow-backend/
step-by-step instructions to install Keras using a TensorFlow backend for machine learning.

Keras is simply a wrapper around more complex numerical computation engines such as TensorFlow and Theano.

When it comes to Keras you have two choices for a backend engine — either TensorFlow or Theano. Theano is older than TensorFlow and was originally the only choice when selecting a backend for Keras.

So why might you want to use TensorFlow over Theano?

The short version is that TensorFlow is extremely flexible, allowing you to deploy network computation to multiple CPUs, GPUs, servers, or even mobile systems without having to change a single line of code.

This makes TensorFlow an excellent choice for training distributed deep learning networks in an architecture agnostic way, something that Theano does not (currently) provide.

Installation:

  1. Use Python virtual environments.

    You can quit the virtualenv with command ‘deactivate’

    And go back the virtualenv with command ‘workon opencv_keras_tf’

    Check python version:

     
  2. Install TensorFlow
    NOTE: Read this about CUDA compute capability : http://stackoverflow.com/questions/10961476/what-are-the-differences-between-cuda-compute-capabilities
    IT SEEMS DEPEND ON THE HARDWARE! NOTHING CAN DO TO IMPROVE THE COMPUTE CAPABILITY!
    AFTER READING THIS https://www.tensorflow.org/versions/r0.10/get_started/os_setup#installing_from_sources AND http://stackoverflow.com/questions/38542763/how-can-i-make-tensorflow-run-on-a-gpu-with-capability-2-0, I GOT SAD NEWS THAT
    In order to build or run TensorFlow with GPU support, both NVIDIA’s Cuda Toolkit (>= 7.0) and cuDNN (>= v3) need to be installed.
    TensorFlow GPU support requires having a GPU card with NVidia Compute Capability >= 3.0.
    SO MY GPU GeForce GT 520M THAT ONLY HAS CUDA COMPUTE CAPABILITY 2.1 (REF: https://en.wikipedia.org/wiki/CUDA) CAN’T BE USED FOR TENSORFLOW!!!I ONLY CAN USE CPU!!!To install TensorFlow, refer to this page: https://www.tensorflow.org/versions/r0.11/get_started/os_setup.
    Currently I have CUDA 7.5 toolkit installed

    The tensorflow page need CUDA toolkit 8.0 and CuDNN v5. I already installed them. I go to ‘Pip installation’ and choose this binary option:

    SO let’s begin:

    Install TensorFlow:

    Test the installation

     
  3. Install Keras
    Install a few Python dependencies:
    Install numpy scify

    Install scikit-learn

    Install pillow

    Install h5py

    Install keras

    Then run ‘import keras’ in python console to create keras.json file (http://stackoverflow.com/questions/40310035/how-to-change-keras-backend-wheres-the-json-file)

    keras.json file would be created in ~/.keras/ (~/.keras/keras.json file)

    Specifically, you’ll want to ensure that image_dim_ordering  is set to tf  (indicating that the TensorFlow image dimension ordering is used rather than th  for Theano).

    You’ll also want to ensure that the backend  is properly set to tensorflow  (rather thantheano ).

  4. Symlink with OpenCV
    My opencv binding file for python 3 is in /usr/local/lib/python3.4/site-packages/cv2.cpython-34m.so. I need to symlink it with the virtualenv ‘opencv_keras_tf’ like this:
    Go into this directory:

    Then symlink it (HERE I CHANGE THE FILE TO ‘cv2.so’)

    Test it

    OK. NO ERROR

Phalcon Developer Tools on Linux

Reference: https://docs.phalconphp.com/en/latest/reference/linuxtools.html

Developer Tools
These tools are a collection of useful scripts to generate skeleton code. Core components of your application can be generated with a simple command, allowing you to easily develop applications using Phalcon.
Make sure the phalcon module already installed.

Installation of Phalcon Developer Tools for Linux:

  1. Clone the tools
  2. Go into the directory then execute ”. ./phalcon.sh”, (don’t forget the dot at beginning of the command):

    At the end I got an error “ERROR: Phalcon extension isn’t installed…”. This is may be because my php cli version (php version 7) is different with my default php (php version 5.6). From the previous article, I only install phalcon for php 5.6. So change the php version for cli (read again http://myprojects.advchaweb.com/index.php/2016/09/16/update-ppa-for-php/) like this:

    When I did the last error command, it’s working now

     
  3. Create a symbolink link to the phalcon.php script:

    I think ‘phalcon’ can be used from everywhere now. even I don’t need to execute this command anymore

    Here is the ‘phalcon’ command running at home directory:

     

Use Phalcon Developer Tools for Projects (ref: https://docs.phalconphp.com/en/latest/reference/tools.html):

  1. Create a project
    Note: To enable the web tools (for web GUI) , add the ‘–enable-webtools’ after the project name

    SO it just not ‘phalcon create-project store’
  2. Open it on your browser (http://localhost/works/phalcon/store/). But I got this error:

    From this forum: https://forum.phalconphp.com/discussion/15389/volt-directory-cant-be-written, I tried to modify the files permission to ‘664’

    Then refresh, got another error:

    Now try to modify to ‘777’.

    Then refresh again AND IT’S WORKING NOW (http://localhost/works/phalcon/store/)

    The web tools (make sure you create your project with the webtools enabled)
    Open it on your browser http://localhost/works/phalcon/store/public/webtools.php. If you get the display like thisIt means the css and js file can’t be loaded properly. From this link: https://forum.phalconphp.com/discussion/15111/webtools-can-not-load-css-if-using-different-baseuri, I need to modify /app/config/config.php and add ‘staticUri’ like this:

    Then refresh again your browser (http://localhost/works/phalcon/store/public/webtools.php), Here is the displayNOTE: I FOUND ONLY ‘controller’ COMMAND IS WORKING, BUT ‘model’ and ‘scaffold’ COMMANDS IS NOT WORKING! I ALSO TRIED THE COMMAND LIKE ‘phalcon model products’ AND IT DON’T WORK. I THINK THE PROBLEM IN THE DEV TOOLS! I put this issue in phalcon github (https://github.com/phalcon/phalcon-devtools/issues/976): Cannot create model via devtools but can create controller
    “I can create controller via the devtools (and webtools) but I can’t create model. Here is the command:

    $ phalcon model products

    The result:

    Phalcon DevTools (3.0.4)
    Error: Table “products” does not exist.

    I also can’t do it via webtools. I fill the form like the table name and click ‘Generate’. The weird thing happened. it said ‘Models were created successfully’ but I see nothing.

    I also found the url for the webtools is a bit weird (it’s working though). when I opened it the first time, the url is like this: http://localhost/works/phalcon/store/public/webtools.php
    but after i clicked the others links (do some stuff on controllers, models, system info, etc), the ‘/webtools.php/’ keep added and make the url longer, so it’d be like this: http://localhost/works/phalcon/store/public/webtools.php/webtools.php/webtools.php/webtools.php/webtools.php?_url=/controllers/list.

    Info:
    Phalcon DevTools Version: 3.0.4
    Phalcon Version: 3.0.3
    AdminLTE Version: 2.3.6
    OS: Linux teddy-K43SJ 4.4.0-62-generic #83 14.04.1-Ubuntu SMP Wed Jan 18 18:10:30 UTC 2017 x86_64
    PHP Version: 5.6.30-1+deb.sury.org~trusty+1
    PHP SAPI: apache2handler”
    I’M WAITING THE ANSWER!!!

    Test Phalcon (https://docs.phalconphp.com/en/latest/reference/tools.html)
    Generating Controllers

    The command “create-controller” generates controller skeleton structures. It’s important to invoke this command inside a directory that already has a Phalcon project.

    This is the content of /store/app/controllers/TestController.php

    Modify the above controller like this:

    Then open it on your browser: http://localhost/works/phalcon/store/test
    Result of the test controller:
    Create a new database ‘phalcon_store’ (via phpmyadmin)
    Preparing Database Settings
    When a project is generated using developer tools. A configuration file can be found in app/config/config.php (NOT config.ini file).

    To generate models or scaffold, you will need to change the settings used to connect to your database. I CAN’T USE DEVTOOL FOR CREATING MODEL LIKE I SAID ABOVE, SO I’LL DO IT MANUALLY! SO create a new file ‘Products.php’ in /app/models/ directory. I also added setter/getter methods

    SCAFFOLD ALSO SEEMS DONT WORK VIA DEVTOOLS!

    SO FOR SAVING TIME, I DOWNLOAD THE WORKING CODE FROM https://github.com/gsokolowski/ph-store. –> THE LOOKS STILL SAME WITH MINE. NO DIFFERENT. ONLY SHOW ‘Congratulation.
    HERE IS LOCAL PHALCON PROJECT WORKING: http://localhost/works/phalcon/invo. –>LEARN THIS!

    NOTES:
    I found when the first time the page is loaded (index.php in /public/ dir), it’d be referred to /app/views/index.volt. then content “{{ content }}” would be picked up from /app/views/index/index.volt. We can modify this file to change the frontend content

    Here is the looks (http://localhost/works/phalcon/store/)

     

Phalcon Compilation and Installation on Ubuntu 14.04

Reference: https://phalconphp.com/en/download
How To Install Phalcon PHP Framework on Ubuntu 14.10, 14.04 & 12.04
Phalcon is a C extension, so you need to download a binary for your platform or compile it from source code (SO INSTALL THE BINARY OR COMPILE! CHOOSE ONLY OF THEM!).
Installation on Ubuntu 14.04:

Install the binary (the easiest way but it don’t mean it’d be working!)

Install the package

SO the installation is failed! I got the above error. May be because Ubuntu 14.04 has not been supported yet (https://forum.phalconphp.com/discussion/6217/ubuntu-cant-install-phalcon). SO IT’S TIME TO COMPILE THE SOURCE!
But before installing the source, we need some required packages. Check those packages if they haven’t been installed in your machine. My ubuntu 14.04 already has ‘python-software-properties’, ‘software-properties-common’, ‘php5-dev’, ‘php5-mysql’, ‘gcc’ and ‘libpcre3-dev’. So now I just need to compile the phalcon source code:

  1. Clone the phalcon code
  2. Go into the ‘cphalcon/build’ directory

     
  3. then install

    OK. It takes a while to install it. It recommended to install apache web server.
  4. Then Create phalcon.ini file in /etc/php/5.6/mods-available/ directory (because I use php 5.6)

    Then type ‘extension=phalcon.so’ (WITHOUT QUOTE!)
    That mean we can use ‘phalcon’ in PHP 5.6 ONLY! TO enable the mod in the others php version, we can use the same method!
    No need to use command ‘sudo phpenmod phalcon’ anymore!
    NOTE: Somehow I can’t use this command instead of the above

    I also tried to write the extension directly in ‘/etc/php/5.6/apache2/php.ini’ but apache showed error when trying to restart it!
  5. Then restart the apache web server

    If there is no error, then check it on php_info()I CAN ALSO CHECK THE MODULES INSTALLED FROM COMMAND TERMINAL:

    SO COMPILATION AND INSTALLATION SUCCESS!
    TO TRY AND LEARN PHALCON DEEPER (CMS, BLOG, LOGIN, ETC), THIS IS A GOOD COMPILATION: https://github.com/sergeyklay/awesome-phalcon.

Removing Old Kernel of Ubuntu 14.04 Safely

References:  https://help.ubuntu.com/community/RemoveOldKernels
http://blog.dustinkirkland.com/2016/06/purge-old-kernels.html
http://www.webupd8.org/2016/07/how-to-safely-remove-old-linux-kernels.html

My current running kernel:

List of all kernel I have:

Oh man. My machine still keep the kernel 3.xx.xx. It’s already version 4.4.x now! I need to remove the old ones. I got this command ‘sudo purge-old-kernels’ can remove them. The website says:
“purge-old-kernels will remove old kernel and header packages from the system, freeing disk space. It will never remove the currently running kernel. By default, it will keep at least the latest 2 kernels, but the user can override that value using the –keep parameter. Any additional parameters will be passed directly to apt-get(8).”
But first update my system and install ‘bikeshed’

then run ‘sudo purge-old-kernels’ command! (NOTE: READ THE KERNELS LISTED FIRST BEFORE TYPING ‘Y’ TO DELETE THEM! BE CAREFUL! CREATE A BACKUP FIRST!!!)

THE LAST KERNEL WOULD BE REMOVED IS ‘4.4.0-59’. My current kernel version is ‘4.4.0-62’. IT SAID WOULD FREE MY DISK SPACE FOR 10.7 GB!!!
IF YOU SURE, TYPE ‘Y’. HERE IS THE LAST PROCESS I CAN CAPTURE

OK. NOW My disk space is 16.8GB FROM 3.5GB!
RUN UPDATE AFTER THE PROCESS IS FINISHED. RESTART IF NEEDED.

 

 

Installing Tesseract OCR on Ubuntu 14.04

Reference: https://github.com/tesseract-ocr/tesseract/wiki/Compiling
http://hanzratech.in/2015/01/16/ocr-using-tesseract-on-ubuntu-14-04.html

Compilation:

  1. clone the package from github
  2. Go to the new dir
  3. autogen
  4. configure

    Here i can’t configure it correctly because it always complained about leptonica 1.74

    I already did

    But the error still persist!
    SOLUTION: I HAVE TO COMPILE AND INSTALL LEPTONICA 1.74 MANUALLY (READ: http://myprojects.advchaweb.com/index.php/2017/02/02/installing-leptonica-1-74-1-on-ubuntu-14-04/)
    NOW IT SUCCESS!

     
  5. Since we have to compile leptonica to use version 1.74, we should use LDFLAGS=”-L/usr/local/lib” CFLAGS=”-I/usr/local/include” make instead of make for Tesseract.

     
  6. make install

     
  7. sudo ldconfig

     
  8. Make training

     
  9. Install the training

    For the training tutorial, pls read: https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract-4.00 (OR https://github.com/tesseract-ocr/tesseract/wiki/Training-Tesseract for older tesseract version). It says it use neural network-based recognition engine. ALSO “Tesseract 4.00 takes a few days to a couple of weeks. Even with all this new training data, you might find it inadequate for your particular problem, and therefore you are here wanting to retrain it.”. IT’D TAKE A FEW DAYS – WEEKS??? IT SEEMS SAME WITH TRAINING OPENCV. IF I HAVE PLENTY OF TIME I CAN DO THAT. ACTUALLY IT’S INTERESTING!
  10. For visual debugging, build ScrollView.jar

    Export ‘SCROLLVIEW_PATH’:

     

     

  11. Install Language
    For example to install english and many other files, pls see https://github.com/tesseract-ocr/tesseract/wiki/Data-Files. I downloaded english language https://sourceforge.net/projects/tesseract-ocr-alt/files/tesseract-ocr-3.02.eng.tar.gz/download.
    <OLD>Then extract the zip file ‘tesseract-ocr-3.02.eng.tar.gz’. then move all files in /tesseract-ocr/tessdata/ to /tesseract/tessdata/
    DONT FORGET TO POINT OUT ‘TESSDATA_PREFIX’!

    </OLD>
    <NEW>It’d be much better to copy/move the ‘tessdata’ directory into /usr/local/share/tessdata/ than copy/move them into /cpp/tesseract/tessdata/ above (the OLD> because we dont have to type ‘export TESSDATA_PREFIX…’ everytime we need to scan an image. I did this after did the old one

    </NEW>
    AT FIRST I FORGOT ABOUT THIS. WHEN I DID A TEST, HERE IS THE MESSAGE
  12. Check tesseract version (with -v or –version)

     
  13. Test!

    Here is the image source (‘phototest.tif’) And here is the result in /tesseract/output.txt

    NOTE : IT BETTER TO NOT USE FILENAME WITH HAS SPACE BECAUSE TESSERACT CAN’T FIND IT!
    ALSO USE IMAGE WITH HIGH RESOLUTION! OR WE CAN DO THE TRAINING STUFF (IF WE HAVE PLENTY OF TIME!!!)
    OTHER TESTS

    BUT I FOUND THE RESULT STILL NOT GOOD!!! MANY WEIRD CHARS, SPELLING MISTAKES,ETC
    ANOTHER TEST WITH COMMAND TERMINAL:

    Display the result in the terminal:

    open the original image so we can compare it

     
  14. Question: Can we use tesseract to read/scan pdf file?
    pls read: http://kiirani.com/2013/03/22/tesseract-pdf.html
    http://www.barryhubbard.com/linux/converting-pdf-to-text-using-tesseract/
    http://stackoverflow.com/questions/30925218/converting-a-pdf-to-text-using-tesseract-ocr
    TESSERACT CAN’T DO THIS DIRECTLY. IT SAID TO CONVERT THE PDF TO TIFF IMAGE FIRST! ALSO THE MULTI PAGE PDF NEED TO BE CONVERTED TO MULTI TIFF FILES! READ http://www.barryhubbard.com/linux/converting-pdf-to-text-using-tesseract/ TO SEE THE SCRIPT TO DO THAT!

Installing Leptonica 1.74.1 on Ubuntu 14.04

Reference: http://hanzratech.in/2015/01/16/ocr-using-tesseract-on-ubuntu-14-04.html
http://www.leptonica.org/download.html

  1. Download the newest leptonica version (1.74.1) here : http://www.leptonica.org/source/leptonica-1.74.1.tar.gz
    I use wget:


     
  2. Extract the zip file
  3. Go to the new created directory (leptonica-1.74.1) then configure

     
  4. make

     
  5. Because my machine didn’t have ‘checkinstall’, install it first

     
  6. Create the package with ‘checkinstall’

     
  7. Then execute ‘sudo ldconfig’