Deploying a WordPress website on AWS
4 min read
Task-01
Step1: Creating a MYSQL DatabaseWith Amazon RDS
Open the AWS Management Console. When the screen loads, enter RDS in the search bar, then select RDS to open the service console.
Choose the Create Database button to get started.
select MySQL
Choose storage, specify the database name, and create a database.
Step2:Creating an EC2 instance
Click on the launch instance.
select the security group and set MYSQL/Aurora to access Anywhere.
And Done!!
Step 3: Configure the RDS database
SSH in EC2 instance
Now, install MySQL client in it.
sudo yum install -y mysql
connect to RDS through the following command
mysql -h <RDS_endpoint> -P <port> -p
Note: you can find the endpoint in the RDS databases.
the run set of commands to create a username and permit access to it.
CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass'; GRANT ALL PRIVILEGES ON wordpress.* TO wordpress; FLUSH PRIVILEGES; Exit
Step 4: Configure the WordPress on EC2
install apache2 server on EC2
First, download and uncompress the software by running the following commands in your terminal:
wget https://wordpress.org/latest.tar.gz tar -xzf latest.tar.gz
If you run ls to view the contents of your directory, you will see a tar file and a directory called WordPress with the uncompressed contents.
$ ls latest.tar.gz wordpress
Change the directory to the WordPress directory and create a copy of the default config file using the following commands:
cd wordpress cp wp-config-sample.php wp-config.php
Then, run the following command to open the wp-config.php file using the nano editor.
nano wp-config.php
You need to edit two areas of configuration.
First, edit the database configuration by changing the following lines:
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define( 'DB_NAME', 'database_name_here' ); /** MySQL database username */ define( 'DB_USER', 'username_here' ); /** MySQL database password */ define( 'DB_PASSWORD', 'password_here' ); /** MySQL hostname */ define( 'DB_HOST', 'localhost' );
The values should be:
DB_NAME: your database name
DB_USER: The name of the user you created in the database in the previous module
DB_PASSWORD: The password for the user you created in the previous module
DB_HOST: The hostname of the database that you found in the last module
The second configuration section you must configure is the Authentication Unique Keys and Salts. It looks as follows in the configuration file:
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );
you can use these salts:
define('AUTH_KEY', 'JN>`P4.5lo/Q[ukcyTLmt|5-kkTp]Ge$ASLR}Bb-Ts@u[xP={uqJXU)5QMT 8u!e');
define('SECURE_AUTH_KEY', 'W}i26FK+Hm#g|I`k*:s80&AYPC.,MPr[X$9E$W=$1/_2v}<T>$9;w}G:[78MNP0>');
define('LOGGED_IN_KEY', '=_6#@pp*J07Zf/i-YMa6)`O+HyBe-W<E--^av2{sQ!a>OgF+o9k,,#$!;@|Zk&An');
define('NONCE_KEY', '3(SXa>p4{0XSkarx,OG/Y I95nJuY!3*!hKK+~#!Ff9EJMmw!:L0M $p5map8jCL');
define('AUTH_SALT', 'aS{ou/([+cwMMRgf-+-Ji&.9-o@cN^-v}Sb=cvFWj.P?p0 zLj+3>J}xn+tbl1Vd');
define('SECURE_AUTH_SALT', '^5P[T`#[5Qem#4@~c5`JEf;/[|!b:,o/]27UZ_FfC36khb;>@<z+c>TC,|(%g<BY');
define('LOGGED_IN_SALT', '_tL+mGOj4Cc.-Pu,^r@:2y^n1nNQyPw MV&8zcg|/TSsLaRb;-kS<UyF$H(H.e]z');
define('NONCE_SALT', 'to7hx <G Y9MRAOCX/Lj}P-3YcS{pEN|DMC n{5pmlqZNJ*cfV%zDB/FfYaM&a/#');
step 5: Deploy WordPress
sudo apt install php libapache2-mod-php php-mysql -y
Follow the code:
cd /home/ec2-user sudo cp -r wordpress/* /var/www/html/ sudo service httpd restart
Now, if you go to this address
<DNS-ec2-ipaddr>/wp-admin/install.php
It's Done!! ๐๐
NOTE: once you are done with this setup WordPress website delete the RDS database, as it is not free. you can refer to the AWS official documentation to learn more.
Happy Learning!!