Skip to content

Commit

Permalink
Merge branch 'unattended'
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad committed Apr 30, 2012
2 parents a134aad + 9605ac5 commit 1bab589
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 155 deletions.
9 changes: 4 additions & 5 deletions CHANGELOG.mkd
@@ -1,11 +1,10 @@
## Release Notes: ##

### 5.6.0 ###
### 6.0.0 ###

* Support for Ubuntu Precise (12.04).
* Fix some of the library paths.
* PHP Upstream release (5.3.11 and 5.4.1)
* NginX Upstream release (1.2.0)
* The script is now completely unattended.
* Added an OPTIONS file that contains all program versions and paths.
* Improved the final screen. It should now check for the external IP address.

### 5.5.0 ###

Expand Down
35 changes: 35 additions & 0 deletions OPTIONS
@@ -0,0 +1,35 @@
#!/bin/bash

# Enable the script?
ENABLED='no'

### Program Versions: #########################################################

# NginX Version:
# Ex: NGINX_VERSION='1.2.0'
NGINX_VERSION='1.2.0'

# PHP Version:
# Ex: PHP_VERSION='5.4.1'
PHP_VERSION='5.4.1'

# APC Version:
# Ex: APC_VERSION='3.1.10'
APC_VERSION='3.1.10'

# Suhosin Version:
# Ex: SUHOSIN_VERSION='0.9.33'
SUHOSIN_VERSION='0.9.33'

###############################################################################

### Directories ###############################################################

# Destination directory (where to install the software)
DESTINATION_DIR='/opt'

# Web files directory
WEB_DIR='/var/www'

###############################################################################

24 changes: 14 additions & 10 deletions README.mkd
@@ -1,12 +1,8 @@
This package represents a script to install the latest NginX, MySQL and PHP (with APC and Suhosin):
This package represents a script to install the latest NginX, MySQL and PHP (with APC and Suhosin).
Note: At this moment the Suhosin extension is not available for PHP 5.4.
You can install your preferred versions for any of the programs. Just edit the OPTIONS file and change them accordingly.

* NginX 1.2.0 (development) or 1.2.0 (stable)
* PHP 5.3.11 or PHP 5.4.1
* APC 3.1.10
* Suhosin Extension 0.9.33 (at this moment it is not available with PHP 5.4)

All the steps are described at http://vladgh.com/blog/install-nginx-and-php-php-fpm-mysql-and-apc
It's highly recommended to run this installer on a fresh installed system.
It is highly recommended to run this installer on a fresh installed system.
This is tested with Ubuntu 10.04, 11.10 and 12.04, both 32 bits and 64 bits, on official Amazon EC2 Ubuntu images.

####If you find this interesting and you want to keep the development active, please click on the button below to donate:###
Expand All @@ -23,9 +19,17 @@ Clone this repository, and get the latest stable version of this script:
git clone git://github.com/vladgh/VladGh.com-LEMP.git
cd VladGh.com-LEMP

Run the installer; I recommend running everything inside a screen session because if your connection drops you can easily come back with `screen -rad`
Start a screen session:

screen

I recommend running everything inside a screen session because if your connection drops you can easily come back with `screen -rad`. If you use something else (ex: byobu) you can skip this step.

Edit the OPTIONS files and change `ENABLED='yes'`. This is were you can modify the versions for any of the programs, and paths.

Run the installer:

sudo screen ./install.sh
sudo ./install.sh

After the installer is finished (this will take a long time depending on your server specifications), you MUST set your mysql root password:

Expand Down
117 changes: 42 additions & 75 deletions install.sh
Expand Up @@ -4,9 +4,11 @@
####################
### LICENSE: ###
####################
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
# To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/
# or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
# Unported License. To view a copy of this license, visit
# http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to
# CreativeCommons, 444 Castro Street, Suite 900
# Mountain View, California, 94041, USA.
#
###################
### DISCLAIMER: ###
Expand All @@ -20,36 +22,27 @@
# and testing purposes only. If you care about stability and security
# you should use the packages provided by your distribution.

