php_installed=`dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
# remove all php packge
sudo aptitude purge $php_installed
php_installed=`dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
sudo aptitude purge $php_installed
apt-get install python-flup nginx subversion python-mysqldb
nano /etc/nginx/nginx.conf
user www-data; worker_processes 1; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; # multi_accept on; } http { include /etc/nginx/mime.types; access_log /var/log/nginx/access.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; gzip_comp_level 6; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
nano /etc/nginx/sites-available/foo.com server {
listen 80;
server_name www.foo.com foo.com;
if ($host != 'foo.com') {
rewrite ^/(.*)$ http://foo.com/$1 permanent;
}
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
fastcgi_pass 127.0.0.1:7718;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
}
location /robots.txt {
alias /www/foo/media/robots.txt;
}
location /site_media/ {
expires 7d;
alias /www/foo/media/;
}
location /media/ {
alias /www/env/lib/python2.6/site-packages/django/contrib/admin/media;
}
} ln -s /etc/nginx/sites-available/foo.com /etc/nginx/sites-enabled/foo.com
sudo /etc/init.d/nginx restart python /www/foo/manage.py runfcgi host=127.0.0.1 port=7718 pidfile=/www/foo/foocom.pid maxspare=2
python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
apt-get install python-setuptools
easy_install pipThen
pip install virtualenv
pip install virtualenvwrapper
nano ~/.bashrc
# virtualenvwrapper
export WORKON_HOME=~/.virtualenvs
source /usr/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true
source ~/.bashrc
mkdir ~/.virtualenvs
mkvirtualenv --no-site-packages myenv
workon myenv
pip install PinaxAnd replicate a project:
pinax-admin setup_project -b social myproj
To repair, just issue this command:
Man pagemysqlcheck -uroot -pxxxxx --auto-repair --optimize --databases your_db
is a perl script for mysql optimization.
wget http://mysqltuner.com/mysqltuner.pl
chmod +x mysqltuner.pl
./mysqltuner.pl
I acheived amazing performance boost (server load dropped form 10 to 1) following the suggestions of this script, i.e.:
General recommendations:
Add skip-innodb to MySQL configuration to disable InnoDB
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Enable the slow query log to troubleshoot bad queries
Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
query_cache_size (> 64M)
table_cache (> 64)
touch /etc/nsd3/nsd.confCheck these to figure out how to set up php5-fpm : (in case the instructions in the first link not works, install fpm from source, as describe in howtoforge )
apt-get install nsd3
apt-get install nginx
mkdir -p /srv/mysite
adduser rootuser
usermod -G www-data rootuser
mysql -u root -p
CREATE DATABASE mysitedb;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON mysitedb.* TO 'mysiteuser'@'localhost' IDENTIFIED BY 'password#';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON mysitedb.* TO 'mysiteuser'@'localhost.localdomain' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
quit;
cd /srv/mysite
wget http://ftp.drupal.org/files/projects/drupal-6.20.tar.gz
tar zxvf drupal-6.20.tar.gz
mv drupal-6.20/* .
rm -r drupal-6.20 drupal-6.20.tar.gz
cd sites/default/
cp default.settings.php settings.php
chown www-data:www-data settings.php
chmod 775 settings.php
mkdir files
chown www-data:www-data files
chmod 775 files
sudo apt-get install libevent-devInstall memcached:
Create control script:mkdir src cd src wget http://memcached.googlecode.com/files/memcached-1.4.0.tar.gz tar xzvf memcached-1.4.0.tar.gz cd memcached-1.4.0 ./configure make sudo make install cd ..
Add the following code:sudo nano /usr/local/bin/memcache.sh
240 is the memory limit for the instance of memcached, the unit is MB.#!/bin/sh case "$1" in start) /usr/local/bin/memcached -d -u root -m 240 -p 11211 ;; stop) killall memcached ;; esac
make it executable :start a memcached instance when the server startup:
sudo chmod +x /usr/local/bin/memcache.sh
add:sudo nano /etc/rc.local
start a memcached instance by running:/usr/local/bin/memcache.sh start
/usr/local/bin/memcache.sh start
install PECL memcache :apt-get install php-pear
Edit the php.inipecl install Memcache
add "extension=memcache.so" to it.nano/etc/php5/fpm php.ini file:
note: you may place './sites/all/modules/memcache/memcache.inc' with 'cache_inc' => './sites/all/modules/memcache/memcache.db.inc' to cache data both to memory and database if your memcache's memory limit is small or the memcached instance go offline often. (See the README.txt of Memcache API and Integration for more details. )$conf = array( 'cache_inc' => './sites/all/modules/memcache/memcache.inc', );
apt-get install postfixnano /etc/postfix/main.cnf
mydestination = mydomain.com, localhost.mydomain.com, localhost
to
mydestination = localhost.mydomain.com, localhostReboot the server. Done!
There you have it! Python 2.5.5 is installed. Now if you want to run it, you can type python2.5 from the terminal.sudo apt-get install build-essential gcc cd Downloads wget http://www.python.org/ftp/python/2.5.5/Python-2.5.5.tgz tar -xvzf Python-2.5.5.tgz cd Python-2.5.5 ./configure --prefix=/usr/local/python2.5 make make test sudo make install sudo ln -s /usr/local/python2.5/bin/python /usr/bin/python2.5
sudo apt-get install python-setuptools
We need to use sudo here because it has to install to a global location. Don’t worry, this is the last time we’ll need to do something as root.sudo easy_install virtualenv
In this instance I’ve chosen venv as the name for my virtual environment. The —no-site-packages command tells virtualenv not to symlink the global site packages into my local environment, just take the Python standard library. This is important, because it helps us avoid the dependency difficulties mentioned above.virtualenv --no-site-packages venv
echo "venv" >> .gitignore
And it’s done. easy. You might also want to install the MySQL bindings and IPython for ease of use:./venv/bin/easy_install django
To start a new Django project, you’ll note that a django-admin.py file will have been installed for you in the environment:./venv/bin/easy_install ipython python-mysql
Obviously you can skip this step if you have an existing Django project../venv/bin/django-admin.py startproject myapp
cd myapp
../venv/bin/python manage.py runserver 0.0.0.0:8000And you’re away!