How to install Nginx and WordPress on EC2 Ubuntu server

In this post i’ll explain how to install nginx and wordpress on an Ubuntu server.

* First make sure that your server’s security group allowes ports 80, 443.

Step 1: Installation

The first two commands are used to update the server’s sources and install all the neccesery utilities.

[root@ubuntu ~] apt-get update
[root@ubuntu ~] apt-get install nginx mysql-server php5-mysql php5-fpm

Next make sure the the nginx server is running:

[root@ubuntu ~] /etc/init.d/nginx start

At this point go to your browesr and enter the public ip of your server. you should something like this:

לכידה

Step 2: Creating the database:

Enter the database:

[root@ubuntu ~]mysql -u root -p

Enter the following commands (change the values as you like):

[root@ubuntu ~]CREATE DATABASE wordpress;
[root@ubuntu ~]CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
[root@ubuntu ~]GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
[root@ubuntu ~]FLUSH PRIVILEGES;

Step 3: Installation of wordpress: 

you can install the wordpress in any way you want, in this post I will install wordpress in the most easy simple messy way so just enter the following directory:

[root@ubuntu ~] cd /usr/share/nginx/html/

download the zip file from the official website:

[root@ubuntu ~] wget http://wordpress.org/latest.zip

unzip the files:

[root@ubuntu ~] unzip latest.zip

and move the fils to the html directory:

[root@ubuntu ~] mv wordpress/* .


4. Nginx configuration:

Now there’s a few changes we need to make in the configuration of the nginx. this is the most important part so make sure you’re doing it right.

[root@ubuntu ~] vi /etc/nginx/sites-enabled/default

In the configuration file I hightlighted the parts that you need to change so make sure that your file is exactly (!!) like mine. pay attention to the lines that are marked with #

# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts to this file

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

server {
 #listen 80 default_server;
 #listen [::]:80 default_server ipv6only=on;

 root /usr/share/nginx/html;
 index index.php;

 # Make site accessible from http://localhost/
 server_name localhost;

 location / {
 # First attempt to serve request as file, then
 # as directory, then fall back to displaying a 404.
 try_files $uri $uri/ /index.php;
 # Uncomment to enable naxsi on this location
 # include /etc/nginx/naxsi.rules
 }

 # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
 #location /RequestDenied {
 # proxy_pass http://128.0.0.1:8080;
 #}

 #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 /usr/share/nginx/html;
 #}

 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 location ~ \.php$ {
 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;
 #}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# root html;
# index index.html index.htm;
#
# location / {
# try_files $uri $uri/ =404;
# }

5. php configuration:

open the php configuration file:

[root@ubuntu ~] vi /etc/php5/fpm/php.ini
In this file find the parameter:

cgi.fix_pathinfo=0

make sure that it’s set to zero

 

6.Finishing touches: 

[root@ubuntu ~]/etc/init.d/php5-fpm restart
[root@ubuntu ~]/etc/init.d/nginx restart

* reload the webpage and follow the wordpress instructions.

 

 

 

Leave a Reply

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