I have done several installs of wordpress using apache and
php. Typically using this simple set of apt-get commands to install all the
tools I need for apache/php
> sudo apt-get install
apache2
> sudo apt-get install
php5-mysql
> sudo apt-get install
libapache2-mod-php5
> sudo apt-get install
imagemagick
> sudo apt-get install
php5-imagick
> sudo a2enmod rewrite
|
But now I am getting impressed with nginx I like the
configuration files better and its overall faster than apache (or so I have
been told).
A few good pages going over the speed differences on
apache vs nginx can be found at http://www.eschrade.com/page/why-is-fastcgi-w-nginx-so-much-faster-than-apache-w-mod_php/
[1] and http://www.organic-development.com/blog/apache-vs-nginx-performance-comparison.html
[2]
In this guide I am going to install wordpress, php, and
nginx all on aUbuntu 12.10 server.
Install nginx and fastCGI
A good place I got some notes from is http://ubuntuserverguide.com/2012/06/how-to-installing-nginx-with-php5-and-mysql-support-on-ubuntu-server-12-04-lts.html
[3]
> sudo
apt-get update
> sudo apt-get install nginx
> sudo apt-get install
spawn-fcgi
> sudo apt-get install
php5-cgi
> sudo apt-get install
php5-mysql
|
Set up the init script for fastCGI (I found this one at http://rockycode.com/blog/install-php-and-nginx-ubuntu/
[4] another good site going over this same install)
> sudo vi
/etc/init.d/php-fastcgi
|
And place the following into it and save it
#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000
PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename
$PHP_CGI`
PHP_CGI_ARGS="-
USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS
$PHP_CGI -b $BIND"
RETVAL=0
start()
{
echo -n "Starting PHP FastCGI:
"
start-stop-daemon --quiet --start --background
--chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
RETVAL=$?
echo "$PHP_CGI_NAME."
}
stop()
{
echo -n "Stopping PHP FastCGI:
"
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo "$PHP_CGI_NAME."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: php-fastcgi
{start|stop|restart}"
exit 1
;;
esac
exit
$RETVAL
|
Now make it executable and run at boot time
> sudo chmod 755
/etc/init.d/php-fastcgi
> sudo update-rc.d php-fastcgi
defaults
|
Update nginx
I am going to place my website in a directory I am going
to make /www I also made a /www/logs
folder to put site logs in
> sudo mkdir -p /www/main-site
> sudo mkdir -p /www/logs
|
Create a simple index.html file there for testing
> sudo vi
/www/main-site/index.html
|
<html>
<body>
<h1>Test</h1>
</body>
</html>
|
Now update /etc/nginx/nginx.conf
> sudo vi /etc/nginx/nginx.conf
|
Edit the document to the following (my server happens to be running on ip
address 192.168.0.11)
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
error_log /var/log/nginx/error.log;
events {
worker_connections
1024;
use epoll;
multi_accept on;
}
http {
include
/etc/nginx/mime.types;
default_type
application/octet-stream;
server {
listen 80;
keepalive_timeout 70;
server_name 192.168.0.11;
#Logs
access_log
/www/logs/main-site-access.log;
error_log
/www/logs/main-site-error.log;
# doc root
root
/www/main-site;
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/www/main-site$fastcgi_script_name;
include fastcgi_params;
}
}
}
|
Reboot
the server
> sudo reboot now
|
Success! Well at
least in as far as I proved nginx is running, I still need to test php.
Make a php file to test
> sudo vi /www/main-site/test.php
|
And put the following into it
<?php
phpinfo();
?>
|
Success! Nginx and
fastCGI is working!
Wordpress install
Now that nginx and fastCGI are working its time to get
back to installing and setting up a wordpress site.
Install/Setup MySQL
Install mysql on this
server
>
sudo apt-get install mysql-server
|
For the root password set it to “mysqlpassword”
Log into mysql
>
mysql -u root -p -h localhost
|
Set up WordPress MySQL user
>
CREATE DATABASE wp_database;
> GRANT ALL PRIVILEGES ON wp_database.* TO "wp_db_admin"@"localhost"
IDENTIFIED BY "wp_pass";
> FLUSH PRIVILEGES;
> exit
|
Download and install wordpress
> cd /www/main-site
> sudo wget wget http://wordpress.org/latest.tar.gz
> sudo tar -xvf latest.tar.gz
> sudo rm index.html
> sudo mv wordpress/* .
> sudo rm latest.tar.gz
|
Rename wp-config-sample.php
> sudo mv wp-config-sample.php
wp-config.php
|
Edit the wp-config.php file
> sudo vi wp-config.php
|
Edit the Database configuration
Update this portion
define('DB_NAME', 'wp_database');
/** MySQL database username */
define('DB_USER', 'wp_db_admin');
/** MySQL database password */
define('DB_PASSWORD', 'wp_pass');
|
Configure Wordpress
Oops I forgot to set up nginx to use index.php if it can't
find index.html.
Here is the fix for that….
You need to update the nginx.conf file
> sudo vi /etc/nginx/nginx.conf
|
You need to add try_files
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
error_log /var/log/nginx/error.log;
events {
worker_connections
1024;
use epoll;
multi_accept on;
}
http {
include
/etc/nginx/mime.types;
default_type
application/octet-stream;
server {
listen 80;
keepalive_timeout 70;
server_name 192.168.0.11;
#Logs
access_log
/www/logs/main-site-access.log;
error_log
/www/logs/main-site-error.log;
# doc root
root
/www/main-site;
index index.php
try_files $uri $uri/ /index.php;
location ~
\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/www/main-site$fastcgi_script_name;
include fastcgi_params;
}
}
}
|
Restart nginx
> sudo /etc/init.d/nginx restart
|
Success!! Well so far….
Enter a Site Tile, An
admin username, in this case I put admin.
Then enter in the password for this user. I entered in mypassword
Enter in the administrators email address and click Install
WordPress
Success! Wordpress
has been installed
Click on the "Log In" button
Enter the admin’s user name and password and click Log In.
Success!
There you have it, this is the admin page for wordpress
The admin’s page is located at
The normal site is located at
(Be sure to adjust the IP address/DNS name for your system)
As a test
The Wordpress default web site appears.
Now go customize your Wordpress and start adding your
posts.
Configure Wordpress email
I
like to install a SMTP email plugin to replace the default email behavior every
time I do a new install of wordpress.
Here
are my notes for doing just that.
There is a WP Mail SMTP plug in at http://wordpress.org/extend/plugins/wp-mail-smtp/
From the WP admin page
click on Plugins
Then click on Add New
Enter WP Mail SMTP and click Search Plugins
Select Install Now for
“WP Mail SMTP”
Success, click on
Activate Plugin
Click on Settings
Enter your Email address
and your From Name. Make sure “Send All
Wordpress emails via SMTP” is selected.
Enter your SMTP
information, including your username and password.
Click on Save changes.
If you use Gmail the
Settings would be
SMTP Host: smtp.gmail.com
SMTP Port: 465
Use SSL Encryption
Yes:
Use SMTP authentication
Username: your email address served by gmail
Password: your email password
To test the email enter
an email address and click “Send Test”
And here is the test
email I received.
This email tool now is
located in the Settings
References
[1] Why is FastCGI /w Nginx so
much faster than Apache /w mod_php?
Kevin Schroeder
Visited 6/2013
[2] Apache vs nginx
{performance comparison}
Visited 6/2013
[3] How to Installing Nginx with
PHP5-FastCGI and MySql Support on Ubuntu Server 12.04 LTS
Visited 6/2013
[4] Install PHP and
NGINX on Ubuntu
Visited 6/2013
No comments:
Post a Comment