Skip to content

Commit

Permalink
modify wordpress-instance template.
Browse files Browse the repository at this point in the history
  • Loading branch information
wb-bcx714829 committed Jul 12, 2024
1 parent e4dad1e commit 5ce0dc0
Showing 1 changed file with 58 additions and 52 deletions.
110 changes: 58 additions & 52 deletions examples/elastic/wordpress-instance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Parameters:
ZoneId: ${ZoneId}
EngineVersion: ${EngineVersion}
Engine: MySQL
Category: HighAvailability
DBInstanceStorageType: cloud_essd
Default: 'rds.mysql.t1.small'
DBInstanceStorage:
Type: Number
Expand Down Expand Up @@ -210,6 +212,8 @@ Resources:
Ref: DBUser
SecurityIPList: 0.0.0.0/0
AllocatePublicConnection: true
Category: HighAvailability
DBInstanceStorageType: cloud_essd
WebServerConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: { }
Expand Down Expand Up @@ -263,58 +267,60 @@ Resources:
Timeout: 3600
CommandContent:
Fn::Base64Encode:
Fn::Sub:
- |-
#!/bin/bash
DatabaseUser=${DatabaseUser}
DatabasePwd=${DatabasePwd}
DatabaseName=${DatabaseName}
DatabaseHost=${DatabaseHost}
WebRootPath='/var/www/html'
ApacheIndex='Options Indexes FollowSymLinks'
ApacheIndexReplace='Options Indexes FollowSymLinks'
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum install -y unzip zip
yum install -y curl httpd mysql-server php56 php56-php-mysql
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-imap.x86_64 php56w-ldap.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-odbc.x86_64 php56w-process.x86_64 php56w-xml.x86_64 php56w-xmlrpc.x86_64
chkconfig httpd on
# wget http://wordpress.org/latest.tar.gz
# tar -xzvf latest.tar.gz
wget https://ros-template-resources.oss-cn-beijing.aliyuncs.com/WordPress/WordPress.zip
unzip WordPress.zip
mv WordPress-master wordpress
cp wordpress/wp-config-sample.php wordpress/backup-wp-config.php
sed -i "s/database_name_here/$DatabaseName/" wordpress/wp-config-sample.php
sed -i "s/username_here/$DatabaseUser/" wordpress/wp-config-sample.php
sed -i "s/password_here/$DatabasePwd/" wordpress/wp-config-sample.php
sed -i "s/localhost/$DatabaseHost/" wordpress/wp-config-sample.php
mv wordpress/wp-config-sample.php wordpress/wp-config.php
cp -a wordpress/* $WebRootPath
rm -rf wordpress*
service httpd stop
usermod -d $WebRootPath apache &>/dev/null
chown apache:apache -R $WebRootPath
sed -i 's/$ApacheIndex/$ApacheIndexReplace/' /etc/httpd/conf/httpd.conf
service httpd start
${CurlCli} -d '{"data" : "Install nginx."}'
- DatabaseUser:
Ref: DBUser
DatabasePwd:
Ref: DBPassword
DatabaseName:
Ref: DBName
DatabaseHost:
Fn::GetAtt:
- Database
- PublicConnectionString
CurlCli:
Fn::GetAtt:
- WebServerConditionHandle
- CurlCli
Fn::Sub: |-
#!/bin/bash
if [ ! -f .ros.provision ]; then
echo "Name: wordpress-service" > .ros.provision
fi
name=$(grep "^Name:" .ros.provision | awk -F':' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [[ "$name" != "wordpress-service" ]]; then
echo "wordpress-service installed, skip"
exit 0
fi

if ! grep -q "^Step1: Install Environment$" .ros.provision; then
echo "#########################"
echo "# Install Environment"
echo "#########################"
yum -y install httpd httpd-manual mod_ssl mod_perl mod_auth_mysql sysbench
systemctl start httpd
systemctl enable httpd
systemctl status httpd

yum install -y yum-utils epel-release http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php82
yum -y install php php-opcache php-mysqlnd php-pdo php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
systemctl restart httpd
echo "Step1: Install Environment" >> .ros.provision
else
echo "#########################"
echo "# Environment has been installed"
echo "#########################"
fi

if ! grep -q "^Step2: Install and Config WordPress$" .ros.provision; then
echo "################################"
echo "# Install and Config WordPress"
echo "################################"
wget https://ros-template-resources.oss-cn-beijing.aliyuncs.com/WordPress/wordpress-6.3.1-zh_CN.tar.gz
tar -xvf wordpress-6.3.1-zh_CN.tar.gz -C /var/www/html
mv /var/www/html/wordpress/* /var/www/html
chown -R apache:apache /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress
mv /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
sed -i 's/localhost/${Database.PublicConnectionString}/' /var/www/html/wp-config.php
sed -i 's/username_here/${DBUser}/' /var/www/html/wp-config.php
sed -i 's/password_here/${DBPassword}/' /var/www/html/wp-config.php
sed -i 's/database_name_here/${DBName}/' /var/www/html/wp-config.php
systemctl restart httpd
echo "Step2: Install and Config WordPress" >> .ros.provision
else
echo "#########################"
echo "# WordPress has been installed and configed"
echo "#########################"
fi
${WebServerConditionHandle.CurlCli} --data-binary '{"status": "SUCCESS"}'
Type: RunShellScript
Name:
Ref: ALIYUN::StackId
Expand Down

0 comments on commit 5ce0dc0

Please sign in to comment.