Skip to content

Instantly share code, notes, and snippets.

@hackathi
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save hackathi/c06129e2d6c0857823f5 to your computer and use it in GitHub Desktop.

Select an option

Save hackathi/c06129e2d6c0857823f5 to your computer and use it in GitHub Desktop.
Automatic Phalanger 3 installer (Debian 7, Debian 8, Ubuntu)
#!/bin/bash -e
echo "=============================================================================
| Automatic Phalanger on Debian/Ubuntu installer |
|---------------------------------------------------------------------------|
| A few notes: |
| - Be sure to run this script as root. |
| - Downloading stuff can take a while |
| - Autohosting is enabled, so php files are automatically executed |
| - Tested on Debian 7 (wheezy) and Debian 8 (but should work on Ubuntu) |
| - Community product, if it breaks your server, well, your problem. |
| - fix this script if neccessary =) |
|===========================================================================|
PRESS RETURN TO CONTINUE"
read lol
echo "Testing for Phalanger binary archive precence"
if [ -e "Phalanger 3.0.0.4072 (bin).zip" ]
then
echo "Phalanger Binary package found, extracting..."
mkdir phalanger
mkdir phalanger/bin
mkdir phalanger/dynamic
touch phalanger/license.txt
mv "Phalanger 3.0.0.4072 (bin).zip" "phalanger/bin/phalanger.zip"
cd phalanger/bin
unzip phalanger.zip
cd ../..
else
echo "!!! Phalanger binaries not found. go to http://phalanger.codeplex.com/releases/view/103021 and download the latest binary package. Place it in the same directory as this script"
exit 42
fi
echo "Adding mono repositories - this will add a new key to your apt-key storage."
echo "read more info at http://www.mono-project.com/docs/getting-started/install/linux"
# add mono repository
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list
# Another repository is needed for Debian > 7, Ubuntu > 13.04
# related to Apache2.2 vs. 2.4
echo "Is this Debian 8, Ubuntu 13.10 or later?"
select sysversion in "Yes" "No"; do
case $sysversion in
"Yes" )
echo "deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list
break
;;
"No" )
break
;;
esac
done
echo "Updating aptitude package sources and installing dependancies..."
apt-get update
# Installing preconditions
# mono-complete is most likely not neccessary, but ensures that everything works (tm)
apt-get install mono-complete xmlstarlet apache2 libapache2-mod-mono
echo "Enter Phalanger installation directory: (default=/usr/local/lib/phalanger)"
read phalanger_folder
if [ "$phalanger_folder" == "" ]; then
phalanger_folder="/usr/local/lib/phalanger"
fi
cp -r "phalanger/bin" $phalanger_folder
cp -r "phalanger/dynamic" $phalanger_folder
cp -r "phalanger/license.txt" $phalanger_folder
chmod 777 $phalanger_folder/dynamic
echo "Enter Mono etc directory: (default=/etc/mono)"
read mono_etc_folder
if [ "$mono_etc_folder" == "" ]; then
mono_etc_folder="/etc/mono"
fi
echo "Enter target .NET Version"
select mono_net_version_a in "4.0" "4.5"; do
mono_net_folder=$mono_net_version_a
break
done
version="3.0.0.0"
machine_config="$mono_etc_folder/$mono_net_folder/machine.config"
public_key="0a8e8c4c76728c71"
public_key_lib="4af37afe3cde05fb"
public_key_ext="2771987119c16a03"
pars="-L"
# Remove previous phalanger version
#xmlstarlet ed $pars -d "/configuration/configSections[@name=phpNet]" $machine_config
#xmlstarlet ed $pars -d "/configuration/phpNet" $machine_config
#xmlstarlet ed $pars -d "/configuration/system.web/httpHandlers[@path=*.php]" $web_config
echo "Adding definition of phpNet section to machine.config..."
# Adding definition of phpNet section
xmlstarlet ed $pars -s "/configuration/configSections" -t elem -n "section" -v "" $machine_config
xmlstarlet ed $pars -s "/configuration/configSections/section[last()]" -t attr -n "name" -v "phpNet" $machine_config
xmlstarlet ed $pars -s "/configuration/configSections/section[last()]" -t attr -n "type" -v "PHP.Core.ConfigurationSectionHandler, PhpNetCore, Version=$version, Culture=neutral, PublicKeyToken=$public_key" $machine_config
echo "Adding Phalanger assemblies to the GAC..."
#Installing necessary assemblies into GAC
gacutil -i $phalanger_folder/bin/PhpNetCore.dll
gacutil -i $phalanger_folder/bin/PhpNetClassLibrary.dll
gacutil -i $phalanger_folder/bin/PhpNetXmlDom.dll
echo "Enabling mono apache modules..."
#Enabling mod_mono (if it already isnt)
a2enmod mod_mono mod_mono_auto
# bug in mono: autohosting uses mod-mono-server2, and it's hardcoded.
# in new Versions, this is not aviliable, so just create a symlink
ln -s /usr/bin/mod-mono-server4 /usr/bin/mod-mono-server2
echo "Should I add php support via Phalanger globally in apache?"
select register_globals in "Yes" "No"; do # pun intended
case $register_globals in
"Yes" )
echo "Adding .php type to mod_mono.conf"
echo "AddType application/x-asp-net .php" >> /etc/apache2/mods-enabled/mod_mono.conf
break
;;
"No" )
echo "Remember that you have to add the following manually to each virtual host that should have phalanger supported php!"
echo "AddType application/x-asp-net .php"
break
;;
esac
done
service apache2 restart
echo "done. Place the web.config skeleton in the root of your application and start enjoing Phalanger!"
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<httpHandlers>
<add path="*.php" verb="*" type="PHP.Core.RequestHandler, PhpNetCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=0a8e8c4c76728c71"/>
</httpHandlers>
<phpNet>
<compiler/>
<paths>
<set name="DynamicWrappers" value="/usr/local/lib/phalanger/dynamic"/>
<set name="Libraries" value="/usr/local/lib/phalanger/bin"/>
</paths>
<classLibrary>
<add assembly="PhpNetClassLibrary, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4af37afe3cde05fb" section="bcl"/>
<add assembly="PhpNetXmlDom, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2771987119c16a03" section="dom"/>
</classLibrary>
</phpNet>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment