To do this with your existing Wordpress droplet you would want to do the following:
1.) Install the additional required packages
apt-get update;
apt-get install nginx php5-fpm php5-gd libssh2-php
The nginx service will attempt to start up but will fail since Apache is currently using port 80. This is not a problem at this point.
2.) Next we need to update the php.ini for php5-fpm:
sudo nano /etc/php5/fpm/php.ini
You will want to look for cgi.fix_pathinfo. This will be commented out with a semi-colon (;) and set to “1” by default. Now change it to:
cgi.fix_pathinfo=0
3.) Now we can update the nginx configuration to work with php. Open the host configuration with:
sudo nano /etc/nginx/sites-available/default
and update the file so it appears like the one 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;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}<^>
}
The changes are highlighted.
- Next we can copy over the Wordpress files from the Apache web root to the nginx web root.
cp -Rf /var/www/html/* /usr/share/nginx/html/.
We will also want to make sure these files remain owned by www-data to prevent any permissions issues.
chown -Rf www-data.www-data /usr/share/nginx/html/*
5.) Your new nginx server should be all ready to run now, lets test and make sure by stopping the apache service and starting nginx
service apache2 stop;
service nginx start;
Now you can load your site in a web browser to ensure everything is working properly.
6.) Once you are sure that things are working properly you can remove apache
apt-get remove apache2;
and if you moved your MySQL services to another droplet as outlined in my previous reply you can also remove the MySQL service
apt-get remove mysql-server;
400 simultaneous users is quite a bit. I would recommend looking into the following options:
1.) Consider separating your MySQL and web services between two or more droplets
2.) Set up CloudFlare or another caching reverse proxy service to reduce the load on your droplet
We have a tutorial on scaling up Wordpress here as well which may be helpful.
Already using cloudfare … But still its there…
IS there any tutorials available for seperating mysql and webservices between two or more droplets?
I’ve outlined the process for you below. Following these steps will allow you to move your MySQL database to a separate droplet while retaining your current droplet to provide the web service.
1.) First you will want to create a second droplet using a base OS image. For the purposes of this walk-through I’d recommend Ubuntu or Debian.
2.) On your new droplet you will need to install MySQL
3.) On your new droplet edit the file /etc/mysql/my.cnf and change the bind_address line to your IP address. I recommend using your private IP address rather than the public one if you have private networking enabled on both droplets
4.) Now you will want to back up your MySQL database on your current Wordpress droplet. Log into it via ssh and get your root password from the file /root/.my.cnf then run
mysqldump -uroot -p wordpress > wordpress-backup.sql
This will create a file “wordpress-backup.sql” that contains your database.
5.) On your new MySQL droplet use the following commands to create your new database.
connect to mysql
create your new database
6.) Now we need to set up permissions for this database to be accessed remotely from your other droplet. Replace “webserver” with your other droplet’s IP address. If you are connecting via the private network this should be the private network IP.
In this case we are using your root user, you can also choose to create a separate user if you wish.
7.) Now, upload your wordpress-backup.sql to your new MySQL droplet and use the following command to import it.
8.) Your new database server is now ready to take over. There is only one more thing to do to make the switch, we will now update your Wordpress configuration to start using the remote MySQL droplet instead of the local MySQL server. Connect to your existing Wordpress droplet and in your web root edit the file wp-config.php and change the following section to reflect your new MySQL server with 0.0.0.0 being your private (or public) IP address on the new droplet and replacing “password” with the password you created.
9.) Once this change is made your site will immediately begin using the separate MySQL server instead of the local one so we can shut it down so those resources are available for your web service.
service mysql stop
In addition to this you may want to consider setting up CloudFlare for your domain as this will provide some caching and lessen the load on your web service. Additionally switching to a lightweight web server like nginx can also improve performance.
Thanks for the tutorial.. Can u also give the tutorial to move current wordpress site to nginx. SO that ican do both and test..
@ryanpq It will be very helpful if you give a tutorial to move current wordpress site to nginx..