- Unsupervised Learning
- Posts
- Building a Wicked Fast CentOS Web Server with Nginx, PHP, and MySQL
Building a Wicked Fast CentOS Web Server with Nginx, PHP, and MySQL
I’m migrating from RamNode back to my favorite host—Linode.
Some may ask why I left in the first place, and the answer is simply that for a while there RamNode had SSD and Linode didn’t. But Linode has fixed that, so I’m back.
Rebuilding danielmiessler.com
I’ve been wanting to do a write-up on configuring a new server from scratch for a long time now, and I’m using this migration back to Linode to do so. Here are some details on the server:
Host: Linode
Plan: 8192 (6 cores, 8GB memory, 196GB of SSD)
OS: 64-bit CentOS 6.5
My stack
My stack remains the same, and can be found at /stack, but here it is:
Host: Linode (8192 Plan: 6 Cores, 8GB Memory, 196GB of SSD)
Operating System: 64-bit CentOS 6.5
Web Server: Nginx for primary web server, using in-memory caching similar to Varnish
Content Delivery: Google’s Page Speed Service, which serves as a reverse proxy and CDN
CMS: WordPress for the /blog, but custom code for everything else
Code Editor: Vim
Source Management: Git
Basic Setup
Here are the basic steps I go through to configure a new server.
Software updates
Self explanatory.
Install a C compiler
I install a lot of my packages from source, so you need this early on.
yum install gcc
yum install gcc-c++
yum install ncurses-devel (needed to install vim from source)
Vim installation and configuration
Uninstall CentoOS’s Vim version
Install from source
ZSH installation and configuration
Install zsh
Change default shell to zsh (chsh -s /bin/zsh)
Copy over your .oh-my-zsh directory, extract
Copy over your .zshrc file
Source your .zshrc file
Change hostname
Edit /etc/sysconfig/network with the proper hostname
Add hostname entries to /etc/hosts
SSH configuration
Settings lockdown (hardening)
Key authentication enabled
Restrict to certain users
Install firewall
Copy over script
Change hostname if necessary
Run script
iptables-save
Install nginx
Get source from website
Install the PCRE library (pcre-devel)
Install the zlib library (zlib-devel)
Get the more headers library
Compile with –add-module=the_headers_library
Make
Make install
Install PHP
Install php-fpm
Install mysql
Install mysql
Install mysql-server
Change mysql root password
Limit mysql to localhost
Import blog database backup
Auto starts
Auto start php-fpm
Auto start nginx
Auto start mysql
The firewall is handled by service iptables save
Miscellaneous tools
nmap
httpd-tools
Security
Firewall
Copy over firewall script
Run it
/etc/init.d/iptables save
Nginx
PHP
Suhosin
Performance
PHP
Install php-opcache
Restart php-fpm