Setting Up a LAMP Stack and Deploying WordPress
Installing and Configuring MariaDB
1. Clock Synchronization
Install Chrony, restart it, and enable it for automatic startup:
sudo yum -y install chrony
sudo systemctl restart chronyd
sudo systemctl enable chronyd
2. Installing MariaDB and Apache HTTP Server
Install the required packages:
sudo yum -y install httpd mariadb mariadb-server
Start and enable both services:
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl start mariadb
sudo systemctl enable mariadb
3. Configuring MariaDB Database
Initialize the database security settings:
sudo mysql_secure_installation
Follow the prompts:
- Press Enter for no password initially.
- Press Enter for Unix socket authentication.
- Set a root password.
- Remove anonymous users.
- Disallow remote root login (select 'n' to allow).
- Remove test database.
- Reload privilege tables.
4. Verifying Database Login
Log in to MariaDB with the root password:
mysql -u root -p
Installing and Configuring PHP
1. Installing PHP
Install PHP and necessary extensions:
sudo yum -y install php php-cli php-fpm php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd
2. Configuring PHP Timezone
Check the current timezone:
php -i | grep date.timezone
Edit /etc/php.ini to set the timezone:
date.timezone = Asia/Shanghai
Restart and enable PHP-FPM:
sudo systemctl restart php-fpm
sudo systemctl enable php-fpm
3. Creating a Test Web Page
Navigate to the web directory and create a PHP file:
cd /var/www/html
sudo vim info.php
Add the following content:
<?php
phpinfo();
?>
4. Modifying Apache Configuration
Edit the Apache configuration file to include PHP index files:
sudo vim /etc/httpd/conf/httpd.conf
Find the DirectoryIndex line and add index.php:
DirectoryIndex index.html index.php
5. Accessing the PHP Website
Restart Apache and access the site via browser using the server's IP address:
sudo systemctl restart httpd
Deploying WordPress
1. Installation and File Transfer
Install tools for file transfer if needed:
sudo yum -y install lrzsz
Download the WordPress package and extract it:
cd /opt
sudo mkdir software
cd software
sudo wget https://downloads.wordpress.org/release/wordpress-6.5.5.tar.gz
sudo tar -zxvf wordpress-6.5.5.tar.gz
Copy WordPress to the web directory:
sudo cp -r wordpress /var/www/html/
Set permissions:
sudo chown -R apache:apache /var/www/html/wordpress
sudo chmod -R 775 /var/www/html/wordpress
2. Configuring the Databsae
Log in to MariaDB and create a database and user for WordPress:
CREATE DATABASE wp_database;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON wp_database.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
3. Configuring Virtual Host
Copy the virtual hosts configuration template:
sudo cp -p /usr/share/doc/httpd-core/httpd-vhosts.conf /etc/httpd/conf.d/
Edit /etc/httpd/conf.d/httpd-vhosts.conf to set up a virtual host for WordPress.
4. Accessing WordPress
Restart Apache and access WordPress via browser:
sudo systemctl restart httpd
Follow the WordPress setup wizard to configure the site, using the database details created earlier.
Conclusion
This guide covers the installation and configuration of a LAMP stack (Linux, Apache, MariaDB, PHP) and the deployment of WordPress. Ensure all services are running and configured correctly for a functional web environment.