### Program Versions:
NGINX_STABLE="1.2.0"
NGINX_DEV="1.2.0"
PHP_53="5.3.11"
PHP_54="5.4.1"
APC_VER="3.1.10"
SUHOSIN_VER="0.9.33"

### Directories
DSTDIR="/opt"
WEBDIR="/var/www"
# Directories
SRCDIR=`dirname $(readlink -f $0)`
OPTIONSFILE="${SRCDIR}/OPTIONS"
TMPDIR="${SRCDIR}/sources"
INSTALL_FILES="${SRCDIR}/install_files/*.sh"
LOG_FILE="${SRCDIR}/install.log"

### Log file
LOG_FILE="install.log"

### Active user
# Active user
USER=$(who mom likes | awk '{print $1}')

# Load installation files
# Load options and installation files
. $OPTIONSFILE
for file in ${INSTALL_FILES} ; do
. ${file}
done

###################################################################################
###############################################################################
### RUN ALL THE FUNCTIONS:

check_root
check_options
log2file

# Traps CTRL-C
Expand All @@ -59,65 +52,34 @@ function ctrl_c() {
}

clear >&3
echo '=========================================================================' >&3
echo '===============================================================================' >&3
echo 'This script will install the following:' >&3
echo '=========================================================================' >&3
echo " - Nginx ${NGINX_DEV} (development) or ${NGINX_STABLE} (stable);" >&3
echo " - PHP ${PHP_53} or ${PHP_54};" >&3
echo " - APC ${APC_VER};" >&3
echo " - Suhosin ${SUHOSIN_VER} (at this moment not available for PHP 5.4)" >&3
echo '=========================================================================' >&3
echo '===============================================================================' >&3
echo " - Nginx ${NGINX_VERSION};" >&3
echo " - PHP ${PHP_VERSION};" >&3
echo " - APC ${APC_VERSION};" >&3
if [[ $PHP_VERSION != 5.4* ]]; then
echo " - Suhosin ${SUHOSIN_VERSION}." >&3
fi
echo '===============================================================================' >&3
echo 'For more information please visit:' >&3
echo 'https://github.com/vladgh/VladGh.com-LEMP' >&3
echo '=========================================================================' >&3
echo 'Do you want to continue[Y/n]:' >&3
read continue_install
case $continue_install in
'n'|'N'|'No'|'no')
echo -e "\nCancelled." >&3
exit 1
;;
*)
esac

echo 'Which of the following PHP releases do you want installed:' >&3
echo "1) Current PHP 5.3 Stable (${PHP_53})(default)" >&3
echo "2) Current PHP 5.4 Stable (${PHP_54})(at this moment without the Suhosin extension)" >&3
echo -n 'Enter your menu choice [1 or 2]: ' >&3
read nginxchoice
case $nginxchoice in
1) PHP_VER=$PHP_53 ;;
2) PHP_VER=$PHP_54 ;;
*) PHP_VER=$PHP_53 ;
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
echo '===============================================================================' >&3

prepare_system

install_mysql

install_php
install_apc
if [ $PHP_VER == $PHP_54 ]; then

if [[ $PHP_VERSION = 5.4* ]]; then
tput bold >&3; tput setaf 1 >&3; echo 'At this moment the Suhosin extension is not available for PHP 5.4' >&3; tput sgr0 >&3
else
install_suhosin
fi
check_php

check_php
install_nginx
check_nginx

set_paths
restart_servers

Expand All @@ -126,27 +88,32 @@ rm -r $TMPDIR

sleep 5

# Get external IP if possible
wimi="http://automation.whatismyip.com/n09230945.asp"
if curl -s --head ${wimi} | grep "200 OK" > /dev/null
then
EXTIP=$(curl -s ${wimi})
else
EXTIP=$(hostname -f)
fi

