Created
July 18, 2011 11:26
-
-
Save robwilliams/1089235 to your computer and use it in GitHub Desktop.
Hosting Wordpress Sites Using NGINX and FastCGI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add a user | |
adduser {USER} | |
# add user group | |
adduser {USER} www-data | |
# You will be prompted to enter a password | |
# Ssh in as that user to ensure that in the next steps you are setting permissions correctly | |
ssh {USER}@yourhost.com | |
# uncomment and set umask to 002 in ~/.profile | |
mkdir ~/public | |
mkdir ~/log | |
## Log back in as root (or run using sudo) | |
# Symlink to sites-enabled when ready | |
ln -s /etc/nginx/sites-available/{USER} /etc/nginx/sites-enabled/{USER} | |
# If MySQL is required: | |
mysql -u root -p | |
> create user {USER} identified by 'samepassword'; | |
> create database {USER}; | |
> GRANT all on {USER}.* to '{USER}'@'%'; | |
> exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The web server | |
apt-get install nginx | |
# The Database Server | |
apt-get install mysql-server | |
# PHP5 and required libraries | |
apt-get install php5 php5-mysql php5-cgi | |
# A FTP Server | |
apt-get install vsftpd | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name {DOMAIN}; | |
access_log /home/{USER}/log/access.log; | |
error_log /home/{USER}/log/error.log; | |
location / { | |
root /home/{USER}/public; | |
index index.php index.html index.htm; | |
# this serves static files that exist without running other rewrite tests | |
if (-f $request_filename) { | |
expires 30d; | |
break; | |
} | |
# this sends all non-existing file or directory requests to index.php | |
if (!-e $request_filename) { | |
rewrite ^(.+)$ /index.php?q=$1 last; | |
} | |
} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
location ~ \.php$ { | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /home/{USER}/public/$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make it Executable | |
chmod +x /etc/init.d/php-fastcgi | |
# Configure it to run on startup | |
update-rc.d php-fastcgi defaults | |
# Start it up now | |
service php-fastcgi start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment