Installing WordPress on Ubuntu 14.04 Nginx on AWS

Published on Author craigzearfossLeave a comment
  • Create a database.
    mysql -h localhost -u root -p
    CREATE DATABASE WORDPRESS_DATABASE;
    CREATE USER WORDPRESS_USER@localhost IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON WORDPRESS_DATABASE.* TO WORDPRESS_USER@localhost;
    FLUSH PRIVILEGES;
    exit;
    
  • Download WordPress and copy it to the document root.
    cd ~
    wget http://wordpress.org/latest.tar.gz
    tar xzvf latest.tar.gz
    sudo mv wordpress/ /var/www/WORDPRESS_DIRECTORY/
    
  • Download some additional PHP modules WordPress will need.
    sudo apt-get update
    sudo apt-get install php5-gd libssh2-php
    
  • Configure WordPress.
    cd /var/www/WORDPRESS_DIRECTORY/
    cp wp-config-sample.php wp-config.php
    

    Edit wp-config.php

    sudo nano wp-config.php
    

    SET the DB_NAME, DB_USER and DB_PASSWORD.
    Update the secret keys by replacing the values in the file with the values from the url https://api.wordpress.org/secret-key/1.1/salt/.

  • Set directory permissions and make uploads directory.
    sudo chown -R demo:www-data /var/www/WORDPRESS_DIRECTORY/*
    mkdir wp-content/uploads
    sudo chown -R :www-data /var/www/WORDPRESS_DIRECTORY/wp-content/uploads
    
  • Update directory owner on plugins and themes directories.
    chown -R www-data:www-data wp-content/plugins/
    chown -R www-data:www-data wp-content/themes/
    
  • Create the Nginx server configuration file /etc/nginx/sites-available/wordpress.
    server {
    	listen 80 default_server;
    	listen [::]:80 default_server ipv6only=on;
    
    	root /var/www/WORDPRESS_DIRECTORY;
    	index index.php index.html index.htm;
    
    	# Make site accessible from http://localhost/
    	server_name WORDPRESS_DOMAIN;
    
            client_max_body_size 50m;
    
    	location / {
    		# try_files $uri $uri/ =404;
    		try_files $uri $uri/ /index.php?q=$uri&$args;
    	}
    
    	error_page 404 /404.html;
    
    	# redirect server error pages to the static page /50x.html
    	#
    	error_page 500 502 503 504 /50x.html;
    	location = /50x.html {
    		root /var/www/WORDPRESS_DIRECTORY;
    	}
    
    	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    	#
    	location ~ \.php$ {
    		try_files $uri =404;
    		fastcgi_split_path_info ^(.+\.php)(/.+)$;
    		# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    	
    		# With php5-cgi alone:
    		#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;
    	}
    
    	# deny access to .htaccess files, if Apache's document root
    	# concurs with nginx's one
    	#
    	#location ~ /\.ht {
    	#	deny all;
    	#}
    }
    
  • Restart the server.
    sudo service nginx restart
    
  • If this is on your local server then add the following entry to you /etc/hosts file.
    127.0.0.1     WORDPRESS_DOMAIN
    
  • In your browser go the http://WORDPRESS_DOMAIN and set your Site Title, Username, Password and Email.
  • Instructions for setting up backups are here, WordPress Automatic Backups

References:

Leave a Reply

Your email address will not be published. Required fields are marked *