Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Wednesday, 10 August 2016

Ubuntu - ReactJS with Hot Loader Installation

Hi there,

This is an example for ReactJS with Hot Loader:

  1. You must have NodeJS installed:
    • https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
  2. Running these commands:
    • npm init
    • npm install -S express lodash react react-dom
    • npm install babel-core babel-loader babel-preset-es2015 babel-preset-react react-hot-loader webpack webpack-dev-server --save-dev
    • npm install -g webpack webpack-dev-server
  3. Create webpack-dev-server global command in case it not works:
    • Create bash file bash.sh:
      • #!/bin/bash
        
        path=$(readlink -f .)
        path="$path/node_modules/.bin/webpack-dev-server"
        
        sudo ln -s $path /usr/local/bin
        echo "DONE!";
        
    • sudo bash.sh
  4. Create webpack.config.js file:
    • var webpack = require('webpack');
      var path = require('path');
      
      module.exports = {
          devtool: 'inline-source-map',
          entry: [
              'webpack-dev-server/client?http://127.0.0.1:8080/',
              'webpack/hot/only-dev-server',
              './src'
          ],
          output: {
              path: path.join(__dirname, 'public/build'),
              filename: 'bundle.js',
              sourceMapFilename: 'bundle.map',
              publicPath: '/'
          },
          resolve: {
              modulesDirectories: ['node_modules', 'src'],
              extensions: ['', '.js']
          },
          module: {
              loaders: [
              {
                  test: /\.jsx?$/,
                  exclude: /node_modules/,
                  loaders: ['react-hot', 'babel?presets[]=react,presets[]=es2015']
              }
              ]
          },
          plugins: [
              new webpack.HotModuleReplacementPlugin(),
              new webpack.NoErrorsPlugin()
          ],
          devServer: {
              contentBase: "./public",
              hot: true
          }
      };
      
  5. Create index.html file:
    • <html>
          <head>
              <title>React</title>
          </head>
          <body>
              <div id="app"></div>
      
              <script src="build/bundle.js"></script>
          </body>
      </html>
      
  6. Create index.js file:
    • import React from 'react';
      import { render } from 'react-dom';
      import App from 'components/app';
      
      render(<App />, document.getElementById('app'));
      
  7. Create app.js file:
    • import React from 'react';
      
      export default class App extends React.Component {
          render() {
              return (
                  <div>
                      <h1>Hello world!</h1>
                  </div>
              );
          }
      }
      
  8. At the end, you might have a directory tree like this:
  9. Rebuild:
    • webpack
  10. Run server:
    • webpack-dev-server
    • or
    • node_modules/.bin/webpack-dev-server
  11. Open web browser:
    • http://localhost:8080/

Good luck!

Thursday, 4 August 2016

Magento - Installation

Hello,

I got these issues when trying to setup Magento in my local machine using Nginx:
  1. Magento 2.x:
    •  Cannot instantiate interface
      • FastCGI sent in stderr: "PHP message: PHP Fatal error:  Cannot instantiate interface Magento\Framework\App\Config\Scope\ReaderPoolInterface in /xxx/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php on line 73" while reading response header from upstream, client: 127.0.0.1, server: my-magento.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php5.6-fpm.sock:", host: "my-magento.com"
      • Modify the sample nginx config file you have been included in your virtual host:
        • From:
          • location ~* ^/setup($|/) {
        • To:
          • location /setup {
    • security.limit_extensions
      • "Access to the script '/xxx/setup/index.php/session/prolong' has been denied (see security.limit_extensions)"
        • Change
          • cgi.fix_pathinfo=0
        • To:
          • cgi.fix_pathinfo=1
  2. Magento 1.x:
    • Nginx:
      • Virtual host file:
        • location ~ .php/ {
           rewrite ^(.*.php)/ $1 last;
          }
          

Good luck!

Wednesday, 3 August 2016

Ubuntu - Swap between PHP 5.5, 5.6 and 7.0

Hello,

This is tutorial how we can do it:
  1. Install PHP 5.5:
    • sudo apt-get install -y php5
  2. Install PHP 5.6:
    • sudo add-apt-repository ppa:ondrej/php
      • In some case, you will need to change Ubuntu codename in this file:
        • sudo vim /etc/apt/sources.list.d/ondrej-ubuntu-php-xenial.list
    •  sudo apt-get update
    • sudo apt-get install -y php5.6
  3. Install PHP 7.0:
    • sudo apt-get install -y php7.0
  4.   Create symlink in your .bashrc file for quick access:
    • vim ~/.bashrc
    • Apache2:
      • #################################################
        ############### PHP Version Toggle ##############
        #################################################
        # Remove the -q to see debugging information if there are problems
        alias enphp5.5="
         sudo a2dismod php5.6 -q;
         sudo a2dismod php7.0 -q;
         sudo a2enmod php5 -q;
         sudo ln -sf /usr/bin/php5 /usr/bin/php;
         sudo service apache2 restart"
        alias enphp5.6="
         sudo a2dismod php5 -q;
         sudo a2dismod php7.0 -q;
         sudo a2enmod php5.6 -q;
         sudo ln -sf /usr/bin/php5.6 /usr/bin/php;
         sudo service apache2 restart"
        alias enphp7.0="
         sudo a2dismod php5 -q;
         sudo a2dismod php5.6 -q;
         sudo a2enmod php7.0 -q;
         sudo ln -sf /usr/bin/php7.0 /usr/bin/php;
         sudo service apache2 restart"
        
    • Nginx:
      • Remove apache2:
        • sudo service apache2 stop
        • sudo apt-get remove apache2*
        • sudo apt-get purge apache2
      • Install php-fpm for all versions
        • sudo apt-get install php5-fpm
        • sudo apt-get install php5.6-fpm
        • sudo apt-get install php7.0-fpm
      • Stop all php-fpm:
        • sudo service php5-fpm stop
        • sudo service php5.6-fpm stop
        • sudo service php7.0-fpm stop
      • #################################################
        ############### PHP Version Toggle ##############
        #################################################
        # Remove the -q to see debugging information if there are problems
        alias enphp5.5="
         sudo ln -sf /usr/bin/php5 /usr/bin/php;
         sudo service php5.6-fpm stop;
         sudo service php7.0-fpm stop;
         sudo service php5-fpm start;
         sudo find /etc/nginx/sites-available -type f -exec sed -i 's,/run/php/php5.6-fpm.sock,/var/run/php5-fpm.sock,g;s,/run/php/php7.0-fpm.sock,/var/run/php5-fpm.sock,g' {} \;
         sudo service nginx restart"
        alias enphp5.6="
         sudo ln -sf /usr/bin/php5.6 /usr/bin/php;
         sudo service php5-fpm stop;
         sudo service php7.0-fpm stop;
         sudo service php5.6-fpm start;
         sudo find /etc/nginx/sites-available -type f -exec sed -i 's,/var/run/php5-fpm.sock,/run/php/php5.6-fpm.sock,g;s,/run/php/php7.0-fpm.sock,/run/php/php5.6-fpm.sock,g' {} \;
         sudo service nginx restart"
        alias enphp7.0="
         sudo ln -sf /usr/bin/php7.0 /usr/bin/php;
         sudo service php5-fpm stop;
         sudo service php5.6-fpm stop;
         sudo service php7.0-fpm start;
         sudo find /etc/nginx/sites-available -type f -exec sed -i 's,/var/run/php5-fpm.sock,/run/php/php7.0-fpm.sock,g;s,/run/php/php5.6-fpm.sock,/run/php/php7.0-fpm.sock,' {} \;
         sudo service nginx restart"
        
  5. Reload your new .bashrc commands:
    • source ~/.bashrc
  6. Done, now you can try it with:
    • enphp5.5
    • php -v
    • enphp5.6
    • php -v
    • enphp7.0
    • php -v

Good luck!
Source: https://github.com/JREAM/phalcon-xenial

Sunday, 20 December 2015

Restoring Large MySQL Dump

Hello,

This is tutorial how to restore your Database:
  1. Create dump file:
    • mysqldump -uroot -ppassword dbname > dbname_backup.sql
  2. Split dump file:
    • mkdir splits
    • split -n 1000 dbname_backup.sql splits/sql
  3. Create new database: dbname_clone
  4. Restore database:
    • cd splits
    • cat sql* | mysql -uroot -ppassword dbname_clone
Good luck!

Tuesday, 26 May 2015

Ubuntu - Google Translate CLI

Hello,

This is tutorial how to install:
  1. sudo apt-get install gawk wget
  2. sudo apt-get install konwert
  3. git clone https://github.com/soimort/translate-shell
    • cd translate-shell
    • sudo make install
  4. Test:
    • trans -b 'Saluton, Mondo!'
    • trans :fr word

Some issue you might facing:
  1. [WARNING] Your locale codeset (en_US:en) is not UTF-8.
    • sudo locale-gen en_US en_US.UTF-8
    • dpkg-reconfigure locales

Good luck!

Sunday, 27 July 2014

Ubuntu - SSHFS scripts

Hello,

This is small script for mount and unmount directory from your server:
  • Create script:
    • mkdir server
    • vim mount-server.sh
      • #!/bin/bash
        
        ACTION=$1
        
        if [ "$ACTION" == "mount" ]; then
            sshfs -o "IdentityFile=~/Desktop/Public-Key.pem" ubuntu@xxx.xxx.xxx.xxx:/home/web/ ~/www/server/
            echo "Mounted!"
        else
            fusermount -u server
            echo "Unmounted!"
        fi
    • chmod +x mount-server.sh
  • Usage:
    • Mount: ./mount-server.sh mount
    • Unmount: ./mount-server.sh unmount
  • Check server folder

Good luck!

Sunday, 8 December 2013

Ubuntu - Squid Proxy Server

Hi,

There are some steps to install Squid Proxy Server:
  1. Install Squid:
    • sudo apt-get install squid
  2. Backup "squid.conf" file:
    • sudo cp /etc/squid3/squid.conf /etc/squid3/squid.conf.original
    • sudo chmod a-w /etc/squid3/squid.conf.original
  3. Open "/etc/squid3/squid.conf":
    • Find "visible_hostname" and change to your own name:
      • visible_hostname ubuntu
    • Change port:
      • http_port 8888
    • Allow all computers can access:
      • acl
        • acl manager proto cache_object
        • acl localhost src 127.0.0.1/32 ::1
        • acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
        • acl allcomputers src 192.168.1.0/255.255.255.0
      • http_access
        • http_access allow localhost
        • http_access allow allcomputers
  4. View log:
    • more /var/log/squid3/access.log

Good luck!

Sunday, 15 September 2013

Ubuntu - Secure

Hi,

There are some things you need you take care for your secure:
  1. fail2ban
    • http://www.servermom.com/how-to-install-fail2ban-to-protect-server-from-brute-force-ssh-login-attempts-ubuntu/370/
  2. Generate SSH Public Key
    1. Your computer
      • cd .ssh
      • ssh-keygen -t dsa
        • Enter file in which to save the key (/home/shin/.ssh/id_dsa): your-name
        • Enter passphrase (empty for no passphrase): your-hard-password
        • Enter same passphrase again: re-type-your-hard-password
      • We have your-name.pub file in .ssh folder, and copy it to your-server
        • scp your-name.pub your-server-username@your-server:./your-name.pub
        • scp your-name.pub your-server-username@your-server:./your-name.pub
        • --OR--
        • scp -P[port] your-name.pub your-server-username@your-server:./your-name.pub
          • E.G.:
            • my.pub my@server:./my.pub
            • my.pub my@server:./my.pub
            • my.pub -P22 my@server:./my.pub
              • Type your password on your server
    2. Your server
      1. touch .ssh/authorized_keys
      2. sudo chmod 600 .ssh/authorized_keys
      3. cat your-name.pub >> .ssh/authorized_keys
      4. rm your-name.pub
  3. Try to access your-server using SSH Public Keys
    • ssh your-server-username@your-server
      • Type your-password when create your-name.pub file
  4. Limit users can not access your-server using ssh
    • sudo vim /etc/ssh/sshd_config
      • AllowUsers <user1> <user2>

Good luck!

Tuesday, 7 May 2013

Grails - Installation

There are tutorial how to install Grails:

  1. Install Java:
  2. Install Groovy/Grails Tool Suite IDE:
    • http://www.springsource.org/downloads/sts-ggts
      • http://download.springsource.com/release/STS/3.2.0/dist/e4.2/spring-tool-suite-3.2.0.RELEASE-e4.2.2-linux-gtk-x86_64-installer.sh
      • ./spring-tool-suite-3.2.0.RELEASE-e4.2.2-linux-gtk-x86_64-installer.sh
  3. Set environment variable:
    • vim ~/.bashrc
      • export GRAILS_HOME=/path/to/springsource/grails-2.2.1
      • export PATH="$PATH:$GRAILS_HOME/bin"
        • /path/to/springsource/grails-2.2.1: after install Groovy/Grails Tool Suite IDE you will get application folder like this.
    • Save file and reboot, try test it by this command:
      • grails -version
Good luck!

Friday, 29 March 2013

SSL - Installation

Hi,

There are some tutorial how to install SSL in your server:
  1. Lighttpd:
    1. Create ssl folder in your server
    2. Create CSR file in your server: https://developers.google.com/search-appliance/kb/secure/external-ssl
      • Do not using special characters in your information input to your CSR file: # $ % @...
    3. Using the CSR file for buying a SSL service. After buying, you should received 2 or maybe 3 files, download and store it in your ssl folder:
      • Web Server CERTIFICATE: your-site.crt
        • -----BEGIN CERTIFICATE-----
          -----END CERTIFICATE-----
      • INTERMEDIATE CA: intermediate.crt
        • -----BEGIN CERTIFICATE-----
          -----END CERTIFICATE-----
    4. Create your pem file:
      • cat your-site.key your-site.crt > your-site.pem
    5. This is an example config file:
      • $HTTP["host"] == "your-site" {
            server.document-root = "/path/to/your/project"

            $SERVER["socket"] == ":443" {
                ssl.engine  = "enable"
                ssl.pemfile = "/path/to/your/pem/file"
                ssl.ca-file = "/path/to/your/intermediate/file"
            }
        }
    6. Auto redirect all site to HTTPS:
      • $SERVER["socket"] == ":80" {
            $HTTP["host"] =~ "(.*)" {
                url.redirect = ( "^/(.*)" => "https://%1/$1" )
            }
        }
    7. Restart Webserver and test in your browser: https://your-site
      • Amazon Server: you must enable security group HTTPS first
  2. Apache:

Good luck!

Wednesday, 20 March 2013

Ubuntu - perl: warning: Setting locale failed


Hi,

You can simply fixed it like:
  • perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LANG = “en_US.utf8
    are supported and installed on your system.
    perl: warning: Falling back to the standard locale (“C”).
  • export LANGUAGE=en_US.UTF-8
    export LANG=en_US.UTF-8
    export LC_ALL=en_US.UTF-8
    locale-gen en_US.UTF-8
    apt-get install locales
    dpkg-reconfigure locales

Good luck!

Friday, 8 March 2013

VirtualBox - Tricks

Hi,

There are some tricks when using VirtualBox:
  1. Get IP of VirtualBox:
    1. Using Bridged Adapter
    2. Create Host-only Networks:
      • Preferences -> Network
      • Add host-only network
      • Choose a virtual host -> Setting
      • Choose Network tab
      • Attached to: Host-only Adapter
      • Chose Name to your host-only network created
      • Ok
    3. Run VirtualBox and get there IP
  2. Share
Good luck!

Wednesday, 12 December 2012

Firefox - Downgrade

Hi,
There is tutorial how to downgrade your Firefox:
  1. Download version you would like:
    • http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/
  2. Following commands:
    • tar xjf firefox-xx.xx.xx.tar.bz2
    • sudo mv firefox /usr/lib/firefox-xx.xx.xx
    • sudo mv /usr/bin/firefox /usr/bin/firefox-old
    • ln -s /usr/lib/firefox-xx.xx.xx/firefox /usr/bin/firefox
      • If your new firefox can not run, do this thing:
        • cd firefox
        • mv firefox-bin firefox.sh
  3. Disabled automatic updating:
    • Edit -> Preferences -> Update
    • Checked: "Nerver check for updates (not recommended: security risk)
Now when you open Firefox it should be expected version instead of current version.
Good luck!

Thursday, 8 November 2012

Atlassian Bamboo - Installation

Hi,
  1. Install:
    1. Download latest package here:
      • http://www.atlassian.com/software/bamboo/download
    2. Install Java:
    3. Install Ant:
      • Install:
        • sudo apt-get install ant
      • Create Ant Executable:


      • Tricks:
        • Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar
          • Checking your tools.jar file:
            • locate tools.jar
            • /usr/lib/jvm/java-6-openjdk-amd64/lib/tools.jar
          • If not exist, try install:
            • sudo apt-get install openjdk-6-jdk
    4. Install PHPUnit:
      • http://shinphp.blogspot.com/2012/10/ubuntu-phpunit.html
      • Create PHPUnit Executable:


  2. Tricks:
    1. Can not use sshexc
      • sudo apt-get install libjsch-java
      • sudo ln -s /usr/share/java/jsch.jar /usr/share/ant/lib/

Good luck!

Friday, 2 November 2012

Java - Installation

Hi,

This is tutorial how to install java:
  1. Install:
    • sudo apt-get install openjdk-6-jdk
  2. vim ~/.bashrc
    • Normal:
      • export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64/jre
    • For Grails:
      • export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
    • export JDK_HOME=/usr/lib/jvm/java-6-openjdk-amd64
    • export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
      • /usr/lib/jvm/java-6-openjdk-amd64/jre: find it correctly in your system
  3. Save file and reboot, try test it by this command:
    • echo $JAVA_HOME
    • java -version
Good luck!

Friday, 12 October 2012

PHPUnit & Xdebug - Installation

Hi,

Default packages:
  1. Ubuntu:
    • sudo apt-get install php5-dev php-pear
    • sudo apt-get install php5-xdebug php5-dev
    • sudo apt-get install php-pear
    • sudo pear channel-discover pear.phpunit.de
    • sudo pear channel-discover components.ez.no
    • sudo pear channel-discover pear.symfony-project.com
    • sudo pear channel-discover pear.symfony.com
    • sudo pear update-channels
    • Uncomment of added in "/etc/php5/cli/php.ini":
      • include_path = ".:/usr/share/php"
  2. Centos:
    • yum install php-pear
    • yum install php-dom
    • yum install php-devel gcc
    • pear channel-discover pear.phpunit.de
    • pear channel-discover pear.symfony-project.com
    • pear channel-discover pear.symfony.com
    • pear channel-discover components.ez.no
    • pecl install xdebug
    • Added new file "/etc/php.d/xdebug.ini":
      • zend_extension=/usr/lib64/php/modules/xdebug.so
        • --OR--
      • extension=xdebug.so
    • Uncomment of added in "/etc/php.ini":
      • include_path = ".:/php/includes:/usr/share/pear:/usr/share/php"

Install latest PHPUnit:
  1. Ubuntu:
    • sudo apt-get remove phpunit
    • sudo pear install -a phpunit/PHPUnit
      • Testing: phpunit --version
  2. Centos:
    • pear install --alldeps phpunit/PHPUnit
      • Testing: phpunit --version

Downgrade current PHPUnit to 3.5.15:
  1. Uninstall current PHPUnit:
    • sudo pear uninstall phpunit/PHPUnit
    • sudo pear uninstall phpunit/DbUnit
    • sudo pear uninstall phpunit/PHP_CodeCoverage
    • sudo pear uninstall phpunit/File_Iterator
    • sudo pear uninstall phpunit/PHPUnit_MockObject
    • sudo pear uninstall phpunit/Text_Template
    • sudo pear uninstall phpunit/PHP_Invoker
    • sudo pear uninstall phpunit/PHP_TokenStream
    • sudo pear uninstall phpunit/PHP_Timer
    • sudo pear uninstall phpunit/PHPUnit_Selenium
    • sudo pear uninstall pear.symfony-project.com/YAML
  2. Install PHPUnit 3.5.15:
    • sudo pear clear-cache
    • sudo pear install pear.symfony-project.com/YAML-1.0.2
    • sudo pear install phpunit/PHPUnit_Selenium-1.0.1
    • sudo pear install phpunit/Text_Template-1.0.0
    • sudo pear install phpunit/PHPUnit_MockObject-1.0.3
    • sudo pear install phpunit/PHP_Timer-1.0.0
    • sudo pear install phpunit/File_Iterator-1.2.3
    • sudo pear install phpunit/PHP_TokenStream-1.0.1
    • sudo pear install phpunit/PHP_CodeCoverage-1.0.2
    • sudo pear install phpunit/DbUnit-1.0.0
    • sudo pear install phpunit/PHPUnit-3.5.15

Good luck!

Tuesday, 2 October 2012

Ubuntu - Set Default Priority for all Processes for a Specific User


Hi,
This thing will help you can ssh to server if it attach by DDoS:
  1. Assuming that we have sufficient memory:
    • sudo vi /etc/security/limits.conf
  2. The configuration syntax is as follow:
    • [username] [hard|soft] priority [nice value]
  3. Insert the following line:
    • www-data hard priority 10
      • priority: -20 - 10
  4. Now, reboot the server.
  5. To verify that you've done it correctly, run top or htop:
    • Check NI column and check a number

Good luck!

Wednesday, 26 September 2012

Apache2


Hi,
  1. Ubuntu:
    • Install:
      • sudo apt-get install apache2
      • sudo apt-get install libapache2-mod-php5
      • Enable rewrite module:
        • sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enable/rewrite.load
    • Reinstall:
      • sudo aptitude: search apache2 and remove all package
      • sudo dpkg --get-selections | grep apache
      • sudo apt-get remove --purge apache2 apache2-mpm-worker
      • apache2-threaded-dev apache2-utils apache2.2-common
      • sudo apt-get install apache2 libapache2-mod-python libapache2-mod-wsgi \ libapache2-mod-python-doc
    • Tricks:
      • Could not reliably determine the server's fully qualified domain name:
        • Add this line in to file "sudo vim /etc/apache2/httpd.conf"
          • ServerName localhost
        • Restart apache
      • Change request by client:
        • sudo vim /etc/apache2/apache2.conf
        • MaxClients your-request-number
      • Piped logging into PHP file:
        • CustomLog "| /usr/bin/php /var/www/log.php 2> /home/www-data/error" combined
  2. Centos:
    • Install:
      • yum install php
      • yum install httpd
    • Reinstall:
    • Tricks:
      • Could not reliably determine the server's fully quilified domain name, using 127.0.0.1 ServerName
        • Add this line in to file "sudo vim /etc/httpd/conf/httpd.conf"
          • ServerName 127.0.0.1
        • Restart apache
      • Adding virtual host:
        • You must store data from /var/www

Good luck!

Friday, 31 August 2012

Ubuntu - Converting libraries

Hi,

These are plugin we need for ubuntu:
  1. sudo apt-get install html2text
  2. sudo apt-get install poppler-utils
  3. sudo apt-get install antiword
  4. sudo apt-get install python-excelerator

Using command line to convert:
  1. html2text test.html > html.txt
  2. pdftotext test.pdf pdf.txt
  3. antiword -m UTF-8.txt -t test.doc > doc.txt
  4. py_xls2txt test.xls > excel.txt

Good luck!

Friday, 2 March 2012

Ubuntu - Google Chrome can not be run as root

Hi,


This is easy to fix:

  • sudo vim /opt/google/chrome/chrome
  • Find string: "geteuid"
  • Replace with string: "getppid"
  • Done!

Good luck!