Chapter 11: Application Hosting — WordPress, Flask and Express
11.1 WordPress
In short: WordPress is an open-source content management system (CMS) written in PHP that uses MySQL/MariaDB.
Quick answer: the short, self-contained version of this lesson is the guide How to Install WordPress on AWS EC2 (Amazon Linux 2023).
Why and what
Friends, WordPress is a CMS that runs on PHP and MySQL. Once your blog is on WordPress, posts can be published without writing code.
मित्रांनो, WordPress म्हणजे PHP आणि MySQL वर चालणारा CMS. तुमचा ब्लॉग एकदा WordPress वर आला की कोड न लिहिता पोस्ट्स टाकता येतात.
दोस्तों, WordPress मतलब PHP और MySQL पर चलने वाला CMS. आपका ब्लॉग एक बार WordPress पर आ गया तो बिना कोड लिखे पोस्ट्स डाल सकते हैं.
WordPress is an open-source content management system (CMS) written in PHP that uses MySQL/MariaDB. It powers a very large share of all websites — blogs, college department sites, small business and news portals. Hosting it yourself teaches the complete LAMP/LEMP workflow.
Browser ─► Apache/Nginx :80 ─► PHP (mod_php / PHP-FPM) ─► WordPress PHP files (/var/www/wordpress)
│
▼
MariaDB/MySQL database "wordpress"
Requirements: PHP 7.4+ (8.x recommended), MySQL 8.0+ or MariaDB 10.5+, a web server with URL rewriting, ~1 GB RAM (a t3.micro works for learning; add swap if needed).
Step 1 — Install the stack
Come on, now let's install WordPress. Choose your OS and follow along — don't skip any step. Let's put your blog live today.
चला, आता WordPress इन्स्टॉल करूया. तुमचा OS निवडा आणि सोबत करा – एकही स्टेप स्किप करू नका. तुमचा ब्लॉग आज लाइव्ह करूया.
चलो, अब WordPress इंस्टॉल करते हैं. अपना OS चुनो और साथ-साथ करो – कोई भी स्टेप स्किप मत करो. आपका ब्लॉग आज लाइव करते हैं.
Ubuntu (Apache):
sudo apt update
sudo apt install -y apache2 mysql-server php libapache2-mod-php php-mysql \
php-curl php-gd php-mbstring php-xml php-intl php-zip php-soap wget unzip
sudo service apache2 start
sudo service mysql start
sudo systemctl enable apache2 mysql
Amazon Linux 2023 (Apache):
sudo yum install -y httpd mariadb105-server php php-fpm php-mysqlnd \
php-gd php-mbstring php-xml php-intl php-opcache wget
sudo service httpd start
sudo service mariadb start
sudo service php-fpm start
sudo systemctl enable httpd mariadb php-fpm
CentOS Stream 9 (Apache):
sudo yum install -y httpd mariadb-server php php-fpm php-mysqlnd \
php-gd php-mbstring php-xml php-intl php-opcache wget tar
sudo service httpd start
sudo service mariadb start
sudo service php-fpm start
sudo systemctl enable httpd mariadb php-fpm
Then secure the database: sudo mysql_secure_installation (see Chapter 10).
Step 2 — Create the WordPress database
sudo mysql <<'EOF'
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'Wp@Pass123';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EOF
Step 3 — Download and extract WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mv wordpress /var/www/wordpress
ls /var/www/wordpress
Step 4 — Configure wp-config.php
cd /var/www/wordpress
sudo cp wp-config-sample.php wp-config.php
sudo sed -i "s/database_name_here/wordpress/" wp-config.php
sudo sed -i "s/username_here/wpuser/" wp-config.php
sudo sed -i "s/password_here/Wp@Pass123/" wp-config.php
grep DB_ wp-config.php
Add unique security keys (salts). Get a fresh set from the official generator:
curl -s https://api.wordpress.org/secret-key/1.1/salt/
sudo nano /var/www/wordpress/wp-config.php
In nano, delete the eight lines that contain put your unique phrase here and paste the eight lines printed by curl. Save (Ctrl+O, Enter) and exit (Ctrl+X).
Step 5 — Ownership and permissions
Friends, if ownership is wrong, plugins and uploads fail. www-data on Ubuntu, and apache on Amazon Linux and CentOS – remember this difference.
मित्रांनो, ओनरशिप चुकली तर प्लगइन्स आणि अपलोड्स फेल होतात. Ubuntu वर www-data, आणि Amazon Linux आणि CentOS वर apache – हा फरक लक्षात ठेवा.
दोस्तों, ओनरशिप गलत हो तो प्लगइन्स और अपलोड्स फ़ेल होते हैं. Ubuntu पर www-data, और Amazon Linux और CentOS पर apache – ये फ़र्क याद रखो.
# Ubuntu:
sudo chown -R www-data:www-data /var/www/wordpress
# Amazon Linux 2023 / CentOS Stream 9:
sudo chown -R apache:apache /var/www/wordpress
sudo find /var/www/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress -type f -exec chmod 644 {} \;
sudo chmod 640 /var/www/wordpress/wp-config.php
CentOS Stream 9 only — SELinux: allow WordPress to write uploads/plugins and to make outgoing connections (updates, plugin downloads):
sudo yum install -y policycoreutils-python-utils
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/wordpress/wp-content(/.*)?"
sudo restorecon -Rv /var/www/wordpress
sudo setsebool -P httpd_can_network_connect 1
Step 6a — Apache virtual host
Ubuntu (/etc/apache2/sites-available/wordpress.conf):
sudo tee /etc/apache2/sites-available/wordpress.conf > /dev/null <<'EOF'
<VirtualHost *:80>
ServerName blog.local
DocumentRoot /var/www/wordpress
<Directory /var/www/wordpress>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
</VirtualHost>
EOF
sudo a2ensite wordpress.conf
sudo a2dissite 000-default.conf
sudo a2enmod rewrite
sudo apache2ctl configtest && sudo service apache2 reload
Amazon Linux 2023 / CentOS Stream 9 (/etc/httpd/conf.d/wordpress.conf):
sudo tee /etc/httpd/conf.d/wordpress.conf > /dev/null <<'EOF'
<VirtualHost *:80>
ServerName blog.local
DocumentRoot /var/www/wordpress
DirectoryIndex index.php index.html
<Directory /var/www/wordpress>
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/wordpress_error.log
CustomLog /var/log/httpd/wordpress_access.log combined
</VirtualHost>
EOF
sudo apachectl configtest && sudo service httpd reload
(mod_rewrite is enabled by default on AL2023/CentOS. AllowOverride All lets WordPress's .htaccess create pretty permalinks.)
Step 6b — Or use Nginx instead of Apache (LEMP)
Install nginx and PHP-FPM instead of Apache (sudo apt install -y nginx php-fpm ... on Ubuntu; stop/disable Apache first). Server block:
server {
listen 80;
server_name YOUR_SERVER_NAME; # public IP or domain
root /var/www/wordpress;
index index.php index.html;
client_max_body_size 64M; # allow bigger media uploads
location / {
try_files $uri $uri/ /index.php?$args; # pretty permalinks
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php-fpm/www.sock; # Ubuntu: unix:/run/php/php-fpm.sock
}
location ~* \.(css|js|png|jpg|jpeg|gif|svg|webp|ico)$ {
expires 30d;
access_log off;
}
location ~ /\.ht { deny all; }
}
PHP-FPM user with Nginx
On AL2023/CentOS PHP-FPM runs as user apache by default (even with Nginx), so chown -R apache:apache is still correct. On Ubuntu both Nginx and PHP-FPM run as www-data.
Ravindra Bagale's Tip
Attach an Elastic IP before you open the WordPress installer. WordPress saves the site URL in its database, and if the public IP changes later, every link and CSS file points to the old IP. Two minutes of planning saves an hour of fixing.Ravindra Bagale's Tip – मराठी
WordPress installer उघडण्याआधी Elastic IP attach करा. WordPress site URL database मध्ये save करतो, आणि नंतर public IP बदलला तर प्रत्येक link आणि CSS file जुन्या IP कडे point करते. दोन मिनिटांचं planning एक तासाचं fixing वाचवतं.
Ravindra Bagale's Tip – हिंदी
WordPress installer खोलने से पहले Elastic IP attach करो. WordPress site URL database में save करता है, और बाद में public IP बदला तो हर link और CSS file पुराने IP की तरफ़ point करती है. दो मिनट की planning एक घंटे की fixing बचाती है.
Step 7 — Finish installation in the browser
Open http://<PUBLIC_IP>/ → choose language → enter Site Title, admin Username, strong Password, Email → Install WordPress → log in at http://<PUBLIC_IP>/wp-admin.
WordPress and changing IPs
WordPress stores the site URL in the database. If the public IP changes (stop/start without an Elastic IP), the site redirects to the old IP and breaks. Attach an Elastic IP before installing (see section 14.1), or use a domain (Chapter 9). To fix after the fact, add define('WP_HOME','http://NEW_IP'); define('WP_SITEURL','http://NEW_IP'); to wp-config.php.
WordPress hardening checklist
Friends, the work isn't over once it's installed. Complete this checklist after every install – security is not a one-time job, it's a habit.
मित्रांनो, इन्स्टॉल झालं म्हणजे काम संपलं नाही. ही चेकलिस्ट प्रत्येक इन्स्टॉलनंतर पूर्ण करा – सिक्युरिटी एकदा करायचं काम नाही, ती सवय आहे.
दोस्तों, इंस्टॉल हो गया मतलब काम ख़त्म नहीं हुआ. ये चेकलिस्ट हर इंस्टॉल के बाद पूरी करो – सिक्योरिटी एक बार का काम नहीं, ये आदत है.
- Strong admin password; don't use the username
admin. - Keep WordPress core, themes and plugins updated; delete unused ones.
wp-config.phppermission640; disable file editing in the dashboard: adddefine('DISALLOW_FILE_EDIT', true);.- Point a domain to the server (Chapter 9) and enable HTTPS with certbot (sections 7.13 and 9.11).
- Back up the database (
mysqldump wordpress) andwp-contentregularly; take EBS snapshots. - Increase PHP upload limits if needed:
upload_max_filesizeandpost_max_sizein/etc/php.ini(AL2023/CentOS) or/etc/php/8.x/apache2/php.ini//etc/php/8.x/fpm/php.ini(Ubuntu), then restart PHP-FPM/Apache.
Ravindra Bagale's Tip
Many students see a 404 on every post after changing permalinks. On Apache you need both AllowOverride All and, on Ubuntu, sudo a2enmod rewrite; on Nginx, try_files $uri $uri/ /index.php?$args;. And never use admin as the login username.
Ravindra Bagale's Tip – मराठी
खूप students permalinks बदलल्यावर प्रत्येक post वर 404 बघतात. Apache वर AllowOverride All आणि Ubuntu वर sudo a2enmod rewrite दोन्ही लागतात; Nginx वर try_files $uri $uri/ /index.php?$args;. आणि login साठी admin username कधीच वापरू नका.
Ravindra Bagale's Tip – हिंदी
बहुत students permalinks बदलने के बाद हर post पर 404 देखते हैं. Apache पर AllowOverride All और Ubuntu पर sudo a2enmod rewrite दोनों चाहिए; Nginx पर try_files $uri $uri/ /index.php?$args;. और login के लिए admin username कभी इस्तेमाल मत करो.
Lab
Chala, Elastic IP attach karun Ubuntu kiwa Amazon Linux 2023 var WordPress install kara aani "My first AWS post" naavachi ek post publish kara. Mag Settings → Permalinks madhe Post name nivda aani post ughadte ka te bagha – 404 aala tar AllowOverride All check kara.
Got it? Stack, database, wp-config.php, ownership, vhost and the browser install – these are the six stages of WordPress. Now let's move on to running a Python app in production.
समजलं का? स्टॅक, डेटाबेस, wp-config.php, ओनरशिप, vhost आणि ब्राउझर इन्स्टॉल – हेच WordPress चे सहा टप्पे. आता पुढे जाऊया Python ॲप प्रॉडक्शनमध्ये चालवायला.
समझ आया? स्टैक, डेटाबेस, wp-config.php, ओनरशिप, vhost और ब्राउज़र इंस्टॉल – यही WordPress के छह पड़ाव हैं. अब आगे चलते हैं Python ऐप को प्रोडक्शन में चलाने.