How to Install WordPress on AWS EC2 (Amazon Linux 2023)
To install WordPress on AWS EC2 with Amazon Linux 2023, install Apache, PHP and MariaDB with sudo yum install -y httpd mariadb105-server php php-fpm php-mysqlnd ..., create a wordpress database and user, download WordPress to /var/www/wordpress, set the database details in wp-config.php, give the files to the apache user and add an Apache virtual host. Then open http://<ELASTIC_IP>/ and finish the five-field installer. Attach an Elastic IP first, because WordPress stores the site URL in its database.
Hello friends! WordPress is a CMS that runs on PHP and MySQL – once installed, you can publish posts without writing code. Today we build your own blog, where you can post your AWS notes and project updates every day. There are many steps, but don't worry – do each step with me and don't skip anything.
नमस्कार मित्रांनो! WordPress म्हणजे PHP आणि MySQL वर चालणारा CMS – एकदा इन्स्टॉल झाला की कोड न लिहिता पोस्ट्स टाकता येतात. आज स्वतःचा ब्लॉग बनवूया, जिथे तुम्ही तुमच्या AWS नोट्स आणि प्रोजेक्ट अपडेट्स रोज टाकू शकाल. स्टेप्स जास्त आहेत, पण घाबरू नका – एक एक स्टेप माझ्या सोबत करा आणि काही स्किप करू नका.
नमस्कार दोस्तों! WordPress मतलब PHP और MySQL पर चलने वाला CMS – एक बार इंस्टॉल हो गया तो बिना कोड लिखे पोस्ट्स डाल सकते हो. आज अपना ब्लॉग बनाएँगे, जहाँ आप अपने AWS नोट्स और प्रोजेक्ट अपडेट्स रोज़ डाल सकोगे. स्टेप्स ज़्यादा हैं, पर घबराओ मत – हर स्टेप मेरे साथ करो और कुछ स्किप मत करो.
Quick answer
On Amazon Linux 2023 (Elastic IP attached, HTTP 80 open), the whole install in short:
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
# create DB "wordpress" + user "wpuser" (Step 2), then:
cd /tmp && wget https://wordpress.org/latest.tar.gz && tar -xzf latest.tar.gz && sudo mv wordpress /var/www/wordpress
# wp-config.php (Step 4), ownership (Step 5), virtual host (Step 6), then open http://<ELASTIC_IP>/
What do I need before installing WordPress?
- An Amazon Linux 2023 instance — a free-tier eligible
t3.microworks for learning (WordPress needs about 1 GB of RAM; add swap if needed). See How to Launch an EC2 Instance in AWS. - An Elastic IP attached before you start — see How to Attach an Elastic IP to an EC2 Instance.
- HTTP 80 (and HTTPS 443) open — see How to Open Port 80 and 443 in an EC2 Security Group.
- SSH access and nothing else on port 80 (stop Nginx if you installed it:
sudo service nginx stop). Apache basics: How to Install Apache (httpd) on Amazon Linux 2023.
How does WordPress serve a page on EC2?
A WordPress page: Apache receives the request, PHP-FPM runs the WordPress code, which reads the posts from the MariaDB database, and the finished HTML page goes back to the browser.
एक WordPress पेज: Apache रिक्वेस्ट घेतो, PHP-FPM WordPress चा कोड चालवतो, तो MariaDB डेटाबेस मधून पोस्ट्स वाचतो, आणि तयार HTML पेज ब्राउझर ला परत जातं.
एक WordPress पेज: Apache रिक्वेस्ट लेता है, PHP-FPM WordPress का कोड चलाता है, जो MariaDB डेटाबेस से पोस्ट्स पढ़ता है, और तैयार HTML पेज ब्राउज़र को वापस जाता है.
WordPress is an open-source content management system (CMS) written in PHP that stores posts, users and settings in a MySQL/MariaDB database. Requirements: PHP 7.4+ (8.x recommended), MySQL 8.0+ or MariaDB 10.5+, and a web server with URL rewriting.
How do I install WordPress on Amazon Linux 2023?
Step 1 — Install Apache, PHP and MariaDB (LAMP)
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
sudo mysql_secure_installation # answer the questions; remove anonymous users and the test DB
Step 2 — Create the WordPress database and user
Replace Wp@Pass123 with your own strong password here and in Step 4:
sudo mysql <<'SQL'
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;
SQL
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) 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 — Set ownership and permissions
On Amazon Linux 2023 Apache and PHP-FPM run as the user apache:
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
Step 6 — Add the Apache virtual host
sudo tee /etc/httpd/conf.d/wordpress.conf > /dev/null <<'VHOST'
<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>
VHOST
sudo apachectl configtest && sudo service httpd reload
mod_rewrite is enabled by default on Amazon Linux 2023, and AllowOverride All lets WordPress's .htaccess create pretty permalinks. Because this is the only vhost, it also answers requests to the Elastic IP; when you have a domain, set ServerName to it.
Ravindra Bagale's Tip
Attach an Elastic IP before you open the WordPress installer. WordPress saves the site URL in the database, and if the public IP changes later, every link and CSS file points to the old IP – the site looks broken. Two minutes of planning saves an hour of fixing.Ravindra Bagale's Tip – मराठी
WordPress इन्स्टॉलर उघडण्याआधी Elastic IP अटॅच करा. WordPress साइट URL डेटाबेस मध्ये सेव्ह करतो, आणि नंतर public IP बदलला तर प्रत्येक लिंक आणि CSS फाइल जुन्या IP कडे पॉइंट करते – साइट तुटलेल्या सारखी दिसते. दोन मिनिटांचं प्लॅनिंग एक तासाचं फिक्सिंग वाचवतं.
Ravindra Bagale's Tip – हिंदी
WordPress इंस्टॉलर खोलने से पहले Elastic IP अटैच करो. WordPress साइट URL डेटाबेस में सेव करता है, और बाद में public IP बदला तो हर लिंक और CSS फ़ाइल पुराने IP की तरफ़ पॉइंट करती है – साइट टूटी हुई दिखती है. दो मिनट की प्लानिंग एक घंटे की फ़िक्सिंग बचाती है.
Step 7 — Finish the installation in the browser
Open http://<ELASTIC_IP>/ → choose a language → enter the Site Title, an admin Username (not admin), a strong Password and your Email → Install WordPress → log in at http://<ELASTIC_IP>/wp-admin. Your blog is live! 🎉
How do I secure WordPress after installing it?
- Strong admin password; never the username
admin. - Keep WordPress core, themes and plugins updated; delete unused ones.
wp-config.phpat640, and disable file editing in the dashboard: adddefine('DISALLOW_FILE_EDIT', true);towp-config.php.- Point a domain to the server and enable HTTPS — see How to Connect a GoDaddy Domain to AWS EC2 and How to Install a Free SSL Certificate on EC2 (use
certbot --apache). - Back up the database (
mysqldump wordpress) andwp-contentregularly, and take EBS snapshots. - Bigger media uploads: raise
upload_max_filesizeandpost_max_sizein/etc/php.ini, thensudo service php-fpm restart.
Ravindra Bagale's Tip
💡 Many students see a 404 on every post after setting permalinks to Post name. The reason: the vhost has no AllowOverride All, so .htaccess doesn't work. On Nginx you need try_files $uri $uri/ /index.php?$args;. And never use admin as the login username – bots try that first.
Ravindra Bagale's Tip – मराठी
💡 खूप स्टुडंट्स permalinks Post name केल्यावर प्रत्येक पोस्ट वर 404 बघतात. कारण vhost मध्ये AllowOverride All नसतं, म्हणून .htaccess चालत नाही. Nginx वापरत असाल तर try_files $uri $uri/ /index.php?$args; लागतं. आणि लॉगिन साठी admin username कधीच वापरू नका – bots आधी तेच ट्राय करतात.
Ravindra Bagale's Tip – हिंदी
💡 बहुत स्टूडेंट्स permalinks Post name करने के बाद हर पोस्ट पर 404 देखते हैं. वजह: vhost में AllowOverride All नहीं होता, इसलिए .htaccess नहीं चलता. Nginx इस्तेमाल कर रहे हो तो try_files $uri $uri/ /index.php?$args; चाहिए. और लॉगिन के लिए admin username कभी मत रखो – bots सबसे पहले वही ट्राय करते हैं.
How do I fix common WordPress errors on EC2?
Ghabru naka 😅 — these are the usual ones:
| Symptom | Likely cause | Fix |
|---|---|---|
| Error establishing a database connection | Wrong DB name/user/password in wp-config.php, or MariaDB stopped |
grep DB_ /var/www/wordpress/wp-config.php; sudo service mariadb status |
Browser downloads index.php or shows PHP code |
PHP-FPM not running | sudo service php-fpm start; sudo service httpd restart |
| Apache test page instead of WordPress | vhost not loaded | sudo apachectl -S; check /etc/httpd/conf.d/wordpress.conf; reload |
| Site redirects to an old IP | Public IP changed after stop/start | Attach an Elastic IP; add define('WP_HOME','http://NEW_IP'); define('WP_SITEURL','http://NEW_IP'); to wp-config.php |
| Posts give 404 after changing permalinks | .htaccess ignored |
AllowOverride All in the vhost, reload |
| Plugin/theme install asks for FTP details | Files not owned by apache |
sudo chown -R apache:apache /var/www/wordpress |
| Upload file size error | PHP limits | Raise upload_max_filesize / post_max_size in /etc/php.ini, restart PHP-FPM |
Learn it properly
This guide is the short path. The free AWS course explains every step in depth, with labs (Ubuntu, CentOS Stream 9 and Nginx/LEMP variants too):
Got it? Stack, database, wp-config.php, ownership, vhost and the browser install – those are the six steps of WordPress. Now add a domain and HTTPS, and publish your first post.
समजलं का? Stack, डेटाबेस, wp-config.php, ownership, vhost आणि ब्राउझर इन्स्टॉल – हेच WordPress चे सहा टप्पे. आता डोमेन आणि HTTPS लावा, आणि तुमची पहिली पोस्ट पब्लिश करा.
समझ आया? Stack, डेटाबेस, wp-config.php, ownership, vhost और ब्राउज़र इंस्टॉल – यही WordPress के छह स्टेप्स हैं. अब डोमेन और HTTPS लगाओ, और अपनी पहली पोस्ट पब्लिश करो.
Frequently asked questions
How do I install WordPress on AWS EC2?
Install Apache, PHP and MariaDB, create a database and user, download WordPress to /var/www/wordpress, set the database details in wp-config.php, give ownership to apache, add a virtual host, and finish the installer in the browser.
Which EC2 instance type do I need for WordPress?
WordPress needs PHP, MySQL or MariaDB and about 1 GB of RAM. A free-tier eligible t3.micro works for learning; add swap if memory runs short.
Why should I attach an Elastic IP before installing WordPress?
WordPress stores the site URL in its database. If the public IP changes after a stop/start, every link and CSS file points to the old IP and the site breaks.
WordPress redirects to an old IP address. How do I fix it?
Add define('WP_HOME','http://NEW_IP'); and define('WP_SITEURL','http://NEW_IP'); to wp-config.php, or better, attach an Elastic IP or a domain and use that.
Why do my WordPress posts show 404 after changing permalinks?
Apache must allow .htaccess: the virtual host needs AllowOverride All. On Nginx use try_files $uri $uri/ /index.php?$args;.
Should I use Apache or Nginx for WordPress?
Both work. Apache (LAMP) is the simplest because WordPress's .htaccess rules work at once. Nginx (LEMP) with PHP-FPM needs its own server block but uses less memory under load.