Install WordPress with Nginx on Debian 10

Step1.  Install Nginx, PHP, and MariaDB

WordPress requires a web server on which it will serve its content. It is written in PHP and uses a MySQL/MariaDB database to store its information. We can install Nginx, MariaDB, PHP, and other PHP modules by running the following command:

apt-get install nginx mariadb-server mariadb-client php-cgi php-common php-fpm php-pear php-mbstring php-zip php-net-socket php-gd php-xml-util php-gettext php-mysql php-bcmath unzip wget git -y

Once all the packages are installed, open the php.ini file and tweak some settings:

nano /etc/php/7.3/fpm/php.ini

Make the following changes:

post_max_size = 64M
memory_limit = 256M
max_execution_time = 300
upload_max_filesize = 32M
date.timezone = America/Chicago

Save and close the file, then restart PHP-FPM service to apply the configuration changes:

systemctl restart php7.3-fpm

Note: You can change the above PHP settings as per your requirements.

Step 2: Configure a WordPress Database

Next, we will need to create a database and user for WordPress. WordPress will use this database to store its information, and the user to have access to the database.

First, log in to MariaDB shell with the following command:

mysql -u root -p

Provide your root password when prompt then create a database and user with the following command:

MariaDB [(none)]> CREATE DATABASE wpdb;
MariaDB [(none)]> CREATE USER 'wpuser'@'localhost' identified by 'dbpassword';

Don’t forget to choose a strong password for your database user.

Now, you have a valid database and user for WordPress. Next, grant all the privileges to the WordPress database:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON wpdb.* TO 'wpuser'@'localhost';

Next, flush the privileges to apply the changes we’ve made and exit from the MariaDB shell with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Once you have done, you can proceed to the next step.

Step 3: Install WordPress

First, we will need to download the latest version of the WordPress source form its official website. Run the following command to download the latest release of WordPress:

cd /var/www/html/
wget https://wordpress.org/latest.tar.gz

Once the download is completed, extract the downloaded file with the following command:

tar -xvzf latest.tar.gz

Next, change the directory to wordpress and copy the sample configuration file:

cd wordpress
cp wp-config-sample.php wp-config.php

Next, open the file wp-config.php with the nano editor:

nano wp-config.php

Change the database, database user and password which we have created earlier:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wpdb' );

/** MySQL database username */
define( 'DB_USER', 'wpuser' );

/** MySQL database password */
define( 'DB_PASSWORD', 'dbpassword' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Save and close the file.

Then, change the ownership of the wordpress directory with the following command:

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

Step 4: Configure Nginx for WordPress

Next, we will need to create a Virtual Host configuration file for WordPress. You can create a new Virtual Host configuration file with the following command:

nano /etc/nginx/sites-available/wordpress.conf

Add the following lines:

server {
	listen 80;
	root /var/www/html/wordpress;
	index index.php index.html index.htm;
	server_name example.com;

	access_log /var/log/nginx/wordpress_access.log;
	error_log /var/log/nginx/wordpress_error.log;

	client_max_body_size 64M;

	location / {
		try_files $uri $uri/ /index.php?$args;
		}

	location ~ \.php$ {
		try_files $uri =404;
		include /etc/nginx/fastcgi_params;
		fastcgi_read_timeout 3600s;
		fastcgi_buffer_size 128k;
		fastcgi_buffers 4 128k;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		fastcgi_pass unix:/run/php/php7.3-fpm.sock;
		fastcgi_index index.php;
			}

		}

Make sure to replace example.com with your registered domain name. Save and close the file.

Then enable the newly created virtual block with the following command:

ln -s /etc/nginx/sites-available/wordpress.conf /etc/nginx/sites-enabled/

Finally, restart the nginx and PHP-FPM services to apply the configuration changes:

systemctl restart nginx
systemctl restart php7.3-fpm

Step 5: Access the WordPress Site

Now, open your web browser and visit the URL http://example.com. You will be redirected to the WordPress installation page:

Select your language and click on the Continue button. You should see the following page:

Provide your WordPress site name, Admin Username, Password, Email, and finally click on the Install WordPress button. Once the installation has been finished successfully, you should see the following page:

Now, click on the Log In button. You should see the WordPress login screen:

Provide your admin username or email and password, and click on the Log In button. You should see the WordPress default dashboard in the following screen:

That’s it. WordPress is now installed and ready to use. You can now start by installing new themes and plugins as per your needs. To learn more about WordPress visit the WordPress documentation.

Souce: https://www.rosehosting.com/blog/how-to-install-wordpress-with-nginx-on-debian-10/

返信を残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です