setting IPTables

sudo iptables -I INPUT -p tcp –dport [Port] -j ACCEPT

service iptables restart

service ip6tables restart

Advertisements

Having trouble starting/restarting httpd (apache)

do you have trouble like this?

 

[root@mail ~]# sudo service httpd start
Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:8888
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:8888
no listening sockets available, shutting down
Unable to open logs

 

You’ve most likely got SELinux enabled and in “enforcing” mode.

You can disable it with:

sudo setenforce 0

You can then start apache as normal with

sudo service httpd start

If you want to disable SELinux permanently, edit /etc/selinux/config and change SELINUX=enforcing to SELINUX=disabled

If you want to continue using SELinux, you’ll need to fix your config by adding access to the port, with something along the lines of

sudo semanage port -a -t http_port_t -p tcp 8888 <- tentative

Uploading multiple files with Phalcon PHP and HTML5.

First of all, if you just fell here and don’t know what Phalcon is, I recommend you to first take a ride at its website, or documentation. If you feel ready or already knew it, then we can go on.

Note: if you want the tl;dr version you can go down the page, download the whole project and see the code by yourself.

Note²: my goal here is just show the simplest way to implement a multiple file upload system using Phalcon, so don’t expect to see security rules such as file size limiters, file extension filtering, upload bot blocking, etc.

For this example we will be using the native HTML5 multiple attribute for file inputs, which according to CanIUse, its suported by: IE10+, Chrome, Firefox, Safari 7+, iOS 5+, and Android 4.4+.

So, first of all lets create a new Phalcon project (you can create it manually or using Phalcon Dev Tools, which I highly recommend you to use, you can find more about it here).

Using Dev Tools we can simply use this command to create all Phalcon project structure and files automatically:

$ phalcon project multiple-uploader-example

Where “multiple-uploader-example” is the name you want to give to our project.

Ok, so now we have our fresh created project which will have an structure like this:

Dat Sublime Text 2 Theme…

See these green arrows pointing to IndexController.php and index.volt? These are the only files we will be working at.

Also, we need to create a folder that we will call temp inside public’s folder which will receive the uploaded files:

Ok, so now we need to create a form in the view (index.volt) to send our images, it will be something like this:

<form action=”index/upload” method=”post” enctype=”multipart/form-data”>
 <input type=”file” name=”files[]” multiple>
 <input type=”submit” value=”Send File(s)”>
</form>

The form itself is pretty common, the magic happens when we add the multiple attribute and the brackets in input’s name, now our input supports multiple files. Also, as you can see, the action is leading to index/upload which we will be coding bellow.

In our IndexController.php we now need to handle the upload action, checking if there is any file sent, and handling them properly.

Our yet untouchable IndexController.php is probably looking like this:

class IndexController extends ControllerBase
{
 public function indexAction()
 {
 }
}

You can see that there is already a function which responds to /index actions which is empty, now we need to create the one that will handle /index/upload. To do this we will create another action:

class IndexController extends ControllerBase
{
 public function indexAction()
 {
 }
 
 public function uploadAction()
 {
 }
}

And then put the code which will handle the uploaded files:

#check if there is any file
if($this->request->hasFiles() == true){
 $uploads = $this->request->getUploadedFiles();
 $isUploaded = false;
 #do a loop to handle each file individually
 foreach($uploads as $upload){
 #define a “unique” name and a path to where our file must go
 $path = ‘temp/’.md5(uniqid(rand(), true)).’-’.strtolower($upload->getname());
 #move the file and simultaneously check if everything was ok
 ($upload->moveTo($path)) ? $isUploaded = true : $isUploaded = false;
 }
 #if any file couldn’t be moved, then throw an message
 ($isUploaded) ? die(‘Files successfully uploaded.’) : die(‘Some error ocurred.’);
}else{
 #if no files were sent, throw a message warning user
 die(‘You must choose at least one file to send. Please try again.’);
}

Kind of fuzzy eh? As Medium don’t support syntax highlight (yet! I hope) I think that a image of the whole controller would become handy and easier to understand:

This image is the code above in any editor with syntax highlight

Aaand this is it! Now all you need to do is run your project in a browser (in an apache environment with phalcon installed, obviously) and see the magic happens!


If you want to see what we just created here, you can download the example project here (watch out, its a .rar file, it may contain viruses that will eat you brain inside out while singing shitty pop songs).


If you got stuck somewhere or have any doubts you can always leave a comment in the part you are having troubles. →

And a good week for everyone. ☺

Raw SQL Query PhalconPHP

Phalcon is a high perfomance PHP framework based on MVC pattern.  Phalcon has good performance in handle many request/second compared to other PHP framework, such as : Laravel, Zend, Code Igniter, and Kohana.

This tutorial will show you how to call raw SQL query for insert,update,select, and delete in Phalcon PHP Framework.

1. Select

This example shows you how to call raw select from Phalcon controller class.

1
2
3
4
5
6
7
8
9
public function selectAction()
{
    $result=$this->db->query("SELECT employee_id,employee_name FROM employee order by employee_id desc");
                        
    while($row=$result->fetchArray())
    {
        echo $row['employee_id']." ".$row['employee_name']."<br>";
    }
}

 

2. Insert

This example shows you how to call raw insert from Phalcon controller class.

