How to Install WordPress Locally: Step-by-Step Guide
Step 1: Open Local
- Open the Local app on your computer.
- If you’re following along, the interface may look slightly different.
- Click on the plus (+) button at the bottom left corner to create a new site.
Step 2: Name Your Site
- You’ll be asked to name your site. For this course, name it Udemy (or any name you prefer).
- Advanced options are available below, but it’s unnecessary to change these settings unless you’re experienced.
Step 3: Configure the Environment
- WordPress requires three programs to run: PHP, a web server, and a database.
- Select the Custom option to configure them manually.
Step 4: Install PHP
- WordPress is built using PHP, so it’s essential to install it.
- Select PHP version 8 (or a higher version if available).
- Using older PHP versions is possible, but they are more vulnerable to security issues.
Step 5: Set Up the Web Server
- Choose between Apache or Nginx as your web server.
- Both are compatible with WordPress. For this course, select Nginx.
- If you prefer Apache, feel free to choose it.
Step 6: Configure the Database
- Choose between MySQL and MariaDB as your database.
- For this course, MariaDB is selected, but MySQL works just as well.
Step 7: Create a WordPress Admin User
- Create a new WordPress user with administrator privileges.
- Input basic login details like username and password.
- Since the server is only accessible locally, security isn’t a major concern.
Step 8: Install the Programs
- After setting up, click Add Site to start the installation process.
- It may take a few minutes to install PHP, Nginx, and MariaDB.
Step 9: Test the WordPress Installation
- Once installation is complete, ensure the server is running. If it’s not, click the Start button.
- Click Open Site to view the WordPress site in your browser.
- Your WordPress site should now be up and running.
Requirements
To run WordPress, it’s recommended your host supports:
- PHP version 7.4 or greater.
- MySQL version 8.0 or greater OR MariaDB version 10.5 or greater.
- HTTPS support
That’s really it. Apache or Nginx is recommended as the most robust and featureful server for running WordPress, but any server that supports PHP and MySQL will do. That said, for the smoothest experience in setting up—and running—your site, each host on the hosting page supports the above and more with no problems.
For detailed PHP extension recommendations, see the Hosting Handbook.
Note: If you are in a legacy environment where you only have older PHP or MySQL versions, WordPress also works with PHP 7.2.24+ and MySQL 5.5.5+. However, these versions have reached their official End Of Life and may expose your site to security vulnerabilities.
Quick Tour of Local
Step 1: Select Your WordPress Site
- Open Local after creating your WordPress site.
- On the left side, you will see a list of sites registered on your machine.
- Select the site you recently created.
Step 2: Domain Overview
- Look at the domain provided on the right side.
- This domain is not officially registered, so other users can’t visit it.
- Local modifies machine settings to intercept requests to this domain and deliver files from your WordPress site.
- If you need, you can change the domain by clicking on the “Change” button.
Step 3: SSL Certificate Setup
- Local automatically generates an SSL certificate for your site.
- This ensures your development environment reflects a secure production environment.
- If you can’t access your site through your browser, click on the “Trusted” button to allow the browser to visit your site.
Step 4: Change Web Server (Optional)
- Local allows you to switch between web servers (e.g., Apache or Nginx) without creating a new server.
- You can also change the PHP version for compatibility testing with older versions.
Step 5: Database Considerations
- Switching databases (MySQL or MariaDB) is not possible for an existing site.
- However, your code will remain compatible with both databases.
Step 6: Admin Login
- You have the option to log in as an administrator.
- This feature allows you to skip the login process, but it might not work if your site isn’t running.
Step 7: WordPress Version and Multisite
- You can view the current WordPress version and check whether Multisite is enabled.
- For this course, Multisite won’t be covered.
Step 8: Database Tab
- View database credentials here.
- Don’t worry if you’re not familiar with database management, as it will be covered later in the course.
Step 9: Tools for Debugging
- Local installs additional tools like Adminer to help you interact with the database.
Step 10: Mail Hog and Live Features
- Mail Hog: A tool for testing emails in your development environment.
- Live Local: Allows you to expose your site to the public, but use this feature carefully as it gives others direct access to your machine.
Step 11: Project File Location
- Under the site name, you will find the path to your project.
- Clicking on it will open the file explorer with three folders:
- Configuration: Contains configuration files for each program.
- Logs: Stores error logs for debugging.
- App: Contains WordPress files where most of your work will happen.
Section: Introduction to PHP Fundamentals
Step 1: Understanding PHP
- PHP is the programming language that WordPress is built with.
- It runs on servers to process web pages.
Step 2: What is PHP?
- PHP allows us to give instructions to a machine, such as registering a new user or processing a purchase.
- It is focused on web development, making it a popular choice for creating websites.
Step 3: PHP’s Popularity
- PHP powers over 79% of websites, meaning 8 out of every 10 sites you visit are written in PHP.
Step 4: How PHP Works
- PHP must be installed on a server, which can be a dedicated server or a personal machine.
- PHP code is written inside a
.php
file. - This code performs tasks and runs only on the server, not in the browser.
Step 5: Generating HTML
- PHP produces an HTML file that can be sent to the browser.
- The browser then renders the HTML file, displaying the content to users.
Step 6: Setting Up a PHP File
- Point your code editor to the WordPress project folder.
- Open the local dashboard to find the full path.
- Navigate to the
app/public
directory and create a file namedtest.php
.
Step 7: Writing HTML in PHP
- Write valid HTML inside the
test.php
file. - Typically, wrap the content in HTML and body tags, but keep it simple for demonstration.
Step 8: Viewing the File in the Browser
- Ensure your server is running before accessing the file.
- Type
test.php
after the domain in the browser’s address bar to view the file.
Step 9: Server Functionality
- The server automatically serves files from the
app/public
directory without needing full paths.
Step 10: Checking Developer Tools
- Press F12 to open Chrome Developer Tools or access it through the menu.
- Familiarize yourself with the Elements and Network panels.
Step 11: Understanding File Types
- The Network panel shows various files received from the server.
- For the
test.php
file, the type will be listed as “document,” indicating it is processed as HTML.
Step 12: Key Concept
- Browsers only receive HTML output from PHP files; they never see the actual PHP code.
Step 13: Next Steps
- We will begin learning more PHP features in the following lecture.
Section: Understanding Variables in PHP
Step 1: Introduction to Variables
- Variables are essential in programming as they allow us to store values.
- Similar to variables in math, where “x” can represent a numeric value.
Step 2: Types of Data
- In PHP, variables can store various data types, including:
- Names
- Addresses
- File data
Step 3: Creating a PHP File
- Open the
test.php
file in your editor. - Add a pair of PHP tags at the top of the file:phpCopy code
<?php
- PHP is different from HTML, as it can perform calculations and complex logic.
Step 4: PHP and HTML
- HTML cannot contain intelligent instructions.
- PHP can be used to output HTML based on conditions.
Step 5: Rules for Writing PHP
- Do not write HTML inside PHP tags (you can write HTML outside).
- Multiple PHP tags can be used in the same file.
- Closing PHP tags are optional if the file ends with PHP code. It’s good practice to omit the closing tag if not needed.
Step 6: Declaring a Variable
- To create a variable, use the dollar sign (
$
) followed by the variable name. - Example:phpCopy code
$age;
- Variable names must start with a letter or underscore and can contain alphanumeric characters.
Step 7: Assigning a Value
- Use the equal sign (
=
) to assign a value to the variable:phpCopy code$age = 28; // Assign your age
- End the line with a semicolon (
;
).
Step 8: Formatting Code
- You can format your code for readability by adding spaces and new lines.
- Keep in mind that PHP and HTML can be written in multiple lines for clarity.
Step 9: Running the Code
- Refresh the browser to check the output. (Note: Nothing will display yet as we only created a variable.)
Step 10: Outputting a Variable
- Use the
echo
statement to output the variable’s value:phpCopy codeecho $age;
- This will display the value stored in the variable in the browser.
Step 11: Case Sensitivity of Variables
- Variables in PHP are case-sensitive.
- For example,
$age
and$AGE
are considered different variables. - Create another variable:phpCopy code
$AGE = 50;
- The output will still show the original
$age
variable’s value.
Step 12: Reassigning Variable Values
- To change the value of a variable, reassign it:phpCopy code
$age = 50; // Make sure to match the case
- Refresh the browser to see the new output.
Section: Understanding Strings and Booleans in PHP
Step 1: Introduction to Data Types
- PHP allows us to work with various values, not just numbers.
- Variables can store different types of data.
Step 2: Understanding Data Types
- A data type describes the type of data stored in a variable.
- Every variable has a data type, which PHP assigns automatically.
Step 3: Overview of Data Types
- Common data types in PHP include:
- Integers: Assigned to whole numbers.
- Floats: Assigned to decimal values.
- Strings: For raw text (names, addresses, etc.).
- Booleans: Representing true or false values.
- Arrays and Objects: Will have separate lectures.
- Null: A variable without a value.
Step 4: Working with Strings
- Strings are the data type for raw text made up of a sequence of characters.
- Example:phpCopy code
$name = 'Your Name'; // Create a string variable
- Strings are created by wrapping text in quotes (single or double quotes are acceptable).
Step 5: Outputting a String
- Use the
echo
statement to display the string:phpCopy codeecho $name; // Outputs the value of the variable
- Remember to end each line of code with a semicolon (
;
).
Step 6: Using Quotes
- Strings can be written in single or double quotes. There’s no functional difference; it’s a matter of preference.
- Example using double quotes:phpCopy code
$name = "Your Name"; // Also valid
Step 7: Introduction to Booleans
- A boolean is a data type where the value is either true or false.
- Create a variable called
is_logged_in
:phpCopy code$is_logged_in = true; // Assign a boolean value
Step 8: Naming Conventions
- For multi-word variable names:
- Use camelCase (capitalize each word except the first).
- Alternatively, use snake_case (separate words with underscores).
Step 9: Assigning Boolean Values
- Booleans can only hold two values: true or false.
- Example of changing the value:phpCopy code
$is_logged_in = false; // Change the value
Step 10: Outputting a Boolean
- If you echo a boolean variable:phpCopy code
echo $is_logged_in; // No output for false
- If the value is
true
, PHP outputs1
, but does not output the word “true”.
Step 11: Importance of Data Types
- Using appropriate data types is essential for optimizing PHP code.
- PHP processes booleans faster than strings due to the limited possible values.
Step 12: Handling Data Types
- Mixing data types can lead to unexpected behavior.
- Throughout the course, there will be practice with different data types to see how each can be useful.
Section: Exploring Functions in PHP
Step 1: Introduction to Functions
- Functions are a common feature in PHP and are heavily used in WordPress.
- A function is a block of code that performs a specific task.
Step 2: Writing a Basic Function
- Clear the existing code inside the PHP tags.
- Echo a welcome message directly to the user (e.g.,
echo 'Welcome to our website!';
). - While it’s acceptable to output a value directly, using functions is preferable for reusability.
Step 3: The Problem with Repetition
- If you want to output the same message multiple times or in different files, copying and pasting the code is inefficient.
- Changing the message later would require updating multiple files, which is tedious.
Step 4: Defining a Function
- Use the
function
keyword to define a function. - Name the function (e.g.,
greeting
), then add parentheses and curly brackets. - Example:phpCopy code
function greeting() { // code goes here }
Step 5: Moving Code Inside the Function
- Move the echo statement inside the function’s curly brackets.
- Remember that code inside functions is not executed until the function is called.
Step 6: Calling a Function
- After defining the function, call it by writing the function name followed by parentheses:phpCopy code
greeting(); // Calls the function
- This will execute the code inside the function and display the message.
Step 7: Reusing Functions
- Functions can be called multiple times in the application, providing code reusability.
- Example of calling the function twice:phpCopy code
greeting(); // First call greeting(); // Second call
Step 8: Function Parameters
- Initially, our function outputs the same message. To customize it, we can add parameters.
- Parameters allow functions to accept input values.
- Example of defining a function with a parameter:phpCopy code
function greeting($message) { echo $message; // Use the message variable }
Step 9: Passing Arguments
- Call the function with different messages:phpCopy code
greeting('Hello, User!'); // First greeting greeting('Welcome Back!'); // Second greeting
Step 10: Understanding Parameters vs. Arguments
- Parameters are variables defined in a function’s declaration.
- Arguments are the actual values passed to the function.
- The terms are often used interchangeably, but it’s important to know the distinction.
1. Introduction to Arrays:
- Arrays help store multiple pieces of data in a single variable.
- Useful for storing collections like blog posts or users.
2. Creating an Array:
- Use the
array()
function to create an array. - Example:phpCopy code
$food = array();
3. Adding Values to the Array:
- Add values inside the
array()
function, separated by commas. - Example:phpCopy code
$food = array('Pizza', 'Burger', 'Pasta');
4. Accessing Array Items:
- Use square brackets
[]
to access individual items by their index. - Indexes start at
0
. - Example:phpCopy code
echo $food[0]; // Outputs: Pizza
5. Exercise:
- Try accessing a different item from the array by changing the index number.
- Example:phpCopy code
echo $food[2]; // Outputs: Pasta
Section: Loops
1. Introduction to Loops:
- Loops allow us to output the entire contents of an array without manually writing multiple
echo
statements. - Instead of repeating code, loops simplify the process by automatically going through each item in the array.
2. Creating a Loop:
- Use the
while
loop to iterate through the array. - Structure of a
while
loop:phpCopy codewhile (condition) { // Code to execute }
3. Setting the Condition:
- The loop runs as long as the condition inside the parentheses is true.
- Example: Create a variable
count
starting at0
:phpCopy code$count = 0;
4. Using the count()
Function:
- The
count()
function is used to get the number of items in the array. - Example: The condition checks if
$count
is less than the total number of items:phpCopy codewhile ($count < count($food)) { // Code to execute }
5. Avoiding Infinite Loops:
- To avoid an infinite loop, increment the
$count
variable inside the loop. - Example:phpCopy code
$count++;
6. Outputting Array Values:
- Use the
$count
variable to access array items dynamically. - Example:phpCopy code
echo $food[$count];
7. Understanding the Loop Flow:
- The loop checks the condition.
- If the condition is true, it outputs the array value and increments the counter.
- The loop repeats until the condition becomes false.
8. Shorthand Syntax:
- You can use the increment operator (
++
) to simplify incrementing$count
by 1. - Example:phpCopy code
$count++;
9. Shorthand for Creating Arrays:
- Instead of using the
array()
function, you can create an array with square brackets. - Example:phpCopy code
$food = ['Pizza', 'Burger', 'Pasta'];