### Final check
if [ -e "/var/run/nginx.pid" ] && [ -e "/var/run/php-fpm.pid" ] ; then
echo '=========================================================================' >&3
echo '===============================================================================' >&3
echo 'All the components were successfully installed.' >&3
echo 'If your hosts are setup correctly you should be able to see some stats at:' >&3
echo "- http://$(hostname -f)/index.php (PHP Status page)" >&3
echo "- http://$(hostname -f)/apc.php (APC Status page)" >&3
echo "- http://$(hostname -f)/nginx_status (NginX Status page)" >&3
echo "- http://$(hostname -f)/status?html (FPM Status page)" >&3
echo 'You should be able to see some stats when you visit the following URLs:' >&3
echo "- http://${EXTIP}/index.php (PHP Status page)" >&3
echo "- http://${EXTIP}/apc.php (APC Status page)" >&3
echo "- http://${EXTIP}/nginx_status (NginX Status page)" >&3
echo "- http://${EXTIP}/status?html (FPM Status page)" >&3
tput bold >&3; tput setb 4 >&3; tput setf 7 >&3
echo 'DO NOT FORGET TO SET THE MYSQL ROOT PASSWORD:' >&3;
tput smul >&3;
echo '"sudo mysqladmin -u root password MYPASSWORD"' >&3
tput sgr0 >&3
echo 'Press any key to exit...' >&3
read -n 1
exit 0
else
echo '=========================================================================' >&3
echo '===============================================================================' >&3
echo 'Errors encountered. Check the install.log.' >&3
echo 'Press any key to exit...' >&3
read -n 1
exit 1
fi
14 changes: 7 additions & 7 deletions install_files/apc.sh
Expand Up @@ -2,17 +2,17 @@

