Setup Production DB Server: MariaDB + PhpMyAdmin

Standard

Update Centos:

sudo yum update
sudo yum install nano wget

DB Server

sudo yum install httpd php php-mysql

sudo service httpd start
sudo systemctl enable httpd

Install MariaDB
Add MariaDB Repo

sudo nano /etc/yum.repos.d/MariaDB.repo

Put this inside MariaDB.repo


# MariaDB 10.1 CentOS repository list - created 2016-06-07 15:06 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Install and Start Maria DB

sudo yum install MariaDB-server MariaDB-client

sudo service mariadb start
sudo systemctl enable mariadb

Securing Maria DB

sudo /usr/bin/mysql_secure_installation

Installing PHP MyAdmin

sudo yum install epel-release

sudo yum install phpmyadmin

PhpMyadmin Configuration

sudo nano /etc/httpd/conf.d/phpMyAdmin.conf

Change Php MyAdmin URL

Alias /NePhpMyAdminUrl /usr/share/phpMyAdmin

To allow access from All add Require all granted

<RequireAny>
   Require all granted
   Require ip 127.0.0.1
   Require ip ::1
</RequireAny>

Restart Web Server

sudo service httpd restart

URL

http://domain.com/NePhpMyAdminUrl

[SOLVED] Laravel 5.1 Nginx/Apache: Can’t display errors, 500 internal server error

Standard

Edit index.php in public folder.

put all code inside try .. catch …


<?php

try {

require __DIR__.'/../bootstrap/autoload.php';

$app = require_once __DIR__.'/../bootstrap/app.php';

$kernel = $app->make('Illuminate\Contracts\Http\Kernel');

$response = $kernel->handle(
	$request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);


} catch(\Exception $e) {
    echo "<pre>";
    echo $e;
    echo "</pre>";
}

[Solved] Laravel Storage Permission Denied even chmod 777

Standard

By default, SELinux will block the ability for Apache/webapps to write to files in RHEL/Centos. This is a security feature to limit what folders Apache can write to. You can notice this issue if you get errors in your Apache/Nginx such as:

PHP Warning:  move_uploaded_file(): Unable to move ‘/path/to/upload/…’ to ‘…….’

Command to set permissions:

chcon -R -t httpd_sys_rw_content_t <folder_name>

You can check the SELinux permissions via the following command:

ls -halZ

If You get Laravel Storage Permission Denied even chmod 777 there is posibility it is caused by SELinux mode in the server. SELinux was enabled which prevent Apache/Nginx to write files even with 777 mode.

Check

 sudo setenforce 0

This should allow writing to storage directory, If permission denied gone, this prove SELinux is the problem. Turn SELinux back

setenforce 1

Then finally use SELinux to allow writing of the file by using this command

chcon -R -t httpd_sys_rw_content_t storage

And you’re off!

[Solved] Composer SSL Certificate Failed

Standard

got this error when running composer on Windows with PHP 5.6

 [Composer\Downloader\TransportException]
 The "https://packagist.org/packages.json" file could not be downloaded: SSL operation failed with code 1. OpenSSL Error messages:
 error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
 Failed to enable crypto
 failed to open stream: operation failed

Run this in console:

php -r "print_r(openssl_get_cert_locations());"

Mine got something like this:

Array
(
    [default_cert_file] => f:\repo\winlibs_openssl_vc11_x86/cert.pem
    [default_cert_file_env] => SSL_CERT_FILE
    [default_cert_dir] => f:\repo\winlibs_openssl_vc11_x86/certs
    [default_cert_dir_env] => SSL_CERT_DIR
    [default_private_dir] => f:\repo\winlibs_openssl_vc11_x86/private
    [default_default_cert_area] => f:\repo\winlibs_openssl_vc11_x86
    [ini_cafile] =>
    [ini_capath] =>
)

but I have no “f:\repo” directory so it was pointing to wrong location.

To fix this, add this line to PHP.ini

openssl.cafile="\xampp\perl\vendor\lib\Mozilla\CA\cacert.pem"

Or download cacert.pem from http://curl.haxx.se/ca/cacert.pem
and add this line to PHP.ini

openssl.cafile="\your\cacert\pem\path\cacert.pem"

Convert Javascript Array into PHP Array

Standard

String Javascript Array
For Example: [“A”,2,[[1,1,1,"A","J",1],[1,2,1,"B","J",1],[1,4,1,"C","J",1]]]

$string_array = '["A",2,[[1,1,1,"A","J",1],[1,2,1,"B","J",1],[1,4,1,"C","J",1]]]';

Convert String to Value/array in PHP

$array = eval("return $string_array;");

Result Array

print_r($array);

Full Code:

$string_array = '["A",2,[[1,1,1,"A","J",1],[1,2,1,"B","J",1],[1,4,1,"C","J",1]]]';

$array = eval("return $string_array;");
print_r($array);

Curl Grep Function

Standard
function curl_grap($Url){
 
    // is cURL installed yet?
    if (!function_exists('curl_init')){
        die('Sorry cURL is not installed!');
    }
 
    // OK cool - then let's create a new cURL resource handle
    $ch = curl_init();
 
    // Now set some options (most are optional)
 
    // Set URL to download
    curl_setopt($ch, CURLOPT_URL, $Url);
 
    // Set a referer
    curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
 
    // User agent
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
 
    // Include header in result? (0 = yes, 1 = no)
    curl_setopt($ch, CURLOPT_HEADER, 0);
 
    // Should cURL return or print out the data? (true = return, false = print)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
    // Timeout in seconds
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
 
    // Download the given URL, and return output
    $output = curl_exec($ch);
 
    // Close the cURL resource, and free system resources
    curl_close($ch);
 
    return $output;
}

Install PHPUnit in Xampp

Standard

First off I’m assuming xampp is installed to C:\xampp
1. Open a command prompt and go to C:\xampp\php
2. Type “pear update-channels” (updates channel definitions)
3. Type “pear upgrade” (upgrades all existing packages and pear)
4. Type “pear channel-discover components.ez.no” (this is needed for PHPUnit)
5. Type “pear channel-discover pear.symfony-project.com” (also needed by PHPUnit)
6. Type “pear channel-discover pear.phpunit.de” (This IS phpunit)
7. Type “pear install –alldeps phpunit/PHPUnit” (installs PHPUnit and all dependencies)