Ubuntu Nginx AWS EC2 RDS | WordPress Ready Server For Multiple Domains

It took a load of work to get this put together and I haven’t had time to put pictures and other stuff into it. The server configuration will definitely need some final tweaks, but this will certainly get things going. Nginx is incredible but new so any help would be appreciated. Use the contact above.

This doesn’t have to be on Amazon Cloud servers and you can easily tweak most of the following for Drupal, Joomla, Magento and all the other open-source goodies out there.

It will probably be helpful if you read this tutorial too. Fast Amazon AWS Optimized WordPress EC2 RDS S3 Manual Cache Gzip Config.

I will format with pics of the server set up soon! Pretty sure this site will be switching over to the server running after finishing this tutorial. This tutorial are actually notes that I wrote while setting up the server for the 15,000,000 time… A little exaggeration:)

For the pennies it will cost you to try this, you really should. It is fast. Very fkng fast. Throw a little cache into the equation and it may be unbeatable.

Hope you enjoy. And remember to help support us:)

So sorry for the lack of formatting.

Before we begin a quick tip.

To change the permissions on all directories within a directory using SSH/ Command Line:

find /var/www/site.com/dirpath -type d -exec chmod 755 {} \;

To change the permissions on all files within a directory using SSH/ Command Line:

find /var/www/site.com/dirpath -type f -exec chmod 644 {} \;

After Ubuntu 12.04 LTS install/ update/ upgrade/ reboot (See previous tutorial)

Create DB instance (See previous tutorial)

Then on the command line for your Ubuntu Server begin with this command:

cd /

sudo apt-get install apache2 mysql-client php5 php5-mysql php5-curl php5-gd php-apc php5-common php5-cli emacs23-nox

sudo apt-get install nginx

delete/ remove the file /etc/nginx/sites-available/default

sudo rm /etc/nginx/sites-available/default

sudo service nginx start

sudo apt-get install php5-fpm

sudo nano /etc/php5/fpm/php.ini

  • Find the line info=1 and change to cgi.fix_pathinfo=0
  • Find max file upload 2M and go up as needed
  • Find max post size and make it larger than max file upload size
  • Find max file uploads and increase as needed

Now we make PHP-FPM use Unix sockets to avoid TCP overhead.

sudo nano /etc/php5/fpm/pool.d/www.conf

change listen = 127.0.0.1:9000 to listen = /var/run/php5-fpm.sock

sudo service php5-fpm restart

sudo vi /etc/apache2/ports.conf

Change the port 80. Use 77 or something…

sudo reboot

sudo nano /var/nginx/www/info.php

PLACE IN FILE>>

<?php
phpinfo();
?>

sudo service nginx restart

Check the info.php by visiting http://yoursite.com/info.php and then remove. Change the following database info to what you used when setting up your RDS instance.

sudo mysql –user=databaseuser –password=databasepass –host=yourdomain.endpoint.us-west-2.rds.amazonaws.com

Make Sure mysql> is showing!!!

CREATE USER ‘databaseuser’@’yourdomain.endpoint.us-west-2.rds.amazonaws.com’ IDENTIFIED BY ‘databasepass’;
GRANT ALL PRIVILEGES ON databasename.* TO ‘databaseuser’@’yourdomain.endpoint.us-west-2.rds.amazonaws.com’;

exit;

You are now back in as ubuntu.

You will want to have a domain pointed to your Elastic IP to continue. There are other options available and continuing on with this tutorial while trying to accomplish those options may be helpful.

First we will get the latest wordpress, then we will move the zip file to our /var/www directory. Next we unzip. Then we change the name of the new wordpress directory created to yourdomain.com

cd /

sudo wget http://wordpress.org/latest.tar.gz

sudo cp -f latest.tar.gz /var/www/

cd var/www/

tar -zxvf latest.tar.gz

sudo mv wordpress yourdomain.com

sudo rm latest.tar.gz

cd yourdomain.com

cp wp-config-sample.php wp-config.php

sudo nano wp-config.php

Change database, username, password and salts as usual.
exit and save :)

cd /var/www/

sudo chown www-data:www-data * -R

The following step is a security measure and can be skipped for those wanting to make updating their wordpress as easy as it can be. Some recommend this as a precaution against past WordPress vulnerabilities. As usual… It is always a good idea to keep updates of your database and files…

Replace “ubuntu” below with another user if you have set it up!

sudo usermod -a -G www-data ubuntu

cd /var/www/yourdomain.com

sudo chown www-data:www-data * -R

Replace “ubuntu” below with another user if you have set it up!

sudo usermod -a -G www-data ubuntu

cd /

cd /etc/nginx/sites-available

sudo vi yourdomain.com

Add the following to the file, making sure you replace yourdomain.com exit/ save.

server {
listen 80;

root /var/www/yourdomain.com;
index index.php index.html index.htm;

server_name yourdomain.com;

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}

# pass the PHP scripts to fpm socket
location ~ .php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

}

Activate the Server with a Symlinkls!!!

sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/yourdomain.com

Delete the default in etc/nginx/sites-enabled

sudo rm /etc/nginx/sites-enabled/default

sudo service nginx restart

To use the www.yourdomain.com subdirectory you will need to repeat the steps above as follows.

cd /

cd etc/nginx/sites-available

sudo vi www.yourdomain.com

Add the following to the file. Make sure you include the www. in the server name but not the root. As shown below:

server {
listen 80;

root /var/www/yourdomain.com;
index index.php index.html index.htm;

server_name www.yourdomain.com;

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}

# pass the PHP scripts to fpm socket
location ~ .php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

}

Activate the Server with a Symlinkls!!!

cd /

sudo ln -s /etc/nginx/sites-available/www.yourdomain.com /etc/nginx/sites-enabled/www.yournewdomain.com

sudo service nginx restart

To add more sites :)

sudo wget http://wordpress.org/latest.tar.gz

sudo cp -f latest.tar.gz /var/www/

cd var/www/

tar -zxvf latest.tar.gz

sudo mv wordpress yourdomain.com

sudo rm latest.tar.gz

RBS: Add an instance… Keep up with the DB Identifier, Master User, Master Pass and the end host :)

sudo mysql –user=newdbuser –password=newdbpassword –host=newdbendpoint.us-west-2.rds.amazonaws.com

Make Sure mysql> is showing!!!

CREATE USER ‘newdbuser’@’newdbendpoint.us-west-2.rds.amazonaws.com’ IDENTIFIED BY ‘newdbpassword’;

GRANT ALL PRIVILEGES ON newdbname.* TO ‘newdbuser’@’newdbendpoint.us-west-2.rds.amazonaws.com’;

quit

sudo cd var/www/newsite.com

sudo cp wp-config-sample.php wp-config.php

sudo nano wp-config.php

Change database, username, password and salts as usual.
exit and save :)

sudo find var/www/newdomain.com -type f -print0 | xargs -0 sudo chmod 644

sudo find var/www/newdomain.com -type d -print0 | xargs -0 sudo chmod 755

cd /var/www/yournewdomain.com

sudo chown www-data:www-data * -R

Replace “ubuntu” below with another user if you have set it up!

sudo usermod -a -G www-data ubuntu

cd /

cd /etc/nginx/sites-available

sudo vi yournewdomain.com

Add the following to the file, exit/ save.

Change root to /var/www/yournewdomain.com
server_name should be your new domain name not yournewdomain.com 😛
Leave location root alone…

server {
listen 80;

root /var/www/yournewdomain.com;
index index.php index.html index.htm;

server_name yournewdomain.com;

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}

# pass the PHP scripts to fpm socket
location ~ .php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

}

Activate the Server with a Symlinkls!!!

cd /

sudo ln -s /etc/nginx/sites-available/yournewdomain.com /etc/nginx/sites-enabled/yournewdomain.com

sudo service nginx restart

To Use www. subdomain

cd /

cd /etc/nginx/sites-available

sudo vi www.yournewdomain.com

Add the following to the file, exit/ save.
MAKE SURE YOU
Change root to /var/www/yournewdomain.com
Leave location root alone…

WATCH CAREFULLY WHERE www. is included with the url… THE actual site root and folders are on the yournewdomain.com directory in /var/www/yournewdomain.com. Just be careful going forward… As you see below in the third line: root is going to a directory without www.

If that doesn’t make sense please continue. It will.

server {
listen 80;

root /var/www/yournewdomain.com;
index index.php index.html index.htm;

server_name www.yournewdomain.com;

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}

# pass the PHP scripts to fpm socket
location ~ .php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

}

Activate the Server with a Symlinkls!!!

cd /

sudo ln -s /etc/nginx/sites-available/www.yournewdomain.com /etc/nginx/sites-enabled/www.yournewdomain.com

sudo service nginx restart

Have fun with your new NGINX WordPress Server on the Amazon Cloud!

To optimize your AWS Nginx server and the WordPress sites see this tutorial:

http://anebula.com/optimize-wordpress-on-nginx/

Comments are closed.