Step One — Install the Nginx Web Server
sudo apt-get update
sudo apt-get install nginx
you can find it by typing one of the following into your terminal:
ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s/\/.*$//’
Browser web page
http://server_domain_name_or_IP
Step Two — Install MySQL to Manage Site Data
sudo apt-get install mysql-server
sudo mysql_install_db
sudo mysql_secure_installationStep Three — Install PHP for Processing
sudo apt-get install php5-fpm php5-mysqlOpen the main php5-fpm configuration file with root privileges:
sudo gedit /etc/php5/fpm/php.ini
We will change both of these conditions by uncommenting the line and setting it to “0” like this:
cgi.fix_pathinfo=0
Save & Exit
Now, we just need to restart our PHP processor by typing:
sudo service php5-fpm restart
Step Four — Configure Nginx to Use our PHP Processor
We do this on the server block level (server blocks are similar to Apache’s virtual hosts). Open the default Nginx server block configuration file by typing:
sudo gedit /etc/nginx/sites-available/default
Currently, with the comments removed, the Nginx default server block file looks like this:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
}
We need to make some changes to this file for our site.
The changes that you need to make are in red in the text below:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name server_domain_name_or_IP;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Now, we just need to restart our PHP processor by typing:
sudo service nginx restart
Step Five — Create a PHP File to Test Configuration
sudo gedit /usr/share/nginx/html/info.php
We can type this into the new file. This is valid PHP code that will return formatted information about our server:
<?php
phpinfo();
?>
save and close the file.
Browser web page
http://server_domain_name_or_IP/info.php
For now, remove the file by typing:
sudo rm /usr/share/nginx/html/info.php
How To Install WordPress with Nginx on Ubuntu 14.04
Step One — Create a MySQL Database and User for WordPress
mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER wordpressuser@localhost IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
FLUSH PRIVILEGES;
exit
Step Two — Download WordPress to your Server
cd ~
wget http://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
sudo apt-get update
sudo apt-get install php5-gd libssh2-php
Step Three — Configure WordPress
cd ~/wordpress
cp wp-config-sample.php wp-config.php
sudo gedit wp-config.php
We can find these parameters in this file and set them up to use the database and user details that we created. My file looks like this:
. . .
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wordpress’);
/** MySQL database username */
define(‘DB_USER’, ‘wordpressuser’);
/** MySQL database password */
define(‘DB_PASSWORD’, ‘password’);
. . .
save and close the file.
Step Four — Copy the Files to the Document Root
sudo mkdir -p /var/www/html
sudo rsync -avP ~/wordpress/ /var/www/html/
cd /var/www/html/
sudo chown -R kesari:www-data /var/www/html/*
mkdir wp-content/uploads
sudo chown -R :www-data /var/www/html/wp-content/uploads
Step Five — Modify Nginx Server Blocks
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress
sudo nano /etc/nginx/sites-available/wordpress
We will want to make the following changes:
server {
listen 80; ##default_server;
#listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm;
server_name IP Address;
location / {
try_files $uri $uri/ =404;
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/html;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
save and close the file.
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
sudo service php5-fpm restart
Step Six — Complete the Installation through the Web Interface
http://ip address/wp-admin
wordpressuser
password
Step Six (Optional) — Configure Pretty Permalinks for WordPress
http://ip address/wp-admin
Modifying Apache to Allow URL Rewrites
sudo nano /etc/apache2/sites-available/000-default.conf
This should look something like this:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName server_domain_name_or_IP
<Directory /var/www/html/>
AllowOverride All
</Directory>
. . .
save and close the file.
which allows you to modify URLs.
sudo a2enmod rewrite
sudo service nginx restart
Create an .htaccess File
Type this to create an empty file:
touch /var/www/html/.htaccess
sudo chown :www-data /var/www/html/.htaccess
chmod 664 /var/www/html/.htaccess
chmod 644 /var/www/html/.htaccess
Change the Permalink Settings in WordPress.
Copy the lines that WordPress gives you and then edit file on your server:
sudo gedit /var/www/html/.htaccess
How To Use WPScan to Test for Vulnerable Plugins and Themes in WordPress
Download and Install WPScan
sudo apt-get install git
sudo apt-get install libcurl4-gnutls-dev libopenssl-ruby libxml2 libxml2-dev libxslt1-dev ruby-dev ruby1.9.3
git clone https://github.com/wpscanteam/wpscan.git
cd wpscan
sudo gem install bundler && bundle install –without test development
Enumerating Plugins
sudo ruby wpscan.rb –url http://www.yoursiteurl.com –enumerate p
sudo ruby wpscan.rb –url http://www.yoursiteurl.com –enumerate vp
Enumerating Themes
sudo ruby wpscan.rb –url http://www.yoursiteurl.com –enumerate t
sudo ruby wpscan.rb –url http://www.yoursiteurl.com –enumerate vt
sudo ruby wpscan.rb –url http://www.yoursiteurl.com –enumerate u
sudo ruby wpscan.rb –url http://www.yoursiteurl.com –enumerate tt
To update wpscan:
sudo ruby wpscan.rb –update
How to setup FTP server on ubuntu 14.04 ( VSFTPD )
sudo apt-get update
sudo apt-get install vsftpd
After installation open /etc/vsftpd.conf file and make changes as follows.
Uncomment the below lines (line no:29 and 33).
write_enable=YES
local_umask=022
chroot_local_user=YES
and add the following line at the end.
allow_writeable_chroot=YES
pasv_enable=Yes
pasv_max_port=40000
pasv_min_port=40100
Save & Close
sudo service vsftpd restart
sudo useradd -m john -s /usr/sbin/nologin
sudo passwd john
Open
sudo gedit /etc/shells
copy line at the end.
/usr/sbin/nologin
Securing FTP ( SFTP ) Installation
sudo apt-get install openssh-server
open sudo gedit /etc/vsftpd.conf
add the below line to enable ssl.
ssl_enable=Yes
sudo groupadd ftpaccess
Now make changes in this /etc/ssh/sshd_config file.
Find the below line
Subsystem sftp /usr/lib/openssh/sftp-server
and replace with
Subsystem sftp internal-sftp
Match group ftpaccess
ChrootDirectory %h
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
and comment the below line ( Last line).
#UsePAM yes
sudo service vsftpd restart
sudo service ssh restart
sudo useradd -m john -g ftpaccess -s /usr/sbin/nologin
sudo passwd john
sudo chown root /home/john
sudo mkdir /home/john/www
sudo chown john:ftpaccess /home/john/www