Lab 5.3: Setting up WordPress on LAMP
Install WordPress:
Download the latest WordPress installation package with the wget command. The following command should always download the latest release.
wget https://wordpress.org/latest.tar.gz
Unzip and unarchive the installation package. The installation folder is unzipped to a folder called wordpress
.
tar -xzf latest.tar.gz
Log in to the database server as the root
user. Enter your database root
password when prompted; this may be different than your root
system password, or it may even be empty if you have not secured your database server.
mysql -u root -p
Create a user and password for your MySQL database. Your WordPress installation uses these values to communicate with your MySQL database. Enter the following command, substituting a unique user name and password.
CREATE USER 'wordpress-user'@'localhost' IDENTIFIED BY 'your_strong_password';
Create your database. Give your database a descriptive, meaningful name, such as wordpress-db
.
CREATE DATABASE `wordpress-db`;
Grant full privileges for your database to the WordPress user that you created earlier.
GRANT ALL PRIVILEGES ON `wordpress-db`.* TO "wordpress-user"@"localhost";
Flush the database privileges to pick up all of your changes.
FLUSH PRIVILEGES;
Exit the mysql
client.
exit
To create and edit the wp-config.php file
Copy the wp-config-sample.php
file to a file called wp-config.php
. This creates a new configuration file and keeps the original sample file intact as a backup.
cp wordpress/wp-config-sample.php wordpress/wp-config.php
Edit the wp-config.php
file with your favorite text editor (such as nano or vim) and enter values for your installation. If you do not have a favorite text editor, vi
is suitable for beginners.
vi wordpress/wp-config.php
Find the section called Authentication Unique Keys and Salts
. These KEY
and SALT
values provide a layer of encryption to the browser cookies that WordPress users store on their local machines. Basically, adding long, random values here makes your site more secure. You can create unique values by visiting https://api.wordpress.org/secret-key/1.1/salt/ Links to an external site. Links to an external site.to randomly generate a set of key values that you can copy and paste into your wp-config.php
file. To paste text into a PuTTY terminal, place the cursor where you want to paste the text and right-click your mouse inside the PuTTY terminal.
WordPress will run at your document root, socopy the contents of the wordpress installation directory (but not the directory itself) as follows:
cp -r wordpress/* /var/www/html/
Open the httpd.conf
file with your favorite text editor (such as nano or vim). If you do not have a favorite text editor, nano
is suitable for beginners.
sudo vim /etc/httpd/conf/httpd.conf
Change the AllowOverride None
line in the above section to read AllowOverride All
.
Info
There are multiple
AllowOverride
lines in this file; be sure you change the line in the<Directory "/var/www/html">
section.
To install the PHP graphics drawing library on Amazon Linux 2:
Use the following command to install the PHP graphics drawing library on Amazon Linux 2. For example, if you installed php7.2 from amazon-linux-extras as part of installing the LAMP stack, this command installs version 7.2 of the PHP graphics drawing library.
sudo yum install php-gd
To verify the installed version, use the following command:
sudo yum list installed | grep php
To fix file permissions for the Apache web server
Grant file ownership of /var/www
and its contents to the apache
user.
sudo chown -R apache /var/www
Grant group ownership of /var/www
and its contents to the apache
group.
sudo chgrp -R apache /var/www
Change the directory permissions of /var/www
and its subdirectories to add group write permissions and to set the group ID on future subdirectories.
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
Recursively change the file permissions of /var/www
and its subdirectories to add group write permissions.
find /var/www -type f -exec sudo chmod 0664 {} \;
Restart the Apache web server to pick up the new group and permissions.
sudo systemctl restart httpd
To run the WordPress installation script with Amazon Linux 2
Use the systemctl command to ensure that the httpd
and database services start at every system boot.
sudo systemctl enable httpd && sudo systemctl enable mariadb
SUBMIT: Screenshot of Post-Install Wordpress Site.