function install_apc() {
# Get APC package
echo "Downloading and extracting APC-${APC_VER}..." >&3
wget -O ${TMPDIR}/APC-${APC_VER}.tgz "http://pecl.php.net/get/APC-${APC_VER}.tgz" & progress
echo "Downloading and extracting APC-${APC_VERSION}..." >&3
wget -O ${TMPDIR}/APC-${APC_VERSION}.tgz "http://pecl.php.net/get/APC-${APC_VERSION}.tgz" & progress
cd $TMPDIR
tar xzvf APC-${APC_VER}.tgz
check_download "APC" "${TMPDIR}/APC-${APC_VER}.tgz" "${TMPDIR}/APC-${APC_VER}/config.m4"
cd ${TMPDIR}/APC-${APC_VER}
tar xzvf APC-${APC_VERSION}.tgz
check_download "APC" "${TMPDIR}/APC-${APC_VERSION}.tgz" "${TMPDIR}/APC-${APC_VERSION}/config.m4"
cd ${TMPDIR}/APC-${APC_VERSION}

# Compile APC source
echo 'Configuring APC...' >&3
${DSTDIR}/php5/bin/phpize -clean
./configure --enable-apc --with-php-config=${DSTDIR}/php5/bin/php-config --with-libdir=${DSTDIR}/php5/lib/php & progress
${DESTINATION_DIR}/php5/bin/phpize -clean
./configure --enable-apc --with-php-config=${DESTINATION_DIR}/php5/bin/php-config --with-libdir=${DESTINATION_DIR}/php5/lib/php & progress

echo 'Compiling APC...' >&3
make -j8 & progress
Expand Down
54 changes: 32 additions & 22 deletions install_files/misc.sh
Expand Up @@ -38,55 +38,48 @@ function check_download () {
else
echo "Error: ${1} Download was unsuccessful." >&3
echo 'Check the install.log for errors.' >&3
echo 'Press any key to exit...' >&3
read -n 1
exit 1
fi
}

function check_php () {
# Check if the PHP executable exists and has the APC and Suhosin modules compiled.
if [ $PHP_VER != $PHP_54 ] && [ -x "${DSTDIR}/php5/bin/php" ] && [ $(${DSTDIR}/php5/bin/php -m | grep apc) ] && [ $(${DSTDIR}/php5/bin/php -m | grep suhosin) ] ; then
echo '=========================================================================' >&3
echo "PHP ${PHP_VER} with APC and Suhosin was successfully installed." >&3
${DSTDIR}/php5/bin/php -v >&3
echo '=========================================================================' >&3
elif [ $PHP_VER == $PHP_54 ] && [ -x "${DSTDIR}/php5/bin/php" ] && [ $(${DSTDIR}/php5/bin/php -m | grep apc) ] ; then
echo '=========================================================================' >&3
echo "PHP ${PHP_VER} with APC was successfully installed." >&3
${DSTDIR}/php5/bin/php -v >&3
echo '=========================================================================' >&3
if [[ $PHP_VERSION != 5.4* ]] && [ -x "${DESTINATION_DIR}/php5/bin/php" ] && [ $(${DESTINATION_DIR}/php5/bin/php -m | grep apc) ] && [ $(${DESTINATION_DIR}/php5/bin/php -m | grep suhosin) ] ; then
echo '===============================================================================' >&3
echo "PHP ${PHP_VERSION} with APC and Suhosin was successfully installed." >&3
${DESTINATION_DIR}/php5/bin/php -v >&3
echo '===============================================================================' >&3
elif [[ $PHP_VERSION = 5.4* ]] && [ -x "${DESTINATION_DIR}/php5/bin/php" ] && [ $(${DESTINATION_DIR}/php5/bin/php -m | grep apc) ] ; then
echo '===============================================================================' >&3
echo "PHP ${PHP_VERSION} with APC was successfully installed." >&3
${DESTINATION_DIR}/php5/bin/php -v >&3
echo '===============================================================================' >&3
else
echo 'Error: PHP installation was unsuccessful.' >&3
echo 'Check the install.log for errors.' >&3
echo 'Press any key to exit...' >&3
read -n 1
exit 1
fi
}

function check_nginx () {
# Check if Nginx exists and is executable and display the version.
if [ -x "${DSTDIR}/nginx/sbin/nginx" ] ; then
echo '=========================================================================' >&3
if [ -x "${DESTINATION_DIR}/nginx/sbin/nginx" ] ; then
echo '===============================================================================' >&3
echo 'NginX was successfully installed.' >&3
${DSTDIR}/nginx/sbin/nginx -v >&3
echo '=========================================================================' >&3
${DESTINATION_DIR}/nginx/sbin/nginx -v >&3
echo '===============================================================================' >&3
else
echo 'Error: NginX installation was unsuccessful.' >&3
echo 'Check the install.log for errors.' >&3
echo 'Press any key to exit...' >&3
read -n 1
exit 1
fi
}

function set_paths() {
# Make the NginX and PHP paths global.
echo 'Setting up paths...' >&3
export PATH="${PATH}:${DSTDIR}/nginx/sbin:${DSTDIR}/php5/bin:${DSTDIR}/php5/sbin"
export PATH="${PATH}:${DESTINATION_DIR}/nginx/sbin:${DESTINATION_DIR}/php5/bin:${DESTINATION_DIR}/php5/sbin"
echo "PATH=\"$PATH\"" > /etc/environment
source /etc/environment
}

function restart_servers() {
Expand All @@ -109,6 +102,23 @@ function check_root() {
fi
}

function check_options() {
# Check the sanity of the options file
# Check if enabled
if [ $ENABLED == 'no' ]; then
echo 'Error: This script is not enabled. To enabled it open the'
echo " OPTIONS file and modify ENABLED='yes'. Also please make sure"
echo ' you check the rest of the file and adjust appropriately.'
exit 1
fi

# Check if version numbers are sane
echo $NGINX_VERSION | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+$' || echo "NginX version number doesn't seem right; Please double check: ${NGINX_VERSION}"
echo $PHP_VERSION | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+$' || echo "PHP version number doesn't seem right; Please double check: ${PHP_VERSION}"
echo $APC_VERSION | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+$' || echo "APC version number doesn't seem right; Please double check: ${APC_VERSION}"
echo $SUHOSIN_VERSION | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+$' || echo "SUHOSIN version number doesn't seem right; Please double check: ${SUHOSIN_VERSION}"
}

function log2file() {
# Logging everything to LOG_FILE
exec 3>&1 4>&2
Expand Down

0 comments on commit 1bab589

Please sign in to comment.