This article shows the steps how we set up a PHP FastCGI interface on nginx and install phpMyAdmin on mysql.domain.com.
Install php5-cgi via aptitude on Ubuntu server:
sudo aptitude install php5-cgi sudo nano /etc/init.d/php-fastcgi
Add the following lines to ‘/etc/init.d/php-fastcgi’ to bind FastCGI on localhost at port 9000:
#!/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
Make the file executable
sudo chmod +x /etc/init.d/php-fastcgi sudo update-rc.d php-fastcgi defaults sudo /etc/init.d/php-fastcgi start
Install phpmyadmin via aptitude on our Ubuntu server:
sudo aptitude install phpmyadmin nano /etc/nginx/sites-available/domain.com
Add an entries to enable ‘mysql.domain.com’ by adding following lines into ‘/etc/nginx/zones/db.domain.com’:
mysql IN A 202.181.234.41
Add the following lines in existing ‘domain.com’ nginx config file:
server {
listen 80;
server_name mysql.domain.com;
access_log /var/log/nginx/mysql.domain.com.access_log;
error_log /var/log/nginx/mysql.domain.com.error_log warn;
root /usr/share/phpmyadmin;
index index.php;
fastcgi_index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
sudo ln -s /etc/nginx/sites-available/domain.com /etc/nginx/sites-enabled/domain.com
Set mysql root password if you haven’t done so:
mysql -u root
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
mysql -u root -p <-- If you have set a root password before
Great, our phpMyAdmin is here: ‘http://mysql.domain.com/’.
Related Posts
- Deploy Rails application via Git and Capistrano
- Setting Up your own DNS server with bind9
- Setting Up Ubuntu Server for Ruby on Rails Deployment
