Script to Install and Secure Apache2 PHP5 MySQL5 in Ubuntu/Debian


Please shareShare on Facebook21Share on Google+20Tweet about this on Twitter11Share on LinkedIn4Share on Reddit0Digg thisShare on StumbleUpon0Share on VKBuffer this page

In this quick post will  show you how  to install fast en secure lamp in Ubuntu and Debian via this small script.





1- Create file; and add the following code


echo "+Updating apt-get..."
apt-get update

echo "+Installing SSH..."
apt-get install -q -y ssh

echo "+Changing default SSH port..."
sed -i 's/Port 22/Port 28/' /etc/ssh/sshd_config
/etc/init.d/ssh restart

echo "+Installing Apache2..."
apt-get install -q -y apache2
sed -i 's/ServerTokens Full/ServerTokens Prod/' /etc/apache2/conf.d/security
sed -i 's/ServerSignature On/ServerSignature Off/' /etc/apache2/conf.d/security
sed -i 's/TraceEnable On/TraceEnable Off/' /etc/apache2/conf.d/security
/etc/init.d/apache2 reload
a2enmod rewrite
/etc/init.d/apache2 restart

echo "+Installing PHP5..."
apt-get install -q -y php5
echo "+Securing PHP.ini file..."
sed -i 's/disable_functions =/disable_functions = show_source, system, exec/' /etc/php5/apache2/php.ini
sed -i 's/expose_php = On/expose_php = Off/' /etc/php5/apache2/php.ini
sed -i 's/display_errors = On/display_errors = Off/' /etc/php5/apache2/php.ini
sed -i 's/log_errors = Off/log_errors = On/' /etc/php5/apache2/php.ini
sed -i 's/allow_url_fopen = On/allow_url_fopen = Off/' /etc/php5/apache2/php.ini

echo "+Installing MySQL Server..."
DEBIAN_FRONTEND='noninteractive' apt-get install -q -y mysql-server
mysqladmin -u root password $MYSQL_PASS
apt-get install -q -y php5-mysql

history -c

echo "+Installation Completed!"

2- Make the script executable

Chmod +x

3- Run thescript

sudo ./

For questions, please post on ask unixmen. Thanks