1
2
3
4
5
6
7
8
public function insertAction()
{
    $success=$this->db->execute("INSERT INTO employee (employee_id,employee_name)
                            VALUES ('14','Aditya Nugraha')");
                        
    if($success)echo "Success!!";
    else echo "Failed!!";
}

 

3. Update

This example shows you how to call raw update from Phalcon controller class.

1
2
3
4
5
6
7
8
9
10
11
12
public function updateAction()
{
    $success=$this->db->execute("UPDATE employee SET employee_name='Aditya'
                                WHERE employee_id='14'");
                        
    if($success)
    {
        $updatedCount=$this->db->affectedRows();
        echo $updatedCount." rows updated";
    }
    else echo "Failed!!";
}

 

4. Delete

This example shows you how to call raw delete from Phalcon controller class.

1
2
3
4
5
6
7
8
9
10
11
12
public function deleteAction()
{
    $success=$this->db->execute("DELETE FROM employee
                                WHERE employee_id='14'");
                        
    if($success)
    {
        $updatedCount=$this->db->affectedRows();
        echo $updatedCount." rows deleted";
    }
    else echo "Failed!!";
}

Cara Upload Project ke Github Melalui CMD

Upload File ke Github

1. Pertama yang harus kalian lakukan adalah mendaftar akun Github terlebih dahulu. Prosesnya terbilang mudah 3 Step untuk bisa membuat akun di Github.

Disini https://github.com/

2.   Setelah berhasil di buat akun Githubnya. Lihat pada pojok kanan atas pilih tanda + samping gambar profil Github kalian. Lalu pilih New repository.

New repository Github

3. Lalu pada bagian Create a new repository . Kalian bisa isikan  Nama Repository di kolom bagian atas. Lalu bagian bawah (optional) kalian bisa mengisikan deskripsinya. Setting ke Public , jika sudah pilih tombol Create Repository yang bewarna hijau. 

Create Repository Github




4.   Jika sudah Copykan alamat atau url repository gitnya. Alamat ini akan kita gunakan untuk tempat meremote folder atau file kita di Github.

alamat atau url Github remote

5. Sekarang kembali ke Command Prompt atau Git Bash, masuk ke dalam folder dan file sebelumnya
( folder : belajargit file : latihan1.txt).

6. Lalu ketikan perintah git config

git config adalah suatu perintah untuk mengkonfigurasi username,  dan alamat email Github kita agar tersimpan di dalam Command Line.

 

git config cmd Windows
git config

git config –global user.name “username Github”
git config –global user.email “alamat email Github”


7.  Kemudian ketikan perintah  git init

8. Sekarang kita akan coba tambahkan 3 file tambahan. Ketikan git add * 

9.  Jika di artikel sebelumnya kita sudah menambahkan commit , sekarang kita tambahkan lagi yaitu dengan mengetikan.

 git commit –m “Upload di Github”

10.  Setelah itu kita akan meremote ke alamat , atau url repository git yang sudah kita copykan tadi.

git remote adalah perintah untuk tempat meremote folder atau file kita sebelumnya yang sudah terinisiaisasi Git, yang tersimpan di local (Komputer kita ) ke server atau tempat repository (Github)

Ketikan perintah :

git remote add origin <alamat git kalian>

//origin adalah nama remote yang telah kita tambahkan
//jika kalian ingin mengubah url remote atau mensetting kembali remote kalian bisa mengetikan perintah :
git remote set-url origin <alamat git>

git remote cmd windows
git remote

11. Lalu ketikan

 git pull origin master.

 

git pull digunakan untuk menarik atau nama lain dari mengunduh,  beberapa file di dalam project yang tersimpan di repository (server),  ke dalam tempat penyimpanan Komputer kita (local).

 

Biasanya ini digunakan untuk suatu project yang dikerjakan atau dikembangkan lebih dari satu orang (kolaboratif) , dan kita mengambil beberapa file yang telah di kerjakan oleh orang tersebut. Jadi ketika ada perubahan dan penambahan file di server atau repository Github, kalian harus menggunakan git pull terlebih dahulu sebelum mempush (git push).

 

12. Terakhir kita ketikan.

 git push origin master

git push digunakan untuk mengupload atau menyimpan,  beberapa file di dalam project dari  tempat penyimpanan Komputer kita (local) , ke dalam project yang tersimpan di repository (server).

Tapi tunggu dulu jika kalian memiliki kegagalan saat mempush  , atau kendala erorr dan server (Github) menolak project  kita seperti pada gambar dibawah:

git push error cmd Windows
git push error

Tenang kalian bisa mencari solusinya di forum diskusi tanya jawab.

Disini : StackOverflow.com

atau kalian bisa ketikan perintah berikut :

git reset –mixed origin/master
git add .
git commit -m “Upload Github Lagi”
git push origin master

 Jika berhasil maka tampilanya akan seperti ini :

git push sukses cmd Windows
git push sukses

Nah sekarang kita lihat ke akun github kita, Jika tampilanya seperti gambar dibawah. Maka project kita telah sukses di upload atau disimpan ke server (Repository) Github.

project sukses tersimpan atau terupload di Github
Oh ya kalian juga dapat mengkloning atau mendownload,  project Github kalian atau orang lain  lewat Command Line dengan perintah:

git clone <alamat git>

git clone alamat git
git clone

Tambahan jika kalian ingin melakukan perubahan atau penambahan :

  • 1. Jadi intinya gini jika kita ingin menambahkan folder ( harus berisi file ) atau file baru dan perubahan pada beberapa file ,kita bisa menampilkan status folder atau file tersebut dengan perintah: git status.
  • 2. Nah ketika status folder atau file tersebut terlihat maka akan di tandai dengan warna merah. Artinya folder atau file dalam mode (unstaged) belum di daftarkan ke system Git.
  • 3. Selanjutnya agar folder atau file tersebut terdaftar ke system git , dan beralih ke mode (staged) , yang dimana telah terjadi perubahan atau penambahan pada project, kita bisa mengetikan perintah git add <namafile> atau git add *.
  • 4. Setelah itu kita beri keterangan atau pesan, kepada system Git, bahwa terjadi perubahan pada project tersebut dengan perintah: git commit -m “Pesan kalian”
  • 5. Lalu baru lah kalian bisa mengupload atau menyimpan project kalian ke repository Github (Server), dengan mengetikan perintah : git push origin master.
Alur Langkah Langkah Mengupload Project ke Github
Alur Mengupload Project ke Github

Selengkapnya jika ingin melihat Basic Git Command lainya ( Perintah Dasar Git ):

Kurang lebih itu saja  tentang Cara Mengupload Project ke Github Melalui Command Line. Jika terdapat kekurangan disana sini mohon maaf sebelumnya. Terima kasih.

How to Install PHP 7 on CentOS/RHEL 7.1 & 6.7

PHP 7.1 is the latest stable release of PHP. May of popular yum repositories are providing rpm packages for PHP 7. This article is using webtatic yum repository and used the same for testing on CentOS 7 server. This article will help you to install PHP 7 on CentOS & Red Hat 7.1 & 6.7 servers.

Install Yum Repository

First of all you need to enable Webtatic and EPEL yum repositories on your system. Use the following command to install EPEL repository on your CentOS and Red Hat 7/6 systems

Use this command to install epel-release yum repository.

# yum install epel-release

and now execute one of the following command as per your operating system version to install webtatic yum repository.

On CentOS/RHEL 7:

# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

On CentOS/RHEL 6:

# rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

Install PHP 7

Use the following command to install PHP 7 on your system.

# yum install php70w

Verify Install PHP Version

Now use the following command to check installed PHP version on your system.

# php -v

PHP 7.0.0 (cli) (built: Dec  2 2015 20:42:32) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

Install PHP Modules

You may also want to install additional php modules based on your application requirements. Below command will install some more useful php modules.

# yum install php70w-xml php70w-soap php70w-xmlrpc
# yum install php70w-mbstring php70w-json php70w-gd php70w-mcrypt

To find out other available php modules use the following command.

# yum search php70 


php70w.x86_64 : PHP scripting language for creating dynamic websites
php70w-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php70w-cli.x86_64 : Command-line interface for PHP
php70w-common.x86_64 : Common files for PHP
php70w-dba.x86_64 : A database abstraction layer module for PHP applications
php70w-devel.x86_64 : Files needed for building PHP extensions
php70w-embedded.x86_64 : PHP library for embedding in applications
php70w-enchant.x86_64 : Enchant spelling extension for PHP applications
php70w-fpm.x86_64 : PHP FastCGI Process Manager
php70w-gd.x86_64 : A module for PHP applications for using the gd graphics library
php70w-imap.x86_64 : A module for PHP applications that use IMAP
php70w-interbase.x86_64 : A module for PHP applications that use Interbase/Firebird databases
php70w-intl.x86_64 : Internationalization extension for PHP applications
php70w-ldap.x86_64 : A module for PHP applications that use LDAP
php70w-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
php70w-mcrypt.x86_64 : Standard PHP module provides mcrypt library support
php70w-mysql.x86_64 : A module for PHP applications that use MySQL databases
php70w-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
php70w-odbc.x86_64 : A module for PHP applications that use ODBC databases
php70w-opcache.x86_64 : An opcode cache Zend extension
php70w-pdo.x86_64 : A database access abstraction module for PHP applications
php70w-pdo_dblib.x86_64 : MSSQL database module for PHP
php70w-pear.noarch : PHP Extension and Application Repository framework
php70w-pgsql.x86_64 : A PostgreSQL database module for PHP
php70w-phpdbg.x86_64 : Interactive PHP debugger
php70w-process.x86_64 : Modules for PHP script using system process interfaces
php70w-pspell.x86_64 : A module for PHP applications for using pspell interfaces
php70w-recode.x86_64 : A module for PHP applications for using the recode library
php70w-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices
php70w-soap.x86_64 : A module for PHP applications that use the SOAP protocol
php70w-tidy.x86_64 : Standard PHP module provides tidy library support
php70w-xml.x86_64 : A module for PHP applications which use XML
php70w-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol

credit : tecadmin.net