Mud: Use nginx to build a WordPress blog using a virtual host, nginxwordpress

Source: Internet
Author: User
Tags install wordpress wordpress blog

Mud: Use nginx to build a WordPress blog using a virtual host, nginxwordpress

This article was sponsored by Xiuyi linfeng and first launched in the dark world.

Recently, I plan to learn about nginx web servers. Since it is learning or practical. We will build a WordPress blog here as an example.

To build a WordPress blog, we need the Mysql database, PHP environment, and Nginx Web server. The procedure is as follows:

1. Mysql database installation and configuration

2. installation and configuration of PHP, PHP-FPM and related PHP Components

3. Nginx Web Server construction and Configuration

4. install wordpress

Note: In this experiment, apart from installing nginx using the source code, all other software is installed using the rpm package yum.

I,MysqlDatabase installation and configuration

1.1 mysqlDatabase Installation

Mysql database, we use yum for installation. As follows:

Yum-y install mysql-server

1.2Modify the mysql Database root User Password and configure Remote Access Permissions

After the mysql database is installed, start the mysql database, modify the settings of the mysql database, and create the ailanni database for wordpress. As follows:

/Etc/init. d/mysqld start

Modify the password of the root user of the mysql database. The default password of the root user is blank after the mysql database is installed. Run the following command:

Mysql-u root-p or mysql-uroot-p

Use mysql;

Update user set password = password ('000000') where user = 'root ';

Flush privileges;

/Etc/init. d/mysqld restart

By default, the mysql database only allows local access to the mysql database. However, for the convenience of mysql database management, we need to enable the remote access permission for mysql database. Run the following command:

Mysql-u root-p or mysql-uroot-p

Use mysql;

Update user set host = '%' where user = 'root ';

Flush privileges;

/Etc/init. d/mysqld restart

After the above configuration is complete, you will find that the mysql connection is very slow. You only need to modify the configuration file of the mysql database.

Open the/etc/my. cnf file, add skip-name-resolve to mysqld, and then restart the mysql database. As follows:

Vi/etc/my. cnf

/Etc/init. d/mysqld restart

1.3Create a database for wordpress

After the preceding operations, we can connect to the mysql database. Here we use the Navicat Premium database client.

Use Navicat Premium to create the database required by the Wordpress blog. For details about how to use Navicat Premium to create a mysql database, refer to "mud: Navicat Premium to use mysql Database". After the database is created, it is as follows:

Of course, we can also use phpmyadmin to create the required database for wordpress.

For installing and using phpmyadmin on nginx, I will introduce it in the next article.

II,PHP,PHP-FPMAndPHPInstallation and configuration of related components

After the mysql database is installed, configure the php environment.

2.1Install PHP and related components

First install php and related components and run the following command:

Yum-y install php *

In related components of php, we must pay attention to the two components: php-mysql and php-fpm. If you use php-mysql to connect to mysql, you will be prompted when installing WordPress: Your php does not seem to have installed the MySQL extension necessary to run WordPress. After installation, restart the mysql database. Otherwise, wordpress cannot connect to the mysql database.

While php-fpm is used in combination with nag.pdf, nginx itself does not support php, and php language is resolved through php-fpm and nginx.

The two components can be installed separately as follows:

Yum-y install php-mysql

Yum-y install php-fpm

After the above installation is complete, let's check the php version. As follows:

Php-v

2.2Configure php-fpm

After installing php-related components, we need to configure php-fpm.

View the related installation documents of php-fpm as follows:

Rpm-ql php-fpm

We can see the related configuration file of php-fpm. The main configuration file is/etc/php-fpm.conf, now view the configuration file, as follows:

More/etc/php-fpm.conf

You will find that the configuration file is not defined at all. The port to be listened to and the address to be listened to by php-fpm.

Why do we say the analysis is incorrect?

In fact, there is nothing wrong with our analysis. Note, we marked the part.

