In this guide, we will walk through the process of setting up a WordPress server on an Ubuntu system. This includes installing and configuring the necessary software such as PHP, Nginx, and MySQL. Each command will be explained to ensure a clear understanding of the steps involved.
1. Update and Upgrade Your System
First, ensure your system is up to date:
sudo apt-get update -y
sudo apt-get update -y
: This command updates the package lists for upgrades and new package installations. The-y
flag automatically confirms the action.
sudo apt-get upgrade -y
sudo apt-get upgrade -y
: This command upgrades all installed packages to their latest versions. Again, the-y
flag confirms the action without prompting.
2. Install PHP and Related Packages
Next, install PHP and some common PHP extensions required by WordPress:
sudo apt-get install php7.2-cli php7.2-common php7.2-fpm php7.2-mysql php7.2-curl -y
sudo apt-get install php7.2-cli php7.2-common php7.2-fpm php7.2-mysql php7.2-curl -y
: Installs the command-line interface for PHP, common PHP modules, the FastCGI Process Manager (FPM), MySQL support, and cURL support.
sudo apt-get install php7.2-json php7.2-cgi php7.2-gd php-pclzip php7.2-zip php7.2-xml -y
sudo apt-get install php7.2-json php7.2-cgi php7.2-gd php-pclzip php7.2-zip php7.2-xml -y
: Installs additional PHP modules for JSON, CGI, GD (graphics), ZIP, and XML support.
sudo apt-get install php7.2 php-common php7.2-readline php7.2-mbstring php7.2-intl -y
sudo apt-get install php7.2 php-common php7.2-readline php7.2-mbstring php7.2-intl -y
: Installs more PHP modules for reading input, multibyte string support, and internationalization.
3. Install Additional Required Packages
Now, install some additional tools and libraries needed for the server:
sudo apt-get install gcc make autoconf libc-dev pkg-config -y
sudo apt-get install gcc make autoconf libc-dev pkg-config -y
: Installs the GNU Compiler Collection (gcc), make utility, autoconf, and development libraries.
sudo apt-get install nginx git curl vim libmcrypt-dev zip unzip -y
sudo apt-get install nginx git curl vim libmcrypt-dev zip unzip -y
: Installs the Nginx web server, Git version control, curl, Vim text editor, mcrypt library, and tools for handling ZIP files.
sudo apt-get install software-properties-common -y
sudo apt-get install software-properties-common -y
: Installs software-properties-common, which adds the ability to manage software repositories.
4. Configure the Web Server
Stop Apache if it is running and start Nginx:
sudo service apache2 stop
sudo service apache2 stop
: Stops the Apache2 web server service.
sudo service nginx start
sudo service nginx start
: Starts the Nginx web server service.
Start PHP-FPM service:
sudo service php7.2-fpm start
sudo service php7.2-fpm start
: Starts the PHP 7.2 FastCGI Process Manager (FPM) service.
Check the status of Nginx and PHP-FPM services:
sudo service nginx status
sudo service nginx status
: Checks the status of the Nginx service to ensure it is running correctly.
sudo service php7.2-fpm status
sudo service php7.2-fpm status
: Checks the status of the PHP-FPM service to ensure it is running correctly.
5. Set Permissions for the Web Directory
Navigate to the web directory and set appropriate permissions:
cd /var/www
cd /var/www
: Changes the current directory to/var/www
, where the web files are stored.
ls -la
ls -la
: Lists all files and directories in/var/www
with detailed information.
sudo chown -R ubuntu:ubuntu html
sudo chown -R ubuntu:ubuntu html
: Changes the ownership of thehtml
directory and its contents to theubuntu
user and group.
sudo chmod -R 777 html
sudo chmod -R 777 html
: Sets read, write, and execute permissions for all users on thehtml
directory and its contents. Note: This is not recommended for production environments due to security risks.
Navigate to the html
directory and clean it up:
cd /var/www/html
cd /var/www/html
: Changes the current directory to/var/www/html
.
sudo rm -rf /var/www/html
sudo rm -rf /var/www/html
: Recursively deletes all files and directories within/var/www/html
.
Setting Up the Database
1. Update and Upgrade Your System
Ensure your system is up to date:
sudo apt-get update -y
sudo apt-get update -y
: Updates the package lists for upgrades and new package installations.
sudo apt-get upgrade -y
sudo apt-get upgrade -y
: Upgrades all installed packages to their latest versions.
2. Install Required Packages
Install software properties common:
sudo apt-get install software-properties-common -y
sudo apt-get install software-properties-common -y
: Installs software-properties-common to manage software repositories.
3. Install and Configure MySQL
Set the MySQL root password:
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
: Pre-configures the MySQL root password asroot
for automated installation.
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
: Confirms the MySQL root password.
Install MySQL server and client:
sudo apt-get install mysql-server mysql-client -y
sudo apt-get install mysql-server mysql-client -y
: Installs the MySQL server and client.
Edit the MySQL configuration file:
sudo sed -i -e 's/bind-address/#bind-address/g' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo sed -i -e 's/bind-address/#bind-address/g' /etc/mysql/mysql.conf.d/mysqld.cnf
: Comments out thebind-address
line to allow MySQL to accept connections from any IP address.
sudo sed -i -e 's/skip-external-locking/#skip-external-locking/g' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo sed -i -e 's/skip-external-locking/#skip-external-locking/g' /etc/mysql/mysql.conf.d/mysqld.cnf
: Comments out theskip-external-locking
line.
Grant privileges to the MySQL root user:
mysql -u root -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root'; FLUSH privileges;"
mysql -u root -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root'; FLUSH privileges;"
: Grants all privileges to the MySQL root user and flushes the privileges.
Restart the MySQL service:
sudo service mysql restart
sudo service mysql restart
: Restarts the MySQL service to apply changes.
This article provides a comprehensive guide to setting up a WordPress server on an Ubuntu system. It covers installing and configuring necessary software including PHP, Nginx, and MySQL, with detailed explanations of each command to facilitate understanding and implementation.