mysqlnd vs libmysql

TL:DR If you are using php 5.3.3 or newer then go mysqlnd, otherwise stay with the default libmysql.

Whats the difference? While I could post it here for you, a more updated source would be http://www.php.net/manual/en/mysqlinfo.library.choosing.php.

As you can see, currently mysqlnd does ‘pretty-much’ evrything libmysql does with a plethora of additional features. So why on earth is that even a valid question? Well.. its not… at least not currently… If we move a few years in the past, mysqlnd did not support compression or SSL, which was in many cases a deal breaker. As of PHP 5.3.3 all of these are supported and it just makes more sense to go with the native driver.

Personally I use mysqlnd because I love using fetch_all. So, how to install? Follow below:

apt-get remove php5-mysql
apt-get insall php5-mysqlnd

(Note. you may have to reinstall anything that depended on mysql, such as phpmyadmin)

How to get mssql to work on php (debian/ubuntu)

Assuming that you already have PHP installed, you enter into the console

 apt-get install php5-sybase

(sadly not as intuitive as apt-get install php5-mssql)

For most instances that may be enough to give you what you need. If by any chance that doesn’t work, or you need more ‘functionality’ you can try (untested by me)

apt-get install php-pear
pear install --nodeps MDB2_Driver_mssql

How to check active connections on web server

Now this isn’t the most accurate method out there but it is by far the easiest.

Open up your console and type
 netstat -an | grep :443 | grep ESTABLISHED | wc -l

 

or even better, for a running total

watch "netstat -an | grep :443 | grep ESTABLISHED | wc -l"

 

Just to add one more not without getting too technical

netstat -an | grep :443 | grep -v TIME_WAIT | wc -l

should give you all connections that the local server hasn’t closed, depening on your application, this may be more accurate

nginx configtest vs nginx -t

While both of these commands will tell you if your new nginx configuration is ok [without killing your current instance]. Configtest uses the running service and tells you if it passes or fails the check whereas nginx -t will not only check the config but print any info, warning as well as error messages..

Usage is typically:

service nginx configtest && service nginx restart
or
nginx -t && service nginx restart

My personal preference is to use nginx -t because 1. its shorter and i’m lazy snf 2. I like knowing where exactly the problem lies (easier debugging and whatnot).

How to setup a VPS (or Dedicated Server) with Nginx from scratch

In this tutorial we are going to go through the steps of securing the server and configuring Nginx, PHP, Phpmyadmin and MySql.

Step 1. Basic Security

Assuming you have already logged into your server we start by changing the root password to something more secure.

passwd

 

This will prompt you to change the root password, It is recommended to choose something extremely complex as it is your most crucial line of defence against the outside world.

Next, open up the ssh config

vim /etc/ssh/sshd_config

and change the port from 22 to anything between 1025 to 65536, this will prevent our server from being easily spotted by malicious eyes Continue reading

How to enable .htaccess in apache

Step 1.

cd /etc/apache2/sites-available

Step 2.

vim default (or default-css)

Step 3. Change AllowOverride from ‘None’ to ‘All’

<VirtualHost *:80>
    ServerAdmin [email protected]

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride All    <---- replace None with All
    </Directory>
    <Directory /var/www >
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All   <---  replace None with All
            Order allow,deny
            allow from all
    </Directory>

Step 4. Enable Mod Rewrite

sudo a2enmod rewrite

5. Restart Apache

service apache2 restart

You are now done…

Sample .htaccess…

Continue reading

How to setup a Nginx Server (LEMP Stack)

nginx-logo

Setup an Ubuntu Server with only the

  • [x] Essential Services
  • [x] SSH Server

Login as root

Lets start with an update

apt-get update
apt-get upgrade

To secure your server a bit. Edit ssh and change the default port

nano /etc/ssh/sshd_config

Change ‘port 22’ to whatever port you wish to use then…

service ssh reload

(you can now login like this:  ssh [email protected] -p portyouchose )

We now begin setting up the actual server components starting with MySQL

apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

(you will be prompted to enter your password here: lets call that passwordA)

Now MySQL is installed lets configure for production use.

mysql_install_db
/usr/bin/mysql_secure_installation

It my ask for the root password: enter passwordA which you entered above.
Do you want to change password: N
Remove Anonymous Users: Y
Disallow Root Login Remotely: Y
Remove test Database: Y
Reload Tables: Y

All done!! At Least with MySQL

During the installation of MySQL an apache server may have been setup.. since we want LEMP (we need to uninstall apache2 and install Nginx) do that with

(uninstall apache)

service apache2 stop
apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
apt-get autoremove

(install Nginx)

apt-get install nginx
service nginx start

(you can do a ‘ifconfig’ to get ip address and test out server in your browser)

On to the last part. Installing PHP.

apt-get install php5-fpm

And configure it..

Open php.ini

vim /etc/php5/fpm/php.ini # you may use nano if u wish (nano /etc/php...)

find ‘cgi.fix_pathinfo=1’ and replace with ‘cgi.fix_pathinfo=0’ – this makes PHP not ‘guess’ what urls users are trying to go to (added security)

and restart php

service php5-fpm restart

Well.. thats about it.. your html files are at /usr/share/nginx/www

For added security you can install denyhosts

apt-get install denyhosts

and phpmyadmin

apt-get install phpmyadmin

 

Enjoy your new high performance and secure Nginx server.