Sysadmins Skills for PHP developers
The IT department, and specially the sysadmins, are usually busy and they have other priorities than the developers. This is not rocket science! and it let you have more control and better performance over your code. You could improve your time so much, that you could even enjoy sunsets with your special someone.
First things first, the server config. Traditionally, you would use LAMP. Now a days you could choose between Apache(LAMP), and Nginx(LNMP). For the database you could use MySQL, MongoDB or even PostgreSQL. That's why, over the years, the traditional LAMP has been replace with a little more complex LANMMPP. And why should we use this config? That's simple, because it's well known, well tested, stable, secure, with low costs, and because it's easy to get it.
There are many Linux distros (Fedora, RHEL, Ubuntu, etc.) but most of them are based on one of this two linux, RedHat or Debian. There main differences are config files, package management, services handlers, versions and updates. Other distros differences are the PHP version they support, and the PHP extensions they have.
So, what Linux distro should we choose? that is the eternal question.
It's all reltaive! But relative to what?
You should choose the distro you know more, the one that suits you best, the one that your collegues and friends used. Even if it's your first time, and you don't want to make a mess, you could mount a virtual machine on Windows or IOS.
Now that you have chosen your distro, let's get down into business, Apache/PHP install!
Depending on the distro you chose, you will have to use yum or apt-get. Check you linux manual to see which one applies. It's very easy. If you like, you could also download the PHP and compile it yourself with only the extensions you like. It's not that hard! Try it!
For the PHP config, first locate the php.ini file, using the grep command. It's usually located under /usr/local/lib or under /etc/php/. With the "php -m" command you could list all the modules installed with your PHP. You could use automatization softwares like Chef, Puppet or Ansible to manage your PHP configuration.
Besides the modules, you should also config your timezone, your memory, time & error management and your level of security.
Then you will have to config Apache and your htaccess file.
Don't forget to restart your Apache service after changes!! And always check the user permissions, if not they will bring you a headache later!
OK, let's go live now!!!!!
Noooo, wait, first let's check some things before we regret it.
Let's make sure that Ntpd is installed and running and that PHP is disabled in places we don't want it to run. We could even limit our site to certain IPs or requiere some sort of authentication.
We should also check our code. Always check that the name of your classes match the files.
For code deploying, it's always better to create an install package. You could use Effing Package Manager, Capifony or other package management software.
Lastly, before deploying, you should config ssh with your server parameters. You could automatize the upload process using a PHP script.
Some tips from the DNS:
- Know the power of the hosts file. You could do some redirects simply by adding 1 line.
- Use virtual document roots
- Define the Name Servers expiration dates
- Dig into the DNS records to see if the Server is config correctly
- Perform a DNS lookup and a traceroute
Another sysadmin skill is the Server monitoring. You should monitored your Apache requests. There are several softwares for this task, like Cacti, Ganglia, Zabbix, collectd, statsd or graphite. Or you could use the linux "top" and "iotop" commands, to check the io, cpu and memory of the Server.
Besides the monitoring, it's good to check the logs, like the access log, the error log and even the syslog.
Now that everything is installed, running & monitoring, let's get into performance!! You could use several tools, like nginx/php-fpm, APC, ZendOptimazer+, Memcache, nginx reverse proxy cache, and Varnish.
Finally, when everything is running smooth, you should make backups. It would be a shame if you loose your data. Tools like rsync, rdiff-backup, Unison, Bacula, and Amanda will help you accomplish this. Also backup your database!
That will be all! You are now a proud sysadmin! Ok, not quite, but you know your stuff.
The best way to improve your skills is to practice, and keep it informed, by reading the Unix and Linux management reading list