Skip to content

Instantly share code, notes, and snippets.

@sheikhwaqas
Last active November 28, 2018 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sheikhwaqas/5577119 to your computer and use it in GitHub Desktop.
Save sheikhwaqas/5577119 to your computer and use it in GitHub Desktop.
Install Apache / MySQL & PHP on a freshly created Red Hat Enterprise Linux Amazon EC2 Instance
# Login to your Amazon EC2 Instance via SSH.
# If you are logged in as root, you don't need to use the sudo command in the commands below.
# Update the current packages installed on the system
sudo yum upgrade
# Install the required packages before installing Apache / MySQL and PHP
sudo yum install gcc gcc-c++ autoconf automake pcre-devel \
libxml2-devel bzip2-devel libcurl-devel freetype-devel \
openldap-clients cyrus-sasl-devel openldap-devel \
libedit-devel readline-devel \
net-snmp net-snmp-devel net-snmp-utils \
libtidy libtidy-devel \
libxslt libxslt-devel
# Download Apache Source from Apache's Website
# http://httpd.apache.org/download.cgi
wget http://www.us.apache.org/dist/httpd/httpd-2.4.4.tar.gz
# Extract the Source Code
tar -zxf httpd-2.4.4.tar.gz
# Download Apache Portable Runtime (APR) and Apache Portable Runtime Utility (APR-Util) from Apache's Website
# http://apr.apache.org/download.cgi
wget http://www.us.apache.org/dist/apr/apr-1.4.6.tar.gz
wget http://www.us.apache.org/dist/apr/apr-util-1.5.2.tar.gz
# Extract APR and APR-Util
tar -zxf apr-1.4.6.tar.gz
tar -zxf apr-util-1.5.2.tar.gz
# Move APR and APR-Util to Apache's srclib Directory
mv apr-1.4.6 httpd-2.4.4/srclib/apr
mv apr-util-1.5.2 httpd-2.4.4/srclib/apr-util
# Change to Apache's Directory, compile and install it with the SSL module enabled
# This will install Apache in /usr/local/apache2 directory
cd httpd-2.4.4
./configure --enable-module-shared="all ssl"
make
sudo make install
# Compiling the source will not register Apache as a Linux service, so that needs to be done manually
# Create a new blank file in /etc/init.d directory and assign it the appropriate permissions
sudo touch /etc/init.d/httpd
sudo chmod 0755 /etc/init.d/httpd
# Paste the following code snippet in the httpd file created in the above step
sudo nano /etc/init.d/httpd
#!/bin/sh
#
# Startup script for the Apache Web Server
#
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache2/logs/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf
# Source function library.
. /etc/rc.d/init.d/functions
# See how we were called.
case "$1" in
start)
echo -n "Starting httpd: "
daemon /usr/local/apache2/bin/httpd -DSSL
echo
touch /var/lock/subsys/httpd
;;
stop)
echo -n "Shutting down httpd: "
killproc httpd
echo
rm -f /var/lock/subsys/httpd
rm -f /usr/local/apache2/logs/httpd.pid
;;
status)
status httpd
;;
restart)
$0 start
$0 stop
;;
reload)
echo -n "Reloading httpd: "
killproc httpd -HUP
echo
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
# Assign the httpd service in the chkconfig so it loads automatically if server is rebooted
sudo chkconfig --add httpd
# Apache has been successfully installed now. You need to start the service
sudo service httpd start
# Navigate your browser to your server's IP address and check if the default Apache's It Works! web page appears.
# If it appears, you have successfully setup Apache. If not, you need to check your security group in Amazon AWS console
# to verify if port 80 is allowed. If port 80 is allowed then you need to open the port 80 in your iptables.
# Open Port 80 and 443 in iptables
sudo iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
sudo service iptables save
sudo service iptables restart
# Check and verify if apache is working now. This should be working properly.
##########################################################################################################################
# PHP Installation Procedure
##########################################################################################################################
# PHP Installation Prerequisites
# Install JPEG library (Used for PHP GD Library Extension)
wget http://ijg.org/files/jpegsrc.v9.tar.gz
tar -zxf jpegsrc.v9.tar.gz
cd jpeg-9
./configure
sudo make
sudo make install
# Install libpng (Used for PHP GD Library Extension)
wget http://downloads.sourceforge.net/project/libpng/libpng16/1.6.2/libpng-1.6.2.tar.gz
tar -zxf libpng-1.6.2.tar.gz
cd libpng-1.6.2
./configure
sudo make
sudo make install
# Install Free TDS (Used for PHP MySQL Extension)
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz
tar -zxf freetds-stable.tgz
cd freetds-0.91
./configure \
--prefix=/usr/local/freetds \
--sysconfdir=/usr/local/freetds/conf \
--disable-libiconv \
--enable-msdblib
sudo make
sudo make install
# Install libmcrypt & Mcrypt (Used for PHP mcrypt Extension)
# Install libmcrypt
wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
sudo make
sudo make install
# Add the Library directory to /etc/ld.so.conf
sudo nano /etc/ld.so.conf
# Add /usr/local/lib on the last line and save the file
sudo ldconfig
# Update/Install mhash
wget http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar -zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
sudo make
sudo make install
sudo ldconfig
# Install mcrypt
wget http://downloads.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar -zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure --disable-posix-threads
sudo make
sudo make install
sudo ldconfig
# Compile / Install PHP from Source
wget http://pk1.php.net/get/php-5.4.16.tar.gz/from/us1.php.net/mirror
tar -zxf php-5.4.16.tar.gz
./configure \
--prefix=/usr \
--sysconfdir=/private/etc \
--infodir=/usr/share/info \
--mandir=/usr/share/man \
--with-apxs2=/usr/local/apache2/bin/apxs \
--enable-cli \
--with-config-file-path=/etc \
--with-libxml-dir=shared,/usr/local/lib \
--with-openssl=shared \
--with-kerberos=shared,/usr \
--with-pcre-regex \
--with-zlib=shared,/usr \
--enable-bcmath=shared \
--with-bz2=shared,/usr \
--enable-calendar=shared \
--with-curl=shared,/usr \
--enable-dba=shared \
--enable-exif=shared \
--enable-ftp=shared \
--with-gd=shared \
--with-jpeg-dir=shared \
--with-png-dir=shared \
--with-freetype-dir=shared,/usr/X11 \
--enable-gd-native-ttf=shared \
--with-icu-dir=shared,/usr \
--without-ldap \
--without-ldap-sasl \
--enable-mbstring=shared \
--enable-mbregex=shared \
--with-mcrypt=shared,/usr/local/bin/mcrypt \
--with-mssql=shared,/usr/local/freetds \
--with-mysql=shared,mysqlnd \
--with-mysql-sock=shared,/var/lib/mysql/mysql.sock \
--with-mysqli=shared,mysqlnd \
--without-iodbc \
--enable-pdo=shared \
--with-pdo-dblib=shared,/usr/local/freetds \
--with-pdo-mysql=shared,mysqlnd \
--without-pdo-pgsql \
--with-pdo-sqlite=shared \
--without-pgsql \
--enable-phar=shared \
--without-libedit \
--without-readline \
--enable-shmop=shared \
--enable-simplexml=shared \
--without-snmp \
--enable-soap=shared \
--enable-sockets=shared \
--enable-sysvmsg=shared \
--enable-sysvsem=shared \
--enable-sysvshm=shared \
--with-tidy=shared \
--enable-wddx=shared \
--enable-xml=shared \
--enable-xmlreader=shared \
--with-xmlrpc=shared \
--with-iconv-dir=shared,/usr \
--with-xsl=shared,/usr \
--enable-zip=shared \
--with-pear
sudo make
sudo make install
cp php.ini-production /etc/php.ini # If PHP is installed for a Production Server
cp php.ini-development /etc/php.ini # If PHP is installed for a Development Server
# PHP Installation Complete. Ensure below mentioned line is present in httpd.conf file. If not, you need to add it
# LoadModule php5_module modules/libphp5.so
# Edit /usr/local/apache2/conf/mime.types
# Add the following line to this file and save it
# application/x-httpd-php .php
#
# Restart apache after you have made these changes
##########################################################################################################################
# MySQL Installation Procedure
##########################################################################################################################
# Install MySQL and MySQL Server
sudo yum install mysql mysql-server
sudo service mysqld start
sudo mysql_secure_installation
# Follow the on-screen instructions to configure the MySQL Server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment