Thursday, December 12, 2024

Install Wordpress on ubuntu With Nginx

👉 In this tutorial, we will guide you through the process of installing and configuring WordPress on a freshly set up Ubuntu server.


  • Why Nginx Use Additional PHP-FPM Configuration ?
  • Apache directly embeds the PHP interpreter within each request, whereas Nginx relies on an external program to process PHP and act as a bridge between the web server and the PHP interpreter.
  • This approach generally provides better performance for PHP-based websites, but it requires extra configuration. Specifically, you'll need to install php8.1-fpm (PHP FastCGI Process Manager), which utilizes the current PHP version (as of this writing). This configuration tells Nginx to forward PHP requests to php-fpm for processing.

Prerequisites:


Step 1) Install LEMP Stack (Linux, Nginx, MySQL, PHP)

Step 2) Install Wordpress

Step 3) Configure Nginx VirtualHost for WordPress

Step 4) Update /etc/hosts file

Step 5) Install phpMyAdmin

Step 6) Configure WordPress Installation



Step 1) Install LEMP Setup (Nginx, Mysql, PHP)


Install Nginx:


sudo apt update && sudo apt install nginx -y

sudo systemctl start nginx && sudo systemctl enable nginx


Install MySQL:


sudo apt install mysql-server -y

sudo mysql -u root -p -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';" sudo service mysql restart

 

a) log into MySQL.

sudo mysql -u root -p

 

b) Create a database and user for WordPress.

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


Install PHP: via bash script file.



Restart The Service:

sudo systemctl start php8.1-fpm
sudo systemctl enable php8.1-fpm
sudo systemctl status php8.1-fpm


Step 2) Install Wordpress


cd /tmp

wget https://wordpress.org/latest.tar.gz

tar -zxvf latest.tar.gz

sudo mv wordpress /var/www/html


sudo chown -R www-data:www-data /var/www/html/wordpress

sudo chmod -R 755 /var/www/html/wordpress


Step 3) Configure Nginx VirtualHost for WordPress


sudo vim /etc/nginx/sites-available/tech2towards.local


Add the Following Configuration:

 


a) Activate your configuration by linking to the configuration file from Nginx’s sites-enabled directory:


sudo ln -s /etc/nginx/sites-available/tech2towards.local /etc/nginx/sites-enabled/

b) Then, unlink the default configuration file from the /sites-enabled/ directory:

sudo unlink /etc/nginx/sites-enabled/default
sudo systemctl restart nginx php8.1-fpm


Step 4) Configure /etc/hosts file


sudo nano /etc/hosts


Add the following entry:


127.0.1.1   tech2towards.local


Step 5) Install phpMyAdmin:

Download Latest Version From : Here

cd /tmp

wget https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.zip

sudo unzip phpMyAdmin-5.2.1-all-languages.zip


sudo mv phpMyAdmin-5.2.1-all-languages phpmyadmin

sudo mv phpmyadmin /var/www/html/wordpress/phpmyadmin

sudo echo "<?php phpinfo(); ?>" > /var/www/html/wordpress/info.php 


Step 6) Configure WordPress Installation:


Now, you need to configure WordPress to connect to the database you created earlier.

a) Go to your WordPress directory:

cd /var/www/html/wordpress/

sudo cp -a wp-config-sample.php wp-config.php

b) Edit the wp-config.php file:

sudo vim wp-config.php

c) Find the following lines and update them with your database details:

  • define('DB_NAME', 'wordpress_db');
  • define('DB_USER', 'wordpress_user');
  • define('DB_PASSWORD', '123456');
  • define('DB_HOST', 'localhost');


d) Save and close the file.

e) Now, Check In Web Browser

  • For Local Machine : http://tech2towards.local/
  • For Cloud Machine: http://Server-Public-Ip/



! END !



Install LEMP Via Single Script File:- Optional*

Note : Make Sure Your Machine Should Be Fresh Other Wise you will be get Error !!!!! 

 

 




 

No comments:

Post a Comment

testing