Get a MySQL Table Row-names and Types using PHP PDO

Sometimes it is advantageous to have information about the columns of a table in the database.

If all you need is the SQL, copy the box bellow and use it in your favorite program.


SELECT `COLUMN_NAME`, `DATA_TYPE`, `COLUMN_DEFAULT`, `COLUMN_TYPE` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?";

 
Here is a nice example function written in PHP that uses PDO to read the table columns and return a formatted array with the data.
Continue reading “Get a MySQL Table Row-names and Types using PHP PDO”

Apache+php-fpm the right way

The simplest, and probably the correct, way to configure php-fpm with apache in Centos 6/7 is by using SetHandler and ProxySet directives.

The snippet bellow show a simple Virtual Host example, just change lines 2 3 and 6 and you are good to go.


<VirtualHost *:80>
    ServerAdmin [email protected]
    Servername example.com
    Options +Indexes
    DirectoryIndex index.php                                                                                                                    
    DocumentRoot /var/www/html
    # Register php-fpm as the handler for (.*).php files.
    <FilesMatch \.php$>
         SetHandler "proxy:fcgi://localhost:9000"
    </FilesMatch>
    # Configure the proxy
    <Proxy fcgi://localhost:9000>
        ProxySet connectiontimeout=5 timeout=240
    </Proxy>

    # If the php file doesn't exist, disable the proxy handler
    # so we can gracefully fail.
    RewriteCond %{REQUEST_FILENAME} \.php$
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
    RewriteRule (.*) - [H=text/html]
</VirtualHost>

 
Continue reading “Apache+php-fpm the right way”

Bad Idea of the day, Compiling PHP-52 for Debian 8

Sometimes you have to test a bad idea, or you just don’t want/can’t to let that 10+ years old ugly and unmaintained project die no matter what, and for that you might have to use a EOL unsupported PHP version

First install the necessary build tools, some of which you may not need:

apt-get install -y autoconf2.13 libbz2-dev libcurl4-openssl-dev libltdl-dev libmcrypt-dev libevent-dev libmhash-dev libmysqlclient-dev libpcre3-dev libpng12-dev libxml2-dev make patch xmlstarlet make patch libssl-dev libssl1.0.0

Continue reading “Bad Idea of the day, Compiling PHP-52 for Debian 8”

Install php7.2 CentOS 6.X and 7.X

As PHP versions 5.6 and 7.0 reach End Of Life you might want to update to something newer and supported, unfortunately the official CentOS repositories don’t have PHP versions 7.1 or 7.2 yet, but with a third-party repository and a bit of fiddling it’s easy to update, and more importantly keep it updated, your server PHP version.
 
Just run as root:
Continue reading “Install php7.2 CentOS 6.X and 7.X”

Install php7.2 Debian Stretch

As PHP versions 5.6 and 7.0 reach End Of Life you might want to update to something newer and supported, unfortunately the official Debian Stretch repositories don’t have PHP versions 7.1 or 7.2 yet, but with a third-party repository and a bit of fiddling it’s easy to update, and more importantly keep it updated, your server PHP version.
 

Just run as root:
Continue reading “Install php7.2 Debian Stretch”

Setting Enviroment Variables for PHP-FPM with Apache

Once in a while you may want to be able to pass information from the apache server to the php-fpm process, a way of doing it is by using environment variables, you can set them either in .htaccess files or in your virtual host configuration files.
 
You can set one variable per line as the following in your file of choice:

SetEnv VARIABLE_NAME "VARIABLE_VALUE"

 
Continue reading “Setting Enviroment Variables for PHP-FPM with Apache”