Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Major code improvements

Testing Purposes Only

Added update_php.sh. This is an early version of a script to update PHP.

This version is untested. Changes will occur.

Fixed some function calls.

Changed how CONFIGURE_ARGS is defined.

Piped the output of the old command to sed to remove the single quotes returned by php -i. This allows the configure script to proceed without errors.

Added first attempt at an APC update script. Needs testing.

Update scripts for apc and php

Update README.mkd

Updated README

No need for git-core (git should fine). Added progress on Setting up PHP

Major improvements

Minor fixes

Added an NginX choice between stable and dev

wip

Update README
  • Loading branch information...
commit 53699ee00e6a5fac46a7d4bf43efb44fbe93813c 1 parent c1aa513
Vlad authored
View
22 README.mkd
@@ -1,6 +1,6 @@
This package represents a script to install the latest NginX, MySQL and PHP (with APC and Suhosin):
- * NginX 1.1.14
+ * NginX 1.1.14 (development) or 1.0.12 (stable)
* PHP 5.3.10
* APC 3.1.9
* Suhosin Extension 0.9.33
@@ -16,7 +16,7 @@ This is tested with Ubuntu 10.04 and 11.10, both 32 bits and 64 bits, on officia
Make sure you have Git installed on your Ubuntu System:
- sudo apt-get install git-core screen
+ sudo apt-get install git screen
Clone this repository, and get the latest stable version of this script:
@@ -34,13 +34,17 @@ Also, if you go to:
* **http://example.com/nginx_status** for the NginX statistics;
* **http://example.com/status?html** for the FPM statistics.
+In order to have imediate access to new paths you should also execute `source /etc/environment`. This command reloads the new environment variables.
+
# Utilities: #
In the "ext" folder you will also find some utilities:
* `nxensite` and `nxdissite` commands to enable or disable sites in NginX (similar to a2ensite and a2dissite in Apache).
-* `update_nginx.sh` script which can upgrade the current nginx.
- * you can run it with `sudo env PATH=$PATH ext/update_nginx.sh 1.0.4` (as you can see there are a few things worth mentioning: you need to declare the current path to the sudo command in order to preserve it; you can only have one argument in a strict form x.x.x; )
+* `update_nginx.sh` script which you can use to upgrade the current nginx.
+ * you can run it with `sudo env PATH=$PATH bash ext/update_nginx.sh 1.0.4` (as you can see there are a few things worth mentioning: you need to declare the current path to the sudo command in order to preserve it; you can only have one argument in a strict form x.x.x; )
* this script is doing nothing more than reconstructing you current nginx config with the new version. It gets the previous configure options programmatically so if you used 3rd party modules it will not work. Also it saves the current config files and brings them back after the compilation was successful.
+* `update_php.sh` - upgrades the current php (`sudo env PATH=$PATH bash ext/update_php.sh 5.3.10`).
+* `update_apc.sh` - upgrades the current apc (`sudo env PATH=$PATH bash ext/update_apc.sh 3.1.19`).
####If you find this interesting and you want to keep the development active, please click on the button below to donate:###
<div style="text-align: center;"><a href='http://www.pledgie.com/campaigns/16676'><img alt='Click here to lend your support to: LEMP Stack and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/16676.png?skin_name=chrome' border='0' /></div>
@@ -55,6 +59,16 @@ In the "ext" folder you will also find some utilities:
## Release Notes: ##
+### 4.01 ###
+
+ * Added the option to choose wich nginx release you wish to install.
+ * Added a script to update php.
+ * Added a script to update apc.
+ * Major code improvements.
+ * Improved the update nginx script.
+ * Fixed timezone issues with newest php version.
+ * Other minor fixes.
+
### 3.19 ###
* Upgraded PHP to version 5.3.10.
View
107 ext/update_apc.sh
@@ -0,0 +1,107 @@
+#!/bin/bash
+#
+###################################################################
+# Script to change APC version. #
+# February 12, 2012 Vlad Ghinea. #
+###################################################################
+#
+# Needs to be called with the version number as argument and also
+# with "sudo env PATH=$PATH" in front to preserve the paths.
+#
+# ex: $ sudo env PATH=$PATH bash update_apc.sh 3.1.9
+#
+# Get APC Version as a argument
+ARGS="$@"
+
+# Traps CTRL-C
+trap ctrl_c INT
+function ctrl_c() {
+ echo -e '\nCancelled by user'; if [ -n "$!" ]; then kill $!; fi; exit 1
+}
+
+die() {
+ echo "ERROR: $1" > /dev/null 1>&2
+ exit 1
+}
+
+check_sanity() {
+
+ # Check if the script is run as root.
+ if [ $(/usr/bin/id -u) != "0" ]
+ then
+ die "Must be run by root user. Use 'sudo env PATH=\$PATH bash ...'"
+ fi
+
+ # A single argument allowed
+ [ "$#" -eq 1 ] || die "1 argument required, $# provided"
+
+ # Check if version is sane
+ echo $1 | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+$' || die "Version number doesn't seem right; Please double check: $1"
+
+ APC_VER="$1"
+ DATE=`date +%Y.%m.%d`
+ SRCDIR=/tmp/apc_$APC_VER-$DATE
+ # Get php executable's path
+ PHP_CMD=$(type -p php)
+ # Get phpize's path
+ PHPIZE=$(type -p phpize)
+ # Get php-config's path
+ PHP_CONFIG=$(type -p php-config)
+ # Get libraries' path
+ LIBDIR=$(php -i | grep include_path | cut -d ' ' -f3 | sed 's/^\.\://')
+
+ # Store the configure args.
+ CONFIGURE_ARGS="--enable-apc --with-php-config=$PHP_CONFIG --with-libdir=$LIBDIR"
+ if [ ! -n "$CONFIGURE_ARGS" ]; then # tests to see if the argument is non empty
+ die "The paths for your previous instalation could not be loaded. You must run the command with 'sudo env PATH=\$PATH bash ...'"
+ fi
+
+ # Check if version is the same
+ if [ $APC_VER == $($PHP_CMD -i 2>&1 | grep -m 2 "Version" | grep -v PHP | cut -d " " -f3) ]; then
+ die "This version number is already installed."
+ fi
+}
+
+get_apc() {
+
+ # Download and extract source package
+ echo "Getting APC"
+ [ -d $SRCDIR ] && rm -r $SRCDIR
+ mkdir $SRCDIR && cd $SRCDIR
+ wget "http://pecl.php.net/get/APC-$APC_VER.tgz"
+
+ if [ ! -f "APC-$APC_VER.tgz" ]; then
+ die "This version could not be found."
+ fi
+
+ tar xzvf APC-$APC_VER.tgz; cd APC-$APC_VER
+}
+
+compile_apc() {
+
+ # Configure and compile APC.
+ echo "Configure APC with typical options..."
+ $PHPIZE -clean
+ ./configure $CONFIGURE_ARGS
+ make -j8
+ make install
+
+}
+
+restart_servers() {
+ echo "Restarting PHP..."
+ if [ $(ps -ef | grep -c "php") -gt 1 ]; then
+ ps -e | grep "php" | awk '{print $1}' | xargs sudo kill -INT
+ fi
+ sleep 2
+ /etc/init.d/php5-fpm start
+}
+
+check_sanity $ARGS
+get_apc
+compile_apc
+restart_servers
+
+# Clean Sources
+rm -r $SRCDIR
+
View
2  ext/update_nginx.sh
@@ -1,7 +1,7 @@
#!/bin/bash
#
###################################################################
-# Script to update Nginx to the latest version. #
+# Script to change Nginx version. #
# June 3rd 2011 Vlad Ghinea. #
###################################################################
#
View
122 ext/update_php.sh
@@ -0,0 +1,122 @@
+#!/bin/bash
+#
+###################################################################
+# Script to change PHP version. #
+# January 19, 2012 Vlad Ghinea. #
+###################################################################
+#
+# Needs to be called with the version number as argument and also
+# with "sudo env PATH=$PATH" in front to preserve the paths.
+#
+# ex: $ sudo env PATH=$PATH bash update_php.sh 5.3.8
+
+# Get PHP Version as a argument
+ARGS="$@"
+
+# Traps CTRL-C
+trap ctrl_c INT
+function ctrl_c() {
+ echo -e '\nCancelled by user'; if [ -n "$!" ]; then kill $!; fi; exit 1
+}
+
+die() {
+ echo "ERROR: $1" > /dev/null 1>&2
+ exit 1
+}
+
+check_sanity() {
+
+ # Check if the script is run as root.
+ if [ $(/usr/bin/id -u) != "0" ]
+ then
+ die "Must be run by root user. Use 'sudo env PATH=\$PATH bash ...'"
+ fi
+
+ # A single argument allowed
+ [ "$#" -eq 1 ] || die "1 argument required, $# provided"
+
+ # Check if version is sane
+ echo $1 | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+$' || die "Version number doesn't seem right; Please double check: $1"
+
+ PHP_VER="$1"
+ DATE=`date +%Y.%m.%d`
+ SRCDIR=/tmp/php_$PHP_VER-$DATE
+ # Get executable path
+ PHP_CMD=$(type -p php)
+ # Get original configure options
+ CONFIGURE_ARGS=$($PHP_CMD -i 2>&1 | grep "Configure Command =>" | cut -d " " -f7- | sed "s/'//g")
+ if [ ! -n "$CONFIGURE_ARGS" ]; then # tests to see if the argument is non empty
+ die "Previous configure options could not be loaded. You must run the command with 'sudo env PATH=\$PATH bash ...'"
+ fi
+
+ # Check if version is the same
+ if [ $PHP_VER == $($PHP_CMD -v 2>&1 | grep "built" | cut -d " " -f2) ]; then
+ die "This version number is already installed."
+ fi
+}
+
+get_php() {
+
+ # Download and extract source package
+ echo "Getting PHP"
+ [ -d $SRCDIR ] && rm -r $SRCDIR
+ mkdir $SRCDIR && cd $SRCDIR
+ wget "http://us.php.net/distributions/php-$PHP_VER.tar.gz"
+
+ if [ ! -f "php-$PHP_VER.tar.gz" ]; then
+ die "This version could not be found on php.net/distributions."
+ fi
+
+ tar zxvf php-$PHP_VER.tar.gz
+ if [ ! -d "php-$PHP_VER" ]; then
+ die "The archive could not be decompressed."
+ fi
+ cd php-$PHP_VER
+}
+
+compile_php() {
+
+ # Configure and compile NginX with previous options
+ echo "Configure with previous options..."
+ ./buildconf --force
+ ./configure $CONFIGURE_ARGS
+ make -j8
+ make install
+
+}
+
+backup_conf() {
+ # Move the current configuration to a safe place.
+ echo "Backing up working config..."
+ [ -d /etc/php5 ] && mv /etc/php5 /etc/php5.original
+}
+
+recover_conf() {
+ # Send the new default configuration to /tmp
+ [ -d /etc/php5 ] && mv /etc/php5 /tmp/php5-$DATE
+
+ # Recover previous configuration files
+ echo "Restore working config..."
+ [ -d /etc/php5.original ] && mv /etc/php5.original /etc/php5
+}
+
+restart_servers() {
+ echo "Restarting PHP..."
+ if [ $(ps -ef | grep -c "php") -gt 1 ]; then
+ ps -e | grep "php" | awk '{print $1}' | xargs sudo kill -INT
+ fi
+ sleep 2
+ /etc/init.d/php5-fpm start
+}
+
+check_sanity $ARGS
+
+backup_conf
+get_php
+compile_php
+recover_conf
+restart_servers
+
+# Clean Sources
+rm -r $SRCDIR
+
View
23 install.sh
@@ -21,7 +21,8 @@
# you should use the packages provided by your distribution.
### Program Versions:
-NGINX_VER="1.1.14"
+NGINX_STABLE="1.0.12"
+NGINX_DEV="1.1.14"
PHP_VER="5.3.10"
APC_VER="3.1.9"
SUHOSIN_VER="0.9.33"
@@ -181,7 +182,12 @@ function install_php() {
cp $SRCDIR/init_files/php5-fpm /etc/init.d/php5-fpm
chmod +x /etc/init.d/php5-fpm
update-rc.d -f php5-fpm defaults
- chown -R www-data:www-data /var/log/php5-fpm
+
+ # The newer versions of php complain if a time zone is not set on php.ini (so we grab the system's one)
+ TIMEZONE=$([ -f /etc/timezone ] && cat /etc/timezone | sed "s/\//\\\\\//g")
+ sed -i "s/^\;date\.timezone.*$/date\.timezone = \"${TIMEZONE}\" /g" /etc/php5/php.ini
+
+ chown -R www-data:www-data /var/log/php5-fpm & progress
# Create log rotation script
echo 'Creating logrotate script...' >&3
@@ -423,7 +429,7 @@ clear >&3
echo "=========================================================================" >&3
echo "This script will install the following:" >&3
echo "=========================================================================" >&3
-echo " - Nginx $NGINX_VER;" >&3
+echo " - Nginx $NGINX_DEV (development) or $NGINX_STABLE (stable);" >&3
echo " - PHP $PHP_VER;" >&3
echo " - APC $APC_VER;" >&3
echo " - Suhosin $SUHOSIN_VER;" >&3
@@ -441,6 +447,17 @@ case $continue_install in
*)
esac
+echo "Which of the following NginX releases do you want installed:" >&3
+echo "1) Latest Development Release ($NGINX_DEV)(default)" >&3
+echo "2) Latest Stable Release ($NGINX_STABLE)" >&3
+echo -n "Enter your menu choice [1 or 2]: " >&3
+read nginxchoice
+case $nginxchoice in
+ 1) NGINX_VER=$NGINX_DEV ;;
+ 2) NGINX_VER=$NGINX_STABLE ;;
+ *) NGINX_VER=$NGINX_DEV ;
+esac
+
prepare_system
install_mysql
Please sign in to comment.
Something went wrong with that request. Please try again.