AWS WordPress 3: Setup LAMP

Overview

This post is the third of a 5-post series with step-by-step procedures that I followed recently to setup WordPress on AWS for this version of the website. In this post, a LAMP stack is setup on the AWS instance. LAMP is an acronym for Linux, Apache, MySQL, and PHP.

Installing Apache Web Server Package:

To install the Apache web server package on the EC2 instance, enter the following command:

sudo apt install apache2

To verify if the installation was successful, enter the elastic IP address (http://xx.xx.xx.xx) into a web browser and see if this is the response:

Installing MySQL Server Package:

To install the MySQL server package on the EC2 instance, enter the following command:

sudo apt-get install mysql-server

To perform the MySQL security installation, enter the following command:

mysql_secure_installation

Enter the password from the previous step. Replies to a series of questions will be requested:

Would you like to setup validate password plugin? n
Remove anonymous users? y
Disallow root login remotely? y
Remove test database and access to it? y
Reload privilege tables now? y

Installing PHP7:

To install the PHP7 and Apache PHP module, enter the following command:

sudo apt-get -y install php7.0 libapache2-mod-php7.0

Then, restart Apache:

sudo systemctl restart apache2

To test the PHP installation, a small PHP file ‘info.php’ will be created and placed in the default website directory ‘/var/www/html’:

sudo nano /var/www/html/info.php

Add the following line in the nano editor:

<?php phpinfo(); ?>

Enter ctrl-x, type y, and return to save.

Change the ownership of this file:

sudo chown www-data:www-data /var/www/html/info.php

Time to check PHP operation. In a browser window, enter the following address replacing the ‘xx’ with the Elastic IP address (http://xx.xx.xx.xx). The PHP file will display a ton of information about the current PHP installation.

Scrolling down through the PHP information reveals that MySQL is not listed meaning that MySQL support in PHP isn’t installed yet. The php7.0-mysql package needs to be installed. In addition, other useful PHP modules can be installed at this point:

sudo apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache  php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext

Then, restart Apache:

sudo systemctl restart apache2

Now, the PHP information retrieved by reloading the browser (http://xx.xx.xx.xx/info.php) will include information about mysql and mysqlnd:

Installing APCu PHP cache to speed up PHP:

APCu speeds up PHP pages by caching and optimizing PHP intermediate code. To install APCu, enter the following command:

sudo rm –f /var/www/html/info.php

Then, restart Apache:

sudo systemctl restart apache2

Now, the PHP information retrieved by reloading the browser (http://xx.xx.xx.xx/info.php) will include information about APCu:

Note: Since the ‘info.php’ displays sensitive server details about the EC2 instance, it is important to delete this file now that PHP operation is verified.

That’s it. The LAMP stack is installed.

2017-08-07T14:00:49+00:00 By |Amazon Web Services, Wordpress|0 Comments

Leave A Comment