This tutorial assumes two sites, varnish.chris.example.com and web.chris.example.com. Both of my test sites will be created on DigitalOcean but on separate instances. Both will be running basic Ubuntu 14.04.
On web.chris.example.com
Install Nginx
- Add the dev repo so that we can get to 1.7.x:
sudo apt-add-repository ppa:nginx/development sudo apt-get update
- Verify that we’ll get 1.7.x (check the version number returned, currently 1.7.5 as of this posting. If you see 1.4.6 you probably didn’t run apt-get update above)
sudo apt-get -s install nginx
- Install Nginx
sudo apt-get install nginx
- Verify that it was installed
nginx -v
Install and configure PHP-FPM
- Install PHP-FPM
sudo apt-get install php5-fpm - Tweak PHP-FMP for security:
sudo vi /etc/php5/fpm/php.ini
-
Look for
;cgi.fix_pathinfo=1
and change it tocgi.fix_pathinfo=0
-
Restart PHP-FPM
sudo service php5-fpm restart
-
Create a directory for our web files:
sudo mkdir /var/www
Configure Nginx
- Edit the default site for Nginx (or whatever site you want to work on)
sudo vi /etc/nginx/sites-available/default
- Erase and change to
server { listen 80 default_server; root /var/www; index index.php; location / { try_files $uri $uri/ =404; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; } }
- Test Nginx:
sudo nginx -t
- Restart Nginx
sudo service nginx restart
- Create a quick test file
echo "<?php phpinfo();" | sudo tee /var/www/index.php
- Use a web browser to confirm that PHP is running
- Remove the test file
sudo rm /var/www/index.php
Install and configure mysql
- Install
sudo apt-get install mysql-server php5-mysql
- Configure
sudo mysql_install_db sudo mysql_secure_installation
Install exim for email (optional)
-
sudo apt-get install exim4 sudo dpkg-reconfigure exim4-config
Install WP-CLI
- Install PHP CLI
sudo apt-get install php5-cli - Download
cd ~ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
- Test
php wp-cli.phar --info
- Make it executable
chmod +x wp-cli.phar
- Make it available everywhere as just the command wp
sudo mv wp-cli.phar /usr/local/bin/wp Confirm it works
wp --info
Install WordPress via WP-CLI (optional, you can do it any way you want)
- Download WordPress
cd /var/www wp core download
- Create a MySql database and user, replace the testXYZ parts as needed
mysql -uroot -p -e “CREATE DATABASE testdb; GRANT ALL PRIVILEGES ON testdb.* TO testuser@localhost IDENTIFIED BY ‘testpassword’; FLUSH PRIVILEGES;” - Create a config file (replace variable below obviously)
wp core config --dbname=testdb --dbuser=testuser --dbpass=testpassword
Generate some sample content
- wp post generate –count=10000
Notes
- Nginx runs as user and group www-data by default. For most of my installs I usually add my non-root account to the www-data group and also make that my default group
sudo usermod -a -G www-data myaccounthere
sudo usermod -g www-data myaccounthere