How to Install WordPress on the Linux Apache MySQL and PHP stack ?
Last Updated :
23 Jul, 2025
WordPress is one of the commonly used Content Management systems on the web. It is written in PHP web servers like Apache are enough to run it. WordPress supports MySQL and MariaDB, but MySQL is widely used. This tutorial will help you to run WordPress using the LAMP(Linux, Apache, MySQL, PHP) stack on your Linux machine (probably VPS).
Prerequisites:
- A Linux machine (Here using Ubuntu)
- A sudo user account
- Some basic command line experience
- Little MySQL experience
This article assumes that you are familiar with PHP, MySQL, and WordPress.
Installing PHP: PHP (Hypertext Preprocessor) is a language used to write WordPress. You can install PHP using below command. libapache2-mod-php and php-mysql are libraries that help PHP, Apache and MySQL smoothly.
sudo apt install php libapache2-mod-php php-mysql
To verify that you have successfully installed PHP, type the below command:
php -v
// output should look like below content
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
Install additional PHP modules like Curl, XML, XMLRPC to help ease the run of WordPress
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
Installing and Configuring Apache: Apache is one of the most widely used web servers. Apache2 is the latest version of the webserver. You can install Apache using the below command:
sudo apt install apache2
To verify that you have successfully installed Apache, type the below command
apache2 -v
// output
Server version: Apache/2.4.41 (Ubuntu)
We will configure Apache virtual hosts for WordPress, we will create a new conf file wordpress.
sudo nano /etc/apache2/sites-available/wordpress.conf
Use the below template to configure to .htaccess file, we will be installing WordPress in /var/www/wordpress, so we will use it as a directory.
<VirtualHost *:80>
ServerName yourdomain.name
<Directory /var/www/wordpress>
AllowOverride All
DirectoryIndex index.php
</Directory>
</VirtualHost>
Now enable the Apache rewrite module and check the Apache config syntax. If you have used syntax correctly, you will get syntax as correct.
sudo a2enmod rewrite
sudo apache2ctl configtest
.
// output
Syntax OK
If you get an error like the below one before Syntax OK, it's perfectly alright because we are using localhost.
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Installing and Configure MySQL: MySQL is a popular open-source relational database management system. To install MySQL you can run the below commands, you can also verify whether MySQL is installed successfully or not.
sudo apt install mysql-server
mysql -V
// output
mysql Ver 8.0.25-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
Now login into MySQL and change the mysql-native-password
sudo mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'secure password';
FLUSH PRIVILEGES;
EXIT;
Now login into MySQL using the root user with the new password and create a new database for wordpress
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Now we will create a new MySQL user and Grant all access to WordPress database to the new wordpress user
mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
mysql> CREATE USER 'wordpressuser'@'%' IDENTIFIED WITH mysql_native_password BY 'secure password';
mysql> GRANT ALL ON wordpress.* TO 'wordpressuser'@'%';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
Downloading WordPress: If you are on Ubuntu, you can directly install using APT and you can skip this step
sudo apt install wordpress
But we will directly install WordPress from the WordPress repository
- First, we will download the WordPress latest version from its repository (we are downloading it into a temporary folder so that the downloaded package and another file that helps in building WordPress but not helpful while it's running will be deleted automatically on a reboot).
- Now we will unzip the WordPress package
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
Now we will create the Apache .htaccess file and WordPress config file from the sample config. We will also create a directory named "upgrade", which makes sure that WordPress won’t run into permissions issues when trying to do an update to its software.
touch /tmp/wordpress/.htaccess
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
mkdir /tmp/wordpress/wp-content/upgrade
Now we will copy the unpacked wordpress directory to /var/www for apache to run
sudo cp -a /tmp/wordpress/. /var/www/wordpress
Configuring WordPress: Now we will adjust the wordpress files and directory permission. "www-data" user and group is the user that the Apache webserver runs as, and Apache will need to be able to read and write WordPress files in order to serve the website and perform automatic updates.
- We need to give wordpress directories 750 permission which means the current user(www-data) can read, write, and execute, the group cannot write, and others cannot read, write, or execute.
- We need to give wordpress files 640 permission which means the current user(www-data) can read, write, and the group can only read and others cannot read, write, or execute.
sudo chown -R www-data:www-data /var/www/wordpress
sudo find /var/www/wordpress/ -type d -exec chmod 750 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 640 {} \;
Now we will create some secure keys for our installation, you can make a request to WordPress API, and it will provide you with the keys, Don't copy these keys make sure you have your own keys
curl -s https://api.wordpress.org/secret-key/1.1/salt/
// the output will be similar to the one belowdefine('AUTH_KEY', ':BiuKIi%W7<p?4Jm}`1XTJOw!cQBKxcOt]DylUDyO$BB<>t)*FN.qf*q|+-W7}8f');
define('SECURE_AUTH_KEY', '7[Kh-{P#A~<PGMkIOHC#9Fta$XGemco5F8k}G66I[lXqD|`IZ8cyM2O>!NjtvW(o');
define('LOGGED_IN_KEY', 'La{SEJ{$uI<6Txgv QqY4cxG]3+-r[Iqcx.IFxlfN.f/Yd?317zR*+Yt=*PMWM$(');
define('NONCE_KEY', 'U5pGQf.`J{.Hd~P/9Snw`V2+#<t+;>OTY!VOW[-aoruh;dhSUX]09xj*O<KXdZ6+');
define('AUTH_SALT', 'fmByAIfcEq&V}Xf,mF)!a09:-Q$R^/:79!k|<pEL@>VU)|C7|(>;`{N(4ZHg O)n');
define('SECURE_AUTH_SALT', 's5N%EIR(eM@tlg;M%L-+F#:<|r_x5-]Ix.&eYN)ya5ktoWLE+H~zUGkX#HceO/;H');
define('LOGGED_IN_SALT', 'EGcaE`=DAh7lv*klFyV0VLy5<@af_*--3otD$3:^;z~C(f^JB[C0T;`yqE)2@y${');
define('NONCE_SALT', 'rP1%&ojrP0XLRuQ1AS#@u}#2-Q+)5ftKeJpWC$oxD]?&3}|+n2Gt{1$`kZbSW`-q');
Now open the WordPress config file and add these keys along with details of the database, we have setup for wordpress. Below is a sample config file-
sudo nano /var/www/wordpress/wp-config.php
PHP
<?php
/* MySQL settings - You can get this
info from your web host */
/** The name of database for WordPress */
define( 'DB_NAME', 'wordpress' );
/** MySQL database username */
define( 'DB_USER', 'wordpressuser' );
/** MySQL database password */
define( 'DB_PASSWORD', 'wordpress' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
/** Database Charset to use in
creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type.
Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {
* @link https://api.wordpress.org/secret-key/1.1/salt/
* WordPress.org secret-key service}
* You can change these at any point in time to
* invalidate all existing cookies. This will force
* all users to have to log in again.
*
* @since 2.6.0
*/
define('AUTH_KEY', ':BiuKIi%W7<p?4Jm}`1XTJOw!cQBKxcOt]DylUDyO$BB<>t)*FN.qf*q|+-W7}8f');
define('SECURE_AUTH_KEY', '7[Kh-{P#A~<PGMkIOHC#9Fta$XGemco5F8k}G66I[lXqD|`IZ8cyM2O>!NjtvW(o');
define('LOGGED_IN_KEY', 'La{SEJ{$uI<6Txgv QqY4cxG]3+-r[Iqcx.IFxlfN.f/Yd?317zR*+Yt=*PMWM$(');
define('NONCE_KEY', 'U5pGQf.`J{.Hd~P/9Snw`V2+#<t+;>OTY!VOW[-aoruh;dhSUX]09xj*O<KXdZ6+');
define('AUTH_SALT', 'fmByAIfcEq&V}Xf,mF)!a09:-Q$R^/:79!k|<pEL@>VU)|C7|(>;`{N(4ZHg O)n');
define('SECURE_AUTH_SALT', 's5N%EIR(eM@tlg;M%L-+F#:<|r_x5-]Ix.&eYN)ya5ktoWLE+H~zUGkX#HceO/;H');
define('LOGGED_IN_SALT', 'EGcaE`=DAh7lv*klFyV0VLy5<@af_*--3otD$3:^;z~C(f^JB[C0T;`yqE)2@y${');
define('NONCE_SALT', 'rP1%&ojrP0XLRuQ1AS#@u}#2-Q+)5ftKeJpWC$oxD]?&3}|+n2Gt{1$`kZbSW`-q');
/**#@-*/
/**
* WordPress Database Table prefix.
*
* You can have multiple installations in
* one database if you give each
* a unique prefix. Only numbers, letters,
* and underscores please!
*/
$table_prefix = 'blog_';
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display
* of notices during development.
* It is strongly recommended that plugin
* and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that
* can be used for debugging,
* visit the documentation.
*
* @link https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/
*/
define( 'WP_DEBUG', false );
/* That's all, stop editing! Happy publishing. */
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
?>
- Change database name, database user, and password to the values that we have created while configuring MySQL.
- Change the salt keys from the keys that you have received when requested wordpress
- Changing table prefix from "wp_" to "blog_" which is optional
Setting up WordPress: Now start the apache2 server and visit the WordPress installation
sudo service apache2 start
// visit 127.0.0.1/wordpress
Now select the user language
Select language
Now configure WordPress user details(This will be the default admin user)
User and site details- Give your WordPress a Site Name
- Now choose a username for the user
- Now give a password
- Give a valid email (The email in the image) should not be used in Production).
- Search engine visibility means gives site admin to allow search engines to index the site.
After you click “Install WordPress”, WordPress will be installed, and you will get a success screen.
WordPress installed successfully
Now, login into the WordPress dashboard using your login details
Login into WordPress
After login, you can see the WordPress dashboard
WordPress Dashboard
Now you can see your WordPress site by visiting its URL
http://127.0.0.1/wordpress
WordPress successfully running
Similar Reads
PHP Tutorial PHP is a popular, open-source scripting language mainly used in web development. It runs on the server side and generates dynamic content that is displayed on a web application. PHP is easy to embed in HTML, and it allows developers to create interactive web pages and handle tasks like database mana
9 min read
Basics
PHP SyntaxPHP, a powerful server-side scripting language used in web development. Itâs simplicity and ease of use makes it an ideal choice for beginners and experienced developers. This article provides an overview of PHP syntax. PHP scripts can be written anywhere in the document within PHP tags along with n
4 min read
PHP VariablesA variable in PHP is a container used to store data such as numbers, strings, arrays, or objects. The value stored in a variable can be changed or updated during the execution of the script.All variable names start with a dollar sign ($).Variables can store different data types, like integers, strin
5 min read
PHP | FunctionsA function in PHP is a self-contained block of code that performs a specific task. It can accept inputs (parameters), execute a set of statements, and optionally return a value. PHP functions allow code reusability by encapsulating a block of code to perform specific tasks.Functions can accept param
8 min read
PHP LoopsIn PHP, Loops are used to repeat a block of code multiple times based on a given condition. PHP provides several types of loops to handle different scenarios, including while loops, for loops, do...while loops, and foreach loops. In this article, we will discuss the different types of loops in PHP,
4 min read
Array
PHP ArraysArrays are one of the most important data structures in PHP. They allow you to store multiple values in a single variable. PHP arrays can hold values of different types, such as strings, numbers, or even other arrays. Understanding how to use arrays in PHP is important for working with data efficien
5 min read
PHP Associative ArraysAn associative array in PHP is a special array where each item has a name or label instead of just a number. Usually, arrays use numbers to find things. For example, the first item is at position 0, the second is 1, and so on. But in an associative array, we use words or names to find things. These
4 min read
Multidimensional arrays in PHPMulti-dimensional arrays in PHP are arrays that store other arrays as their elements. Each dimension adds complexity, requiring multiple indices to access elements. Common forms include two-dimensional arrays (like tables) and three-dimensional arrays, useful for organizing complex, structured data.
5 min read
Sorting Arrays in PHPSorting arrays is one of the most common operation in programming, and PHP provides a several functions to handle array sorting. Sorting arrays in PHP can be done by values or keys, in ascending or descending order. PHP also allows you to create custom sorting functions.Table of ContentSort Array in
4 min read
OOPs & Interfaces
MySQL Database
PHP | MySQL Database IntroductionWhat is MySQL? MySQL is an open-source relational database management system (RDBMS). It is the most popular database system used with PHP. MySQL is developed, distributed, and supported by Oracle Corporation. The data in a MySQL database are stored in tables which consists of columns and rows.MySQL
4 min read
PHP Database connectionThe collection of related data is called a database. XAMPP stands for cross-platform, Apache, MySQL, PHP, and Perl. It is among the simple light-weight local servers for website development. Requirements: XAMPP web server procedure: Start XAMPP server by starting Apache and MySQL. Write PHP script f
2 min read
PHP | MySQL ( Creating Database )What is a database? Database is a collection of inter-related data which helps in efficient retrieval, insertion and deletion of data from database and organizes the data in the form of tables, views, schemas, reports etc. For Example, university database organizes the data about students, faculty,
3 min read
PHP | MySQL ( Creating Table )What is a table? In relational databases, and flat file databases, a table is a set of data elements using a model of vertical columns and horizontal rows, the cell being the unit where a row and column intersect. A table has a specified number of columns, but can have any number of rows. Creating a
3 min read
PHP Advance
PHP SuperglobalsPHP superglobals are predefined variables that are globally available in all scopes. They are used to handle different types of data, such as input data, server data, session data, and more. These superglobal arrays allow developers to easily work with these global data structures without the need t
6 min read
PHP | Regular ExpressionsRegular expressions commonly known as a regex (regexes) are a sequence of characters describing a special search pattern in the form of text string. They are basically used in programming world algorithms for matching some loosely defined patterns to achieve some relevant tasks. Some times regexes a
12 min read
PHP Form HandlingForm handling is the process of collecting and processing information that users submit through HTML forms. In PHP, we use special tools called $_POST and $_GET to gather the data from the form. Which tool to use depends on how the form sends the dataâeither through the POST method (more secure, hid
4 min read
PHP File HandlingIn PHP, File handling is the process of interacting with files on the server, such as reading files, writing to a file, creating new files, or deleting existing ones. File handling is essential for applications that require the storage and retrieval of data, such as logging systems, user-generated c
4 min read
PHP | Uploading FileHave you ever wondered how websites build their system of file uploading in PHP? Here we will come to know about the file uploading process. A question which you can come up with - 'Are we able to upload any kind of file with this system?'. The answer is yes, we can upload files with different types
3 min read
PHP CookiesA cookie is a small text file that is stored in the user's browser. Cookies are used to store information that can be retrieved later, making them ideal for scenarios where you need to remember user preferences, such as:User login status (keeping users logged in between sessions)Language preferences
9 min read
PHP | SessionsA session in PHP is a mechanism that allows data to be stored and accessed across multiple pages on a website. When a user visits a website, PHP creates a unique session ID for that user. This session ID is then stored as a cookie in the user's browser (by default) or passed via the URL. The session
7 min read