Install Wordpress with Apache, PHP and MySQL (Automated Startup Script)


You can copy and paste the following bash script into the startup script area of the Vultr Control Panel.

It will install all of necessary packages to run WordPress, generate and import database credentials, and open the necessary firewall ports.

#/bin/shinstall_dir="/var/www/html"#Creating Random WP Database Credenitalsdb_name="wp`date +%s`"db_user=$db_namedb_password=`date |md5sum |cut -c '1-12'`sleep 1mysqlrootpass=`date |md5sum |cut -c '1-12'`sleep 1ftp_password=`date |md5sum |cut -c '1-12'`#### Install Packages for https and mysqlyum -y install httpd httpd-develyum -y install mysql mysql-server mysql-develyum -y install lynx vsftpd##### Open firewall for http and SSLiptables -Fiptables -A INPUT -i lo -j ACCEPTiptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPTiptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPTiptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT/etc/init.d/iptables save/etc/init.d/iptables restart#### Start http/etc/init.d/httpd startchkconfig httpd on#### Start mysql and set root password/etc/init.d/mysqld startchkconfig mysqld on/usr/bin/mysql -e "USE mysql;"/usr/bin/mysql -e "UPDATE user SET Password=PASSWORD($mysqlrootpass) WHERE user='root';"/usr/bin/mysql -e "FLUSH PRIVILEGES;"touch /root/.my.cnfchmod 640 /root/.my.cnfecho "[client]">>/root/.my.cnfecho "user=root">>/root/.my.cnfecho "password="$mysqlrootpass>>/root/.my.cnf####Install PHPyum -y install php php-common php-mysql php-gd php-mbstring php-mcrypt php-xml php-develsed -i '0,/AllowOverride/ None/! {0,/AllowOverride/ None/ s/AllowOverride/ None/AllowOverride/ All/}' /etc/httpd/conf/httpd.conf #Allow htaccess usage/etc/init.d/httpd restart####Download and extract latest WordPress Packageif test -f /tmp/latest.tar.gzthenecho "WP is already downloaded."elseecho "Downloading WordPress"cd /tmp/ && wget "http://wordpress.org/latest.tar.gz";fi/bin/tar -C $install_dir -zxf /tmp/latest.tar.gz --strip-components=1chown apache: $install_dir -R#### Set FTP Credentialsecho $ftp_password | passwd apache --stdin/etc/init.d/vsftpd startchkconfig vsftpd on#### Create WP-config and set DB credentials/bin/mv $install_dir/wp-config-sample.php $install_dir/wp-config.php/bin/sed -i "s/database_name_here/$db_name/g" $install_dir/wp-config.php/bin/sed -i "s/username_here/$db_user/g" $install_dir/wp-config.php/bin/sed -i "s/password_here/$db_password/g" $install_dir/wp-config.phpcat << EOF >> $install_dir/wp-config.phpdefine('FS_METHOD', 'ftpext');define('FTP_BASE', '$install_dir');define('FTP_USER', 'apache');define('FTP_PASS', '$ftp_password');define('FTP_HOST', '127.0.0.1');define('FTP_SSL', false);EOFcat << EOF >> $install_dir/.htaccess# BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^index.php$ – [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule># END WordPressEOFchown apache: $install_dir -R##### Set WP Saltsgrep -A50 'table_prefix' $install_dir/wp-config.php > /tmp/wp-tmp-config/bin/sed -i '/**#@/,/$p/d' $install_dir/wp-config.php/usr/bin/lynx --dump -width 200 https://api.wordpress.org/secret-key/1.1/salt/ >> $install_dir/wp-config.php/bin/cat /tmp/wp-tmp-config >> $install_dir/wp-config.php && rm /tmp/wp-tmp-config -f/usr/bin/mysql -u root -e "CREATE DATABASE $db_name"/usr/bin/mysql -u root -e "GRANT ALL PRIVILEGES ON $db_name.* to '"$db_user"'@'localhost' IDENTIFIED BY '"$db_password"';"######Display generated passwords to log file.echo "Database Name: " $db_nameecho "Database User: " $db_userecho "Database Password: " $db_passwordecho "Mysql root password: " $mysqlrootpassecho "FTP Password: " $ftp_password

You will not need, but can retrieve the database credentials by tailing the end of the /tmp/firstboot.log file after installation. It is also recommended to remove the /tmp/firstboot.log file upon installation. You will be able to access your installation at http://yourip.

Note: This script is meant to run on CentOS 6. It is not guaranteed to work on CentOS 7.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article

No comments

Powered by Blogger.