Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Setting Up a LAMP Stack on CentOS

Tech 2

1. Configure System Time

Ensure the system clock is synchronized:

systemctl restart chronyd
systemctl enable chronyd
hwclock -w

2. Install Apache and MariaDB

Install the required packages:

yum -y install httpd mariadb mariadb-server
systemctl enable --now httpd
systemctl enable --now mariadb

3. Secure MariaDB Installation

Run the security script to harden the database:

mysql_secure_installation

During execution:

  • Press Enter when prompted for the current root password (none set initially).
  • Enable unix_socket authentication.
  • Set a strong root password.
  • Remove anonymous users.
  • Skip disabling remote root login if local access only is acceptable.
  • Delete the test database.
  • Reload privilege tables.

4. Install PHP and Extensions

Install PHP along with commonly used modules:

yum -y install php php-cli php-fpm php-gd php-curl php-mysqlnd

5. Configrue PHP Timezone

Edit /etc/php.ini to set the correct timezone:

[Date]
date.timezone = Asia/Shanghai

Then restart and enable PHP-FPM:

systemctl restart php-fpm
systemctl enable php-fpm

6. Test PHP Processing

Create a test file in the web root:

echo '<?php phpinfo(); ?>' > /var/www/html/index.php

Update Apache’s directory index settings in /etc/httpd/conf/httpd.conf:

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

Restart Apache:

systemctl restart httpd

7. Prepare WordPress Files

Install tools for file transfer and extraction:

yum -y install lrzsz tar
mkdir -p /opt/software
cd /opt/software

Upload wordpress-*.tar.gz using rz -E, then extract it:

tar -xzvf wordpress-*.tar.gz

8. Deploy WordPress to Web Root

Move WordPress files into the document root and set permissions:

cp -r wordpress /var/www/html/
chown -R apache:apache /var/www/html/wordpress
chmod -R 775 /var/www/html/wordpress

9. Create Database and User for WordPress

Log into MariaDB:

mysql -u root -p

Execute the following SQL commands:

CREATE DATABASE wordpress_db;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Note: Replace 'secure_password' with a strong password.

10. Configure Virtual Host for WordPress

Copy the virtual host template and edit it:

cp /usr/share/doc/httpd-core/httpd-vhosts.conf /etc/httpd/conf.d/
vim /etc/httpd/conf.d/httpd-vhosts.conf

Add the following configuration (replace IP with your server’s address):

<VirtualHost 192.168.35.142:80>
    DocumentRoot "/var/www/html/wordpress"
    <Directory "/var/www/html/wordpress">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Restart Apache to apply changes:

systemctl restart httpd

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.