Archive for category How To

Install APC on OSX Snow Leopared

  1. sudo pear update-channels
  2. brew install pcre
  3. sudo pecl install apc-3.1.6
  4. Edit php.ini
    1. extension=apc.so
    2. apc.enabled=1
    3. apc.shm_segments=1
    4. apc.shm_size=32M
    5. apc.cache_by_default=1
    6. apc.stat=1
    7. apc.rfc1867=1 //For upload progress.
    8. apc.stat=7200 //2 hours

Installing Git on Westhost & Redhat

  1. Install Python using your web installs
  2. download the latest source from git
  3. make NO_CURL=1 NO_MSGFMT=YesPlease NO_TCLTK=YesPlease prefix=/usr/local install
  4. That should do it.

Setting up Apache & SSL on OSX Leapord

Task:
Configure my localhost & apache to allow for ssl.
Resources
  • http://shiningthrough.co.uk/Setting-up-an-SSL-enabled-Apache-development-server-using-Phusion-Passenger-on-OS-X-Snow-Leopard
  • http://www.modssl.org/
  • http://www.entropy.ch/software/macosx/docs/mod_ssl.html
Solution:
  • Go here: http://developer.apple.com/internet/serverside/modssl.html
  • Note: when asked for “Common Name” when creating your certificate file, instead of using the 127.0.0.1 use the domain name
    you are going to use for development. ie: www.mysite.local

    # This is the Apache server configuration file providing SSL support.
    # It contains the configuration directives to instruct the server how to
    # serve pages over an https connection. For detailing information about these
    # directives see
    #
    # Do NOT simply read the instructions in here without understanding
    # what they do.  They're here only as hints or reminders.  If you are unsure
    # consult the online docs. You have been warned.
    
    # Pseudo Random Number Generator (PRNG):
    # Configure one or more sources to seed the PRNG of the SSL library.
    # The seed data should be of good random quality.
    # WARNING! On some platforms /dev/random blocks if not enough entropy
    # is available. This means you then cannot use the /dev/random device
    # because it would lead to very long connection times (as long as
    # it requires to make more entropy available). But usually those
    # platforms additionally provide a /dev/urandom device which doesn't
    # block. So, if available, use this one instead. Read the mod_ssl User
    # Manual for more details.
    #
    #SSLRandomSeed startup file:/dev/random  512
    #SSLRandomSeed startup file:/dev/urandom 512
    #SSLRandomSeed connect file:/dev/random  512
    #SSLRandomSeed connect file:/dev/urandom 512
    
    #
    # When we also provide SSL we have to listen to the
    # standard HTTP port (see above) and to the HTTPS port
    #
    # Note: Configurations that use IPv6 but not IPv4-mapped addresses need two
    #       Listen directives: "Listen [::]:443" and "Listen 0.0.0.0:443"
    #
    Listen 443
    NameVirtualHost *:443
    
    ##
    ##  SSL Global Context
    ##
    ##  All SSL configuration in this context applies both to
    ##  the main server and all SSL-enabled virtual hosts.
    ##
    
    #
    #   Some MIME-types for downloading Certificates and CRLs
    #
    AddType application/x-x509-ca-cert .crt
    AddType application/x-pkcs7-crl    .crl
    
    #   Pass Phrase Dialog:
    #   Configure the pass phrase gathering process.
    #   The filtering dialog program (`builtin' is a internal
    #   terminal dialog) has to provide the pass phrase on stdout.
    SSLPassPhraseDialog  builtin
    
    #   Inter-Process Session Cache:
    #   Configure the SSL Session Cache: First the mechanism
    #   to use and second the expiring timeout (in seconds).
    #SSLSessionCache         "dbm:/private/var/run/ssl_scache"
    SSLSessionCache        "shmcb:/private/var/run/ssl_scache(512000)"
    SSLSessionCacheTimeout  300
    
    #   Semaphore:
    #   Configure the path to the mutual exclusion semaphore the
    #   SSL engine uses internally for inter-process synchronization.
    SSLMutex  "file:/private/var/run/ssl_mutex"
    
    ##
    ## SSL Virtual Host Context
    ##
    ServerName www.mysite.local
    ServerAlias www.mysite.local
    #   General setup for the virtual host
    DocumentRoot "/Users/markevans/Sites/www.mysite.com"
    ServerAdmin mark@mysite.com
    
    ErrorLog "/Users/markevans/Sites/logs/www.mysite.com/error_log"
    CustomLog "/Users/markevans/Sites/logs/www.mysite.com/ssl_request_log" \
    "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SSLCertificateFile /Users/markevans/Sites/sslcerts/www.mysite.com/server.crt
    SSLCertificateKeyFile /Users/markevans/Sites/sslcerts/www.mysite.com/server.key
    
  • Handy Degbugging Command lines

  • sudo apachectl configtest
  • http -S

Single .htaccess file in your git repo for both your dev and production server

Problem:

You want to have dev.yoursite.com and www.yoursite.com but you don’t want dev.yoursite.com visible to the public.

Solution:

If your using apache(which many of us are),

.htaccess and .htpasswd to the rescue.

In your .htaccess file add:

