HOW TO install WordPress with Ubuntu 14.04 AWS instance with LEMP latest version
Launch the AWS instance in desire region/location (need port 22 and 80 open for all)
Access the instance by SSH
Step 1 - Install NGINX latest (stable) version
Update the Ubuntu
$sudo apt-get update
Get the repo for latest version of Nginx
Edit the file below;
$sudo vi /etc/apt/sources.list
Append at the end of the file
deb http://nginx.org/packages/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/ubuntu/ trusty nginx
Update the repository
$sudo apt-get update
If a W: GPG error: http://nginx.org/packages/ubuntu xenial Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY $key (ABF5BD827BD9BF62) is encountered during the NGINX repository update, execute the following:
$sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 'Enter the Key value from above error (ABF5BD827BD9BF62)'
Update the repository again
$sudo apt-get update
Install the nginx server, you will get the latest version of nginx stable.
$sudo apt-get install nginx
Verify the installation by accessing your server by IP address http://webserver_ip/ in any browser to see the Welcome Nginx page
Read more about the
NGINX tuning for better performance.
Step 2 - Install Mysql server
$sudo apt-get install mysql-server
It will prompt for mysql root password, type twice with confirmation and to complete the setup
tell MySQL to generate the directory structure it needs to store its databases and information. We can do this by typing:
$sudo mysql_install_db
Secure your mysql by using below command, this will prompt some questions, answers accordingly.
$sudo mysql_secure_installation
Suggestion, remove the root access from remote and remove the test mysql db.
you will be prompted to remove some test users and databases. You should just hit "ENTER" through these prompts to remove the unsafe default settings.
Step 3 - Install the PHP
$sudo apt-get install php5-fpm php5-mysql php5-gd libssh2-php
To secure the PHP, open the below file
$sudo vi /etc/php5/fpm/php.ini
Look for the parameter that sets cgi.fix_pathinfo. This will be commented out with a semi-colon (;) and set to "1" by default. Change both of these conditions by uncommenting the line (remove the semi-colon from front of the line and setting the value to "0".
cgi.fix_pathinfo=0
Save and close the file
Restart the PHP5
$sudo service php5-fpm restart
Now, configure the Nginx to use the PHP5.
Delete the default nginx config file which comes with nginx installation.
$sudo rm /etc/nginx/conf.d/default.conf
Create the file by name of your website to locate easily
$sudo vi /etc/nginx/conf.d/'website.conf'
Create a new file with below details;
server {
listen 80;
server_name www.websitename.com;
access_log /var/log/nginx/'websitename'.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.php index.htm;
}
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$ {
root html;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000; # or use fastcgi_pass unix:/var/run/php5-fpm.sock
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #Verify the root path
include fastcgi_params;
}
}
CREATE a test page to verify the settings of installed PHP and Nginx Configuration.
$sudo vi /usr/share/nginx/html/info.php
Add below lines to the file
<?php
phpinfo();
?>
Save and exit from the info.php file.
Restart the nginx service
$sudo service nginx restart
*If fail restart the PHP5-FPM service too
Try to access the file in browser http://webserver_ip/info.php
Step 4 - Create DB for WordPress;
Create mysql DB;
$mysql -u root -p
Use root password to get inside of the database.
> CREATE DATABASE wordpress;
Create user to access the newly created database;
> CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
Allow db user to access the newly created db;
> GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
Flush the privileges
> FLUSH PRIVILEGES;
Exit the database
> \q
Step - 5 Download and Configure WordPress
$ wget http://wordpress.org/latest.tar.gz
untar the downloaded file
$ tar -xzvf latest.tar.gz
This will create folder 'wordpress'. Move this folder to document root.
$ sudo rsync -avP ~/wordpress/ /usr/share/nginx/html/
go to the wordpress folder;
$ sudo cd /usr/share/nginx/html
create a copy of wp-config-sample.php to wp-config.php
$ sudo cp wp-config-sample.php wp-config.php
Edit the new file
$ sudo vi wp-config.php
Make changes as needed;
/** 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 exit the file.
Create a 'uploads' directory under 'wp-content' folder.
$ sudo mkdir wp-content/uploads
Change the ownership and permission for the location /usr/share/nginx/html/
$ sudo chown -R www-data:www-data /usr/share/nginx/html
$ sudo chmod -R 775 /usr/share/nginx/html
$ sudo chmod g+s /usr/share/nginx/html # this will enforce the directory permission to default www-data, this will help if you upload anything on wp-content/uploads folder the permission will change to www-data instead defualt username.
$ sudo find /user/share/nginx/html -type d -exec chmod g+s {} +
This will make all newly created files inherit the parent directory's group, instead of the user's.
If there is any default 'index.html' file in above location, please remove or rename it.
Visit URL by webserver IP address (or DNS name if you have set) to continue with WordPress installation.
http://webserever_ip/
Once installation complete the setup will take you to admin page of the WordPress
http://webserver_ip/wp-admin
Use the same admin user and password which you have configured while installing the WordPress.
Enjoy the worlds most popular blogging engine, WordPress.
Comments
Post a Comment