A quick nginx - wordpress (or multiple sites) - varnish setup
Shell Perl Nginx PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
cloudflare
default
default.vcl
fresh-install.sh
index.php
install.sh
my.cnf
new-simple-site.sh
new-wordpress-site.sh
nginx.conf
php.ini
simple.template
varnish
varnish.service
vsftpd.conf
wordpress.template
www.conf

README.md

The perfect superfast webserver

UPDATE - Now with PHP7 / mariadb /nginx / varnish for UBUNTU 16

Usage :
Head to digital ocean or wherever, create a 5-10$ server (UBUNTU 16+), login as root, and run the following :
curl -sL https://raw.githubusercontent.com/upggr/nginx-varnish-perfect-server/master/install.sh | sudo bash -

Run the following to create your first wordpess installation :
./new-wordpress-site.sh yourdomain.com (replacing with your domain, no www allowed)

If you just want to install a simple site other than wordpress just run :
./new-simple-site.sh yourdomain.com

Then, just visit domain.com (provided you have pointed dns to your ip) and point to your mysql server.

Run the above commands for as many domains as you need. Ports used : 9921,80,22,12000-12010

Here you have it, 1.000.000 hits/per day capable wordpress instance for 10$
Script supports cloudflare, if you combine cloudflare dns and caching with varnish and w3 total cache, you cant go faster :)

Extras:
Configuring mysql:
All you have to do is run sudo mysql_secure_installation and answer the questions. You HAVE to set a password for mysql root.

Configuring phpmyadmin:
Run sudo apt-get install phpmyadmin -y and follow the steps. Your access will be at http://your.ip:8080/phpmyadmin Note that in the first step, you are presented with 2 options, apache and lighthttpd - do not select either. Reboot in the end.
You will also need a new mysql user other than root to login remotely to this phpmyadmin instance. (if you do want something like a root user). Lets assume you want a superuser with username : mysqluser and password : mypassword :
sudo mysql -uroot -p
CREATE USER 'mysqluser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON *.* TO 'mysqluser'@'localhost' WITH GRANT OPTION;
sudo ln -s /usr/share/phpmyadmin /var/www/html

Copy all databases from a remote phpmyadmin enabled mysql/mariadb server :
On old server :
mysql -u root -p
FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = ON;
EXIT
mysqldump --lock-all-tables -u root -p --all-databases > dump.sql
scp dump.sql root@newserver_IP:/tmp
You are done.
Do you want to migrate in stages? Just unlock the tables and start a replication using phpmyadmin:
mysql -u root -p SET GLOBAL read_only = OFF; UNLOCK TABLES; Use replication tab in phpmyadmin! make the new a slave, the old the master, then make the slave the new master.

Create a db for your wordpress site :
Just head to http://your.ip:8080/phpmyadmin create a new database. Then while in this database , go under privileges and add a new user / password. Do not touch any of the options, just create.

FTP access:
No need for FTP access! Just use SFTP on port 22...But if you really want it:
sudo nano /etc/vsftpd.allowed_users <- add user here. Default port for ftp is 9921
Also sudo nano /etc/ssh/sshd_config <- Add to the end : DenyUsers username
Use sudo adduser to create the user/password
sudo usermod -a -G www-data username
usermod -d /var/www/website.gr/ username This will add this user to this website so when they login they see the folder
FTP server will run on port 9921

Cloning a github repository and have it pull continuously in the newly created host:
sudo apt-get install git
sudo su - www-data -s /bin/bash
ssh-keygen -t rsa -b 4096 -C "your.github@email.com"
eval "$(ssh-agent -s)"
ssh-add /var/www/.ssh/id_rsa
cat /var/www/.ssh/id_rsa.pub <=== Copy the output of this. Then head to your github repo or account and add this as a deploy key.
Go to your web directory (cd /var/www/yourdomain.com/public_html)
Run git clone git@github.com:upggr/nginx-varnish-perfect-server.git . <=== Just replace this address with the repository you are cloning
create a new file : gitpull.php in your root (obviously, add it to your repo too so it is not removed with each pull)
Add the following in the file : <?php exec(git pull) ?>
Back in your github, under webhooks in your project settings, add the url : http://yourwebsite.com/gitpull.php

Easily copy other files from other webservers using ftp:
go to your public_html (cd /var/www/yourdomain.com/public_html)
sudo wget --ftp-user='username' --ftp-password='password' -nH --cut-dirs=2 -m ftp://your.other.old.host/site/wwwroot/* (note the --cut-dirs=2 because the files are 2 subfolders deep in this example (/site/wwwroot/)

Copy all www using scp!
Make sure you have added the user you are using to connect to the www-data group.:
On the old server :
tar -zcf /tmp/www.tar.gz /var/www
sudo scp -P 22 -C /tmp/www.tar.gz linuxuser@newserver.ip:/tmp/www.tar.gz
rm -rf /tmp/www.tar.gz
On the new server run :
sudo su - www-data -s /bin/bash
tar -xf /tmp/www.tar.gz -C /
rm -rf /tmp/www.tar.gz

Exclude one of your websites from varnish:
sudo nano /etc/varnish/default.vcl
if (req.http.host == "www.yourdomain.com" && req.url == "/") {return (pass);}