Servers

From Wiki2

Servers

apt-get update
apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
mysql_install_db
apt-get install php5 libapache2-mod-php5 php5-mcrypt
apt-get install php5-cli php5-cli php5-dev php5-mysql php5-tidy php5-auth-pam
apt-cache search php5-
apt-get instal php-apc
service apache2 restart
apt-get install curl
sudo a2enmod rewrite
apt-get install phpmyadmin
service apache2 restart
apt-get update
curl -s http://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer.phar
alias composer='/usr/local/bin/composer.phar'

core files in ~tim/My Documents/tech/sites/CORE

git install

apt-get install git-core
git prompt

add to bottom of .bashrc

   source /etc/bash_completion.d/git-prompt 
   PS1=$PS1'$(__git_ps1 "\[\e[0;33m\](%s) \[\e[0m\]")'

and uncomment (at around line 39 in .bashrc)

  force_color_prompt=yes
setup .ssh

check for .ssh

 ls -a ~/.ssh

if not

 ssh-keygen -t rsa -C "mckenna.tim@gmail.com"

copy the public key to github/account/sshkeys

git config --global user.name "mckennatim"
git config --global user.email "mckenna.tim@gmail.com"


setup mediawiki

mysql

back to database

getRemoteDb.sh

#!/bin/sh
echo "getting database $1"
read -p "Enter Your Password: "  pwd
echo "Welcome $pwd!"

mysqldump -h sitebuilt.net -uroot -p$pwd --opt $1 > $1.sql
mysql -uroot -p$pwd $1 < $1.sql

setup MYSQL

1. in phpmyadmin create the databases

2. put the databases in /var/backups/my. go there and run

  mysql -p -u root sitebuil_wikidb < sitebuil_wikidb.sql
  mysql -p -u root sitebuil_wrdp1 < sitebuil_wrdp1.sql
  mysql -p -u root sitebuil_wuffdb < sitebuil_wuffdb.sql
  mysql -p -u root taxplans < taxplans.sql
  mysql -p -u root webeshoppin < webeshoppin.sql
  mysql -p -u root pathbost_h211 < pathbost_h211.sql
  mysql -p -u root pathbost_h311 < pathbost_h311.sql
  mysql -p -u root pathbost_h409 < pathbost_h409.sql
  mysql -p -u root pathbost_h409 < pathbost_h409.sql

get the latest from using wget, extract and rename

tar -xvf meediwiki...

change directory name \

mv mediawiki... wiki

mediawiki rewrite rules

if you want a setup like http://wiki.sitebuilt.net/Tobin ...

1. create subdomain in /etc/sites-available as in these directions

<VirtualHost *:80>
 ServerName wiki.sitebuilt.net
 DocumentRoot /home/wiki/public_html
 # Other directives here
</VirtualHost>

2. got0 http://shorturls.redwerks.org/ and follow the directions which ends up with in /etc/sites-available/wiki add

   RewriteEngine On
   RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
   RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
   RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/wiki/index.php [L]
   RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
   RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
   RewriteRule ^/?wiki/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/wiki/thumb.php?f=$1&width=$2 [L,QSA,B]
   RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
   RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
   RewriteRule ^/?wiki/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/wiki/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]

and at the bottom of localsettings.php add

 $wgScriptPath = "/wiki";
 $wgScriptExtension = ".php";
 $wgArticlePath = "/$1";

Subdomain

hsc setup

Setup rest rewrite rules

Add rewrite rules[edit] so a restful path /hsc/feeds/1234 (which doesn't really exist) sends you to the API which processes the request using the /feeds/12345 information from the path. load rewrite extension

sudo a2enmod rewrite
/usr/sbin/apache2ctl restart

In /etc/apache2/sites-available/default add rules like

   <Directory /var/www/hsc>
   	RewriteEngine On
   	RewriteRule feed/([0-9]+) /var/www/hsc/index.php?id=$1
   	RewriteRule feeds /var/www/hsc/index.php
   	RewriteRule datastreams /var/www/hsc/index.php?id=$1	
   	RewriteRule prog /var/www/hsc/index.php?id=$1		
   	RewriteRule progs /var/www/hsc/index.php?id=$1		
   </Directory>

remember to restart apache

  /usr/sbin/apache2ctl restart

backups

Scripts are in /usr/local/lib/tm/scripts

<syntaxhighlight lang = "php">

  1. !/bin/bash

_now=$(date +"%m_%d_%Y") _file="/var/backups/misc/bkp-rand_$_now.tar.gz" echo "Starting backup to $_file..." tar czvf $_file $(<file-dir-list.txt) php s3_db.php sitebuil_wuffdb php s3_db.php sitebuil_wikidb php s3_db.php sitebuil_wrdp1 php s3_db.php hsc php s3_db.php webeshoppin php s3_dir.php /var/backups/misc/ </syntaxhighlight>

http://olivier.sessink.nl/publications/hotcloning/ https://my.hostus.us/cart.php?a=confproduct&i=0


creating Subdomains[edit] useradd add user with name= first8letters of subdomain name goto https://manage.www.namecheap.com/myaccount/domain-list.asp ckt nanj and edit all host records subdomain | sitebuilt.net. | CNAME(alias) got /etc/apache2/sites-avalaible in /etc/apache2/sites-available create a file with the name subdomain.sitebuil <VirtualHost *:80>

ServerName subdomain.sitebuilt.net
DocumentRoot /home/username/public_html
# Other directives here

</VirtualHost> a2ensite subdomain.sitebuil (puts a link in sites-enabled) /etc/init.d/apache2 reload apache2ctl restart useradd - setting up accounts[edit] lastlog (lists all the users) useradd -d/home/newdir newdir (makeit <=8 char) passwd newdir create a publichtml and set permissions cd /home mkdir /newdir chmod 711 /home/newdir cd /home/newdir mkdir public_html chmod ugo+rx -R public_html apache etc/httpd.conf setup[edit] This is probably already done. Do this maybe if new install of server <IfModule mod_userdir.c> # # UserDir is disabled by default since it can confirm the presence # of a username on the system (depending on home directory # permissions). # #UserDir disable

# # To enable requests to /~user/ to serve the user's public_html # directory, remove the "UserDir disable" line above, and uncomment # the following line instead: # UserDir public_html

</IfModule>

  1. Control access to UserDir directories. The following is an example
  2. for a site where these directories are restricted to read-only.

<Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Limit Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> in /etc/apache2/sites-available create a file with the username <VirtualHost *:80>

DocumentRoot /home/abvbread/public_html
ServerName www.abvbreadandroses.info
# Other directives here

</VirtualHost> cd /etc/apache2/sites-enabled a2ensite webeshop (puts a link in sites-enabled) or do it manually - ln -s ../sites-available/webeshop webeshop /etc/init.d/apache2 reload sudo /etc/init.d/apache2 restart OR apache2ctl restart R http://198.23.156.78:8787/[edit] added cspan archive to /etc/apt/sources.list Invalid language. You need to specify a language like this: <source lang="html4strict">...</source> Supported languages for syntax highlighting:

[Expand] 

deb http://archive.ubuntu.com/ubuntu lucid main restricted universe deb http://archive.ubuntu.com/ubuntu lucid-updates main restricted universe deb http://archive.ubuntu.com/ubuntu lucid-security main restricted universe deb http://archive.canonical.com/ lucid partner deb http://archive.canonical.com/ lucid partner deb http://watson.nci.nih.gov/cran_mirror/bin/linux/ubuntu lucid/ installed R Invalid language. You need to specify a language like this: <source lang="html4strict">...</source> Supported languages for syntax highlighting:

[Expand] 
  sudo apt-get update
  sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
  sudo apt-get install r-base
  sudo apt-get install r-base-dev

installed rstudio http://198.23.156.78:8787/ Invalid language. You need to specify a language like this: <source lang="html4strict">...</source> Supported languages for syntax highlighting:

[Expand] 

$ sudo apt-get install gdebi-core $ sudo apt-get install libapparmor1 # Required only for Ubuntu, not Debian $ wget http://download2.rstudio.org/rstudio-server-0.97.312-i386.deb $ sudo gdebi rstudio-server-0.97.312-i386.deb you can add packages from the web rstudio Invalid language. You need to specify a language like this: <source lang="html4strict">...</source> Supported languages for syntax highlighting:

[Expand] 

doku[edit] to delete junk archive files

  1. find /home/sitebuil/public_html/doku/data/attic/ -type f -print0 | xargs -0r rm -f

Ubuntu 10.04 java[edit] Since $ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" DOESN'T WORK If you need the real Sun JRE you can: goto dir like /usr/local/src or wherever you put stuff you install that's not apt-get download java-jre with duinsoft's install script: gunzip it run the install script find out whereis (I found it got installed to /opt/java/32/jre1.7.0_09/bin/java) link to it from /usr/local/bin restart the shell so your computer can find it

  1. cd usr/local/src
  2. lynx http://www.duinsoft.nl/pkg/pool/all/update-sun-jre.bin
  3. gunzip update-sun-jre.bin.gz
  4. sh update-sun-jre.bin
  5. cd /usr/local/bin
  6. ln -s /opt/java/32/jre1.7.0_09/bin/java

execute-root-commands-via-php[edit] php include directory[edit] is where to put code that you want to run from multiple different directories. However it can't seem to be set in php.ini. The default is usr/share/php. In order to include files from /usr/local/share/php5/ I put a link in /usr/share/php/ to /usr/local/share/php5/chromephp/ChromePhp.php console log with ChromePhp.php[edit] now included in /usr/share/php files to see in console whatever you put in ChromePhp::log('hello world'); BTW tutn php consol logging on in top right of browser (blue is on) Invalid language. You need to specify a language like this: <source lang="html4strict">...</source> Supported languages for syntax highlighting:

[Expand] 

<?php include 'ChromePhp.php'; ChromePhp::log('hello world'); php error reporting to browser[edit] /etc/php5/apache2/php.ini links to development version that logs errors to browser.

allowing www-data user to write to directory[edit] usermod -a -G group1,group2 username Where username is the user you want to modify and group1 and group2 are the new groups you want that user to join. Running the command without the -a argument will remove that user from all groups except group1 and group2. groups sitebuil members cando chgrp -Rv cando /home/pathbost/public_html/ystill locate[edit] but first updatedb cron and backups[edit] php www-data program that creates a crontab and calls a C program that executes root commands to copy it into crontabs and install it current crontab in /var/spool/cron/crontab/pathbost Invalid language. You need to specify a language like this: <source lang="html4strict">...</source> Supported languages for syntax highlighting:

[Expand] 

  1. m h dom mon dow command
  2. backup MYSQL databases every 4 days (starting at 3:00AM)

00 3 */4 * * cd /home/sitebuil/scripts/S3-Site-Backups; php s3cli_backupDb.php sitebuil_wikidb 05 3 */4 * * cd /home/sitebuil/scripts/S3-Site-Backups; php s3cli_backupDb.php sitebuil_wrdp1 10 3 */4 * * cd /home/sitebuil/scripts/S3-Site-Backups; php s3cli_backupDb.php sitebuil_wuffdb 15 3 */4 * * cd /home/sitebuil/scripts/S3-Site-Backups; php s3cli_backupDb.php taxplans 20 3 */4 * * cd /home/sitebuil/scripts/S3-Site-Backups; php s3cli_backupDb.php webeshoppin

  1. Delete all local backups older than 3 weeks (at 2am)

00 2 * * * find /var/backups/backup/*.gz -ctime +21 -type f -print | xargs rm -f crontab to delete files older than 21 days

  1. Delete all local backups older than 3 weeks (at 2am)

00 2 * * * find /PATH/TO/HOME_DIR/backups/*.gz -ctime +21 -type f -print | xargs rm -f

  1. Run it every three days...

0 0 */3 * * cron tutorial another Re: Where is crontab stored? Root-level crontab should be in /etc/crontab. Root-level anacron and periodics should be in /etc/cron* User-level crontabs should be in /var/spool/cron/crontabs - they are listed by user, pathbost isactually a chrontab select-editor installing and testing a crontab[edit] installing[edit] even after you change it by yourself you can install it by running as root sudo crontab -u pathbost /var/spool/cron/crontabs/pathbost testing[edit]

  • * * * * /bin/echo " pathGZoobar $(date) " >> /usr/local/docs/testcron.txt

will append this every minute to testcron.txt

pathGZoobar Thu Jan  3 14:15:01 EST 2013

You can check the logs to see if the crontab got installed/executed by running as root sudo tail /var/log/syslog vi with crontab 101[edit] su to user then 'crontab -e' 'i' to insert text 'esc :wq to save change, and quit then crontab is installed 'esc :q!' exits without saving (or installing) you can kill your crontab with crontab -r you can list the installed crontab with crontab -l backup to s3[edit] Backups have a 30 day life on s3 and a 21 day life in /var/backups/backup backup_to_S3 code directory backup[edit] To backup a directory run this from the terminal: sudo php /home/sitebuil/scripts/S3-Site-Backups/s3cli_backupDir.php /home/sitebuil/public_html/doku doku database backup[edit] sudo php php /home/sitebuil/scripts/S3-Site-Backups/s3cli_backupDb.php sitebuil_wiki or goto http://pathboston.com/zstill/stillwater.html refs[edit] http://www.cenolan.com/2008/05/simple-linux-to-amazon-s3-backup-script/ http://www.alvechurchdata.co.uk/softhanoi.htm http://s3tools.org/s3cmd http://tagmycode.com/snippet/480/backup-mysql-database-to-amazon-s3-with-s3cmd-on-debian#.UMifCoP2GSo http://docs.amazonwebservices.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html http://en.wikipedia.org/wiki/Backup_rotation_scheme managing-cron-jobs-with-php-2 GOOD http://www.prosoxi.com/2012/12/14/php-crontab-class-to-add-edit-and-remove-cron-jobs/ s3 backup with s3napback string meaning

  ------ -------
  @reboot Run once, at startup
  @yearly Run once a year, "0 0 1 1 *"
  @annually (same as @yearly)
  @monthly Run once a month, "0 0 1 * *"
  @weekly Run once a week, "0 0 * * 0"
  @daily Run once a day, "0 0 * * *"
  @midnight (same as @daily)
  @hourly Run once an hour, "0 * * * *"

password protecting directories[edit] Directories that are password protected are in /etc/apache2/sites-avalable pathbost and sitebuil visitor statistics[edit] http://www.hping.org/visitors/doc.html visitors --output text -A -m 30 /var/log/apache2/access.log -o html >home/sitebuil/public_html/files/webstats.html visitors --output text -A -m 30 /var/log/apache2/other_vhosts_access.log --trails --prefix http://sitebuilt.net -o html > /home/sitebuil/public_html/files/webstatsSBS.html visitors --output text -A -m 30 /var/log/apache2/other_vhosts_access.log --trails --prefix http://pathbost.com -o html > /home/sitebuil/public_html/files/webstatsPATH.html visitors --output text -A -m 30 /var/log/apache2/other_vhosts_access.log --trails --prefix http://levelthefield.us -o html > /home/sitebuil/public_html/files/webstatsLTF.html other software[edit] that doesn't get put somewhere automatically Put source.taz.gz under /usr/local/src From /usr/local/bin creagte a link ln -s ../src/srcdir/compiledbin securing phpmyadmin[edit] https://nearwater (works only from tims laptop) http://paynedigital.com/2011/09/setting-up-and-securing-a-phpmyadmin-install-on-ubuntu-10-04 1. setting up ssl certificate mkdir /etc/apache2/ssl openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.key 2. mv phpmyadmin.conf inside a virtual host and put it in sites-available mv /etc/apache2/conf.d/phpmyadmin.conf /etc/apache2/sites-available/ 3. edit take out Alias, add virtual host and put in new credentials (pem and key) 4. got /etc/apache2/sites-enables and enable it ln -s ../sites-available/phpmyadmin.conf 5. goto /etc/apache2/ports.conf and add NameVirtualHost 198.23.156.78:443 6. restart apache /usr/sbin/apache2ctl restart put a host file entry in windows or from wherever you wan to get to this host /windows/system32/drivers/etc/hosts 198.23.156.78 nearwater moving databases[edit] copies as of 12/2012 of databases are on windows machine /documents/sites/mysqldumps In phpmyadmin of the target mnachine create a user with same nae as source user and put the source ip as host. Create the (empty)databases on the target root@server1 /var/backups# mysql -u root -p -h localhost pathbost_assess < pathbost_assess.sql root@10.194.101.169: home$ mysqldump -utim -pnji9ol pathbost_h409 | mysql -h198.23.156.78 -utim -pnji9ol pathbost_h409 mysqldump -utim -pnji9ol pathbost_poets | mysql -h198.23.156.78 -utim -pnji9ol pathbost_poets To copy directories from old vps to new root@10.194.101.169: home$ rsync -aHvz /home/pathbost/public_html root@198.23.156.78:/home/pathbost installed lamp stack using https://help.ubuntu.com/community/ApacheMySQLPHP

Run, Stop, Test, And Restart Apache Use the following command to run Apache : $ sudo /usr/sbin/apache2ctl start $ sudo /usr/sbin/apache2ctl stop $ sudo /usr/sbin/apache2ctl configtest $ sudo /usr/sbin/apache2ctl restart Mysql Commented out # bind-address = 127.0.0.1 in /etc/mysql/my.cnf so as to access db from any server $ restart mysql