Migration from Apache to Nginx server

In this article I will generate the solution of migration from Apache to Nginx server with your wordpress or other web app.

I am using digital ocean VPS as my blog server. I had been using the Singapore line for a year and the lag was to much for me and also, the shadowsocks service was not good for it. So I decided to change the server to San Francisco.


Last night I just migrated my server to the new one. I also use LEMP as my server framework instead of LAMP.


Here is my experience of migrating the wordpress from Apache to Nginx server, I met some problems but I have fixed them so I want to post an artical about it.

  1. Install LEMP
  2. Export your wordpress or other app database and import to your new server by using phpmyadminYou might meet the problem of the upload max size.
    • Choose export with compress option
    • Change the max size of uploading file for the server(if your compressed file is also too big for the default server upload setting)


    This website will tell you what you need to do.


  3. Compress your wordpress or other app and upload to your new server.
  4. Import database to your new server by using phpmyadmin. (Note: You need to create a new database which has the same name as your old server.)Enter your new database and import your database.After that you might still cannot open your blog which might display database error, you need to check the privilege of your wordpress database, and you will find that you lost a wordpress user for your database, check the wp-config.php inside your wordpress folder, find the DB_USER and create a new user of your database, for me it is like this:wordpressuser preferenceafter that, you can open your blog without your specify website address.when you update your theme or plugin you will find that you need to offer your server’s ftp username and password, if you don’t know you will not to update.The way to solve it is to add a line in the wp-config.php:
    define('FS_METHOD', 'direct');

    This might not be the safest way, but it can solve the problem.

  5. Bind your server with the domain name

If you are using Nginx as me, you need to define a new domain name setting under the sites-available folder:

The format is simply declared in the default setting file. I will show you some example of it:

# 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.

# Default server configuration
server {
    listen 80;
    listen [::]:80;

    # SSL configuration
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    # include snippets/snakeoil.conf;

    root your_web_app_folder;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm;

    server_name your_domain_name;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php;

    # pass the PHP scripts to FastCGI server listening on
    # location ~ \.php$ {
    # 	include snippets/fastcgi-php.conf;
    # 	# With php5-cgi alone:
    # 	fastcgi_pass;
    # 	# With php5-fpm:
    # 	fastcgi_pass unix:/var/run/php5-fpm.sock;
    # }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    # location ~ /\.ht {
    #     deny all;
    # }
    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;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;



You may find that I set the

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php;

The reason that I set index.php is that I changed the permalinks of wordpress so the SEO plugin would map my sebsite better then before. But under Nginx you will find that the old posts will not be open so I found the solution in here.

Change to index.php will help you solve this problem.

I also create the new Nginx setting to solve my website’s domain name Skyfather1994.com, and blog.skyfather1994.com point to my blog.


So basically the migration of my server and web app(in this case is wordpress) from Apache to Nginx was done.

Also, you might find that you cannot open your blog but download a index.php of your wordpress folder, this problem annoyed me for more than an hour, the way to solve it is to clear the browser’s cache, pretty dumb and simple question.= =


Hope this post will help you figure out your problem.