SetEnvIf Host yourstagingserver.com passreq AuthType Basic AuthName “Staging Server” AuthUserFile /path/to/.htpasswd Require valid-user Order allow,deny Allow from all Deny from env=passreq Satisfy any

Configure your password file on both dev & production

Wherever you specify the /path/to/.htpasswd file navigate to that folder from the console and type “htpasswd -c .htpasswd mark”   where mark is the first user you want to create a login for. For each additonal person type “htpasswd .htpasswd linda”  where linda is the next username you want to add to the .htpasswd file. Each time  it will  prompt you to type in the password twice.(your password will be stored in the .htpasswd file) encrypted next to the username you created.

*Note:

AuthUserFile expects an absolute path, but if you don't start your path with a forward slash, it defaults to the directory you specify in your httpd.conf file as ServerRoot.

Useful Rackspace Tutorials

Apache Configuration Virtual Hosts(sites-available & sites-active):

Security: (SSH Keys):
http://cloudservers.rackspacecloud.com/index.php/BasicCloudServerSecurity
IPTables :
http://cloudservers.rackspacecloud.com/index.php/Sampleiptables_ruleset
APT-GET Repositories : For some reason the ubunto distro 9.04 didn’t have these added to its apt-get sources.list. So I added them.
deb http://us.archive.ubuntu.com/ubuntu/ hardy universe deb-src http://us.archive.ubuntu.com/ubuntu/ hardy universe deb http://us.archive.ubuntu.com/ubuntu/ hardy-updates universe deb-src http://us.archive.ubuntu.com/ubuntu/ hardy-updates universe
Installing Ruby:
sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev mkdir ~/src && cd ~/src wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.gz tar -xvf ruby-1.9.1-p0.tar.gz cd ruby-1.9.1-p0 ./configure make make test sudo make install
Install Git Install Rails
sudo gem update –system sudo gem install rails
Install Ruby Mysql Modul
sudo gem install mysql

Install Pecl src : http://www.markfosteronline.com/2009/01/04/how-to-install-a-php-pecl-extensionmodule-on-ubuntu/

  • sudo apt-get install php-pear
  • sudo apt-get install php5-dev
  • sudo apt-get install libcurl4-openssl-dev
  • sudo pecl install pecl_http     just hit enter and use defaults

Monitor ETH Port

  • Use tcpdump -i eth0   to watch the ports
Install DTach – which allows you to run a session in a console, then dtach it, then go to another pc/console and attach.
  • apt-get install dtach
  • ex: dtach -A sessionname program arguments
    • press ctrl+\ to detach it from the terminal
    • then (from another computer or terminal) run “dtach -a sessionname”
  • ex:
    • dtach -A MyBashSession bash -l
    • [press ctrl+]
    • dtach -a MyBashSession
MySQL / Socket Not Found
  • sudo /etc/init.d/service mysql start
Install Zip
  • pecal install zip
  • * If it fails because of some error on expected = “” sudo apt-get install libpcre3-dev
Sources: http://rudygems.com/post/99075288/ruby-191-install

Linux command that are handy when configuring a new server

  • To view a user’s groups:
    “id [user]”
  • Add a user to a group :
    useradd -G {group-name} username
  • Add a user to multiple groups:
    usermod -a -G group1,group2 username
  • Change a users primary group:
    usermod -g group user
  • Add a group to a user
    usermod -a -G group user
  • Get a list of the groups:
    less /etc/group

OSX and Apache .htaccess allow mode rewrite

So today i had to get Apache, PHP and Mysql running again on my macbook after installing a new hardrive. PHP is installed already so thats fine. Mysql a simple download and install. I stick to the 32 bit for now as it not everything plays nicely w/ the 64 bit. Especially not with Python. Apache is naturally installed. Just need to turn on/off the internet sharing within the System Preferences Pane. Then comes the tricky part. In the http.conf file: ensure that the line including the ModRewrite module is uncommented. The line will look like this: LoadModule rewrite_module libexec/apache2/mod_rewrite.so Then go down to your system directive: And make it look like this: <Directory /> Options FollowSymLinks AllowOverride All # Order deny,allow # Deny from all </Directory> Also ensure that in the /etc/apache2/users/username.conf file that it looks like: <Directory "/Users/username/Sites/"> Options Indexes FollowSymLinks MultiViews AllowOverride all Order allow,deny Allow from all </Directory> Additionally when defining your Extra Virtual hosts: Make sure to enable all the error logs etc: ex: <VirtualHost *:80> ServerAdmin username@gmail.com DocumentRoot /Users/username/Sites/my.site.com ServerName local.site.com ServerAlias local.site.com RewriteLog "/Users/username/Sites/logs/my.site.com/rewrite_log" ErrorLog "/Users/username/Sites/logs/my.site.com/error_log" CustomLog "/Users/username/Sites/logs/my.site.com/access_log" common </VirtualHost>

How To: Setup Virtual Hosts on OS X

http://mark-kirby.co.uk/2008/setting-up-virtual-hosts-on-os-x-leopard/

Smush.it – Compress your images for the web

This plugin is now incorporated with YSlow, but run it on any one of your webpages, then download the new image files… Now you website will run faster and the image quality is still really good.

http://developer.yahoo.com/yslow/smushit/index.html