This time i want to talk how to Install WordPress on Ubuntu Server using Nginx, PHP, MySQL. If during the time we are familiar with Apache web server, now in writing this time I do not use Apache as web server, but using Nginx.
Please read and read Apache vs Nginx: Web Server Performance Deathmatch to know a little performance comparison between Apache and Nginx.
Immediately, we practice, let’s …
Install the necessary software (nginx, php, mysql, compiler, and additional software)
1 |
$ sudo apt-get install build-essential linux-headers-$(uname -r) psmisc wget mysql-server mysql-client libmysqlclient15-dev php5-cli php5-cgi php5-mysql php5-xcache nginx libpcre3-dev libbz2-dev |
1. Nginx Configuration
Edit nginx configuration in order to be run as we expected.
1 |
$ sudo vim /etc/nginx/sites-available/default |
1 2 3 4 5 6 7 |
server { listen 202.xxx.xxx.xxx; # input the ip server server_name serverku.com; # input the hostname server access_log /var/log/nginx/localhost.access.log; location / { root /var/www/nginx-default; index index.html index.htm index.php; # add <a href="http://www.info-vijesti.com/">index</a>.php |
Then uncomment the sections below:
1 2 3 4 5 6 |
location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; include /etc/nginx/fastcgi_params; } |
Spawn-fcgi configuration
We can use the spawn-fcgi lighttpd, so it means you have to build from source to get its binary.
1 2 3 4 5 6 7 |
$ wget http://www.lighttpd.net/download/lighttpd-1.4.19.tar.bz2 $ tar jxvf lighttpd-1.4.19.tar.bz2 $ cd lighttpd-1.4.19 $ ./configure $ make $ sudo cp src/spawn-fcgi /usr/bin/spawn-fcgi $ sudo rm -rf lighttpd-1.4.19 lighttpd-1.4.19.tar.bz2 |
Create a script to run spawn-fcgi
1 |
$ sudo vim /usr/bin/php-fastcgi |
1 2 |
#!/bin/sh /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -f /usr/bin/php5-cgi |
1 |
$ sudo vim /etc/init.d/init-fastcgi |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/bin/bash PHP_SCRIPT=/usr/bin/php-fastcgi RETVAL=0 case “$1″ in start) $PHP_SCRIPT RETVAL=$? ;; stop) killall -9 php RETVAL=$? ;; restart) killall -9 php $PHP_SCRIPT RETVAL=$? ;; *) echo “Usage: php-fastcgi {start|stop|restart}” exit 1 ;; esac exit $RETVAL |
Give 755 permissions for the script can be executed.
1 2 |
$ sudo chmod 755 /usr/bin/php-fastcgi $ sudo chmod 755 /etc/init.d/init-fastcgi |
Running init-FastCGI and settings for this script is executed when the server machine on reboot.
1 2 |
$ sudo /etc/init.d/init-fastcgi start $ sudo update-rc.d init-fastcgi defaults |
Start the service nginx
1 |
$ sudo /etc/init.d/nginx start |
Test setup nginx + php + mysql configuration using phpinfo.
2. MySQL Configuration
Make sure the MySQL server service is running well.
1 2 3 4 5 6 7 8 9 10 |
$ mysql -u root -p Enter password: mysql> CREATE DATABASE wordpress; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON wordpress.* TO “wordpressusername”@”hostname” -> IDENTIFIED BY “password”; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) mysql> EXIT |
3. Instalasi WordPress
1 2 3 4 5 |
$ wget http://wordpress.org/latest.tar.gz $ tar -xzvf latest.tar.gz $ sudo mv wordpress /var/www/nginx-default/ $ cd /var/www/nginx-default/wordpress $ sudo cp wp-config-sample.php wp-config.php |
Edit customize wordpress configuration settings database which we have set previously.
1 |
sudo vim wp-config.php |
1 2 3 4 5 6 7 |
define(‘DB_NAME’, ‘wordpress’); /** MySQL database username */ define(‘DB_USER’, ‘wordpressusername’); /** MySQL database password */ define(‘DB_PASSWORD’, ‘password’); /** MySQL hostname */ define(‘DB_HOST’, ‘localhost’); |
Once saved, navigate your browser to http://server_nginx/wordpress/wp-admin/install.php, if we are doing right setting, it will show the wizard for the installation of wordpress, please follow the wizard to finish and tutorial how to Install WordPress on Ubuntu Server using Nginx, PHP, MySQL is finish too :d