Include =/etc/php-fpm.d/*. conf

This statement is very important and contains the key part of the configuration in php-fpm. The key configuration file is the www. conf file marked in the php-fpm installation diagram.

// Etc/php-fpm.d/www. conf

Now let's check the file, as shown below:

More/etc/php-fpm.d/www. conf

In this figure, the marked part shows the address and port to be listened to by php-fpm.

This figure shows the users and user groups used to run the php-fpm process. Here, we use the default user and User Group apache.

To put it bluntly, if we have installed php-fpm without any configuration, use the default configuration.

Of course, if you want to further optimize the php-fpm configuration, you can use the configuration template provided during the php-fpm installation. The configuration template is located:

More/usr/share/doc/php-fpm-5.3.3/php-fpm.conf.default

After the above configuration is complete, start php-fpm and check whether the listening port and address are normal. As follows:

/Etc/init. d/php-fpm start

Chkconfig php-fpm on

Netstat-tunlp | grep 9000

Ps aux | grep php-fpm

Through this, we can see that php-fpm is currently running normally. The listening address and port are 127.0.0.1: 9000, and php-fpm is run by apache users. The main process is running as the root user.

Through the php-fpm startup method, we can see that php-fpm is running in the service mode. Then we can restart and disable php-fpm through the server. As follows:

/Etc/init. d/php-fpm restart

/Etc/init. d/php-fpm stop

III,Nginx WebServer construction and Configuration

3.1InstallNginx

Upload the downloaded nginx file to the server and run the following command:

Scp tengine-2.0.3.tar.gz root@192.168.1.102:/tmp

Ifconfig eth0 | grep "inet addr" | awk '{print $2}' | cut-d:-f2

Decompress nginx and compile and install nginx as follows:

Tar-xf/tmp/tengine-2.0.3.tar.gz-C ./

./Configure

Make & make install

3.2Start nginx

After nginx is installed, start nginx. Nginx can be started in two ways.

One is as follows:

/Usr/local/nginx/sbin/nginx

Another method is as follows:

/Usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx. conf

In fact, the first method is to load the/usr/local/nginx/conf/nginx. conf configuration file by default.

We can see it clearly. Nginx has been started and can be accessed normally.

Now let's look at the users running nginx, as follows:

Ps-aux | grep nginx

We can see that nginx is currently running under the nobody user.

3.3Configure Nginx to support php

After nginx is installed, We need to configure nginx to support php, and we also need to configure nginx for wordpress to be installed as a virtual host.

Configure the php options first.

Remove all comments related to fastcgi in the nginx configuration file. As follows:

Vi/usr/local/nginx/conf/nginx. conf

Location ~ \. Php $ {

Root html;

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME$ Document_root$ Fastcgi_script_name;

Include fastcgi_params;

}

After the above configuration is complete, we will configure the homepage for nginx. Add the index. php file as follows:

Location /{

Root html;

Index. php index.html index.htm;

}

Now let's test whether the nginx php configuration is correct. Edit the index. php file and add <? Php phpinfo () ;?>, As follows:

Vi./html/index. php

Run the following command to test whether the nginx configuration is correct and then restart nginx elegantly:

/Usr/local/nginx/sbin/nginx-t

/Usr/local/nginx/sbin/nginx-s reload

We can see that nginx currently supports php normally.

3.4Configure Nginx to support Virtual Hosts

After configuring nginx for php, We will configure the nginx virtual host.

In fact, nginx configuration is very simple, the entire configuration file. There is only one http tag, and the virtual host configuration is one server tag.

However, the server tag must be included in the http tag. The purpose is that the server tag can exist either in the configuration file where http is located or in a separate file, however, you need to use include in the http tag.

Below is a virtual host a.ilanni.com I configured, as shown below:

Vi/usr/local/nginx/conf/nginx. conf

Server {

Listen 80;

Server_name a.ilanni.com;

Root/ilanni/a.ilanni.com /;

Index. php;

Location ~ \. Php $ {

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME$ Document_root$ Fastcgi_script_name;

Include fastcgi_params;

}

}

Note: I am storing the root directory of the.ilanni.com virtual host in the directory/ilanni/a.ilanni.com/and the user group of the virtual host is root.for example:

To make a difference from the default nginx homepage, I now use a php probe for the home page of the VM a.ilanni.com.

After configuring the VM, restart nginx as follows:

/Usr/local/nginx/sbin/nginx-t

/Usr/local/nginx/sbin/nginx-s reload

We can see it clearly. Currently, the VM a.ilanni.com can be accessed normally and the php probe I mentioned is displayed.

IV,WordpressInstall

We have installed wordpress above. All the mysql Databases and nginx web servers required have been set up.

Now we will upload the wordpress installation package to the server for decompression as follows:

Scp wordpress-4.0-zh_CN.tar.gz root@192.168.1.213:/ilanni

Tar-xf wordpress-4.0-zh_CN.tar.gz

Copy the extracted file to the root directory a.ilanni.com of the VM, as shown below:

Cp-rv./wordpress a.ilanni.com/

Start to install wordpress and access a.ilanni.com in the browser as follows:

Enter information about the mysql database. As follows:

Copy this information to the file wp-config.php. If the file does not exist, create a wp-config.php file under the.ilanni.com root directory, as shown below:

Vi wp-config.php

Set the Sydney type of the blog as follows:

The prompt is as follows:

Access the home page of the VM a.ilanni.com as follows:

The installation of the wordpress blog under nginx has been completed.


Using wordpress to create a blog under the second-level directory, how do I set pseudo-static settings when the host is an nginx virtual host? Independent hosts must be used by the Space Provider

You can upload wordpress to the second-level directory under the second-level directory and access and install it.

How to build a website on a VM

To build a wordpress website, you need to support the php program with a free mysql database. A-MB database is about 50 MB. There is a basic space in the ecentury host that is similar to this configuration. For more than one hundred yuan a year, free individuals feel that they are not very stable and have no technical support. It is difficult to find someone when they need assistance, it's easy to find someone. After you purchase the product, you can contact the technical support on the website to help you install one. You can also download a wordpress and access your domain name as prompted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.