Build WordPress blog from scratch under Linux

Source: Internet
Author: User
Tags fpm phpinfo vps install wordpress phpmyadmin ssh access wordpress database wordpress blog

One, prepare the Linux environmentlocal virtual machines can ignore the first part

Weibo and the public platform are now in a mess of fire. Since the blog has been online, ready to write some of the process, the province later I forgot. It takes a long time to save a souvenir.


The full-text operating environment is Debian. Other Linux distributions have little difference.


No VPS can be installed on a computer Linux virtual machine to try, all the same.



sign in to VPS


under Windows I have been using the putty,linux is not much to say, ssh on the line. The password is not displayed under the Linux shell.


Change root password
    1. passwd
Copy Code

Add New User


Working with Root all the the while I think it's a pretty dangerous thing ...
    1. AddUser username
Copy Code

Username change to your own.


New user added to Sudo


is to add root permissions to the user.
    1. Nano/etc/sudoers
Copy Code

Locate the user privilege specification, and insert a row below

    1. Username All= (All:all) all
Copy Code

Cntrl+o Write, Cntrl+x exit, can also be directly cntrl+x exit, will prompt to save changes, enter Y save, cntrl+c cancel return. If the system does not have Sudo installed:

    1. Apt-get Update
    2. Apt-get Upgrade
    3. Apt-get Install sudo
Copy Code

Modify the SSH configuration file (with caution)


The SSH configuration file should default to the port that is used by default in/etc/ssh/ssh_config,ssh, which is not safe for individuals to think of using the default port of 22. Since the ports below 1024 are occupied by the Linux system, we can change from 1025 to 65536. Open configuration file

    1. Nano/etc/ssh/sshd_config
Copy Code

Find the port 22 line, such as 2222

    1. Port 2222
Copy Code

Disable remote connection of root account:

    1. Permitrootlogin No
Copy Code

Use SSH Protocol 2 only:

    1. Protocol 2
Copy Code

To add new user SSH access rights:

    1. Allowusers username #多用户空格隔开, denyusers is forbidden to access users
Copy Code

Speed up SSH login disable Usedns

    1. Usedns No
Copy Code

Save exit and restart SSH

    1. Reload SSH
Copy Code

Do not exit the current connection, log in with the new user and port, and if you cannot log in, check the SSH configuration file for errors.


Reference article:Getting started with SSH security and configuration


Two, Installing LNMP

LNMP is a set of server environment packages consisting of a series of open source software, taken from the initials of the Linux,nginx,mysql and PHP four words. Once tried military elder brother's Lnmp one key installs the package, installs the simple, the configuration is also simple. But I do not like this obsessive-compulsive disorder ready-made, to tell the truth in this piece of tinker for a long time. Because I can't understand the nginx configuration.


Install MySQL:


    1. sudo apt-get install Mysql-server
During the copy code installation, you will be asked to enter the root password. Execution after installation is complete
    1. sudo mysql_secure_installation
Copy the code and follow the instructions. It is recommended to disable root remote login.


Install Nginx:


Nginx ("Engine X") is a high-performance HTTP and reverse proxy server developed by a Russian company. Specific please Baidu encyclopedia.
    1. sudo apt-get install Nginx
Copy Code


Install PHP:
    1. sudo apt-get install php5-fpm php5-mysql
Copy the code so that all installations are complete


Start Nginx:
    1. sudo service nginx start
Copy code This step, if prompted by [Emerg] bind () to 0.0.0.0:80 failed (98:address already on use), is typically caused by Apache occupancy on port 80, killing all Apache processes:
    1. sudo killall apache2
Copy code to turn off Apache boot:
    1. sudo update-rc.d-f apache2 Remove
Copy the code in the browser to access your IP (local virtual machine is 127.0.0.1), the presence of welcome to Nginx, it indicates that Nginx started successfully.


Nginx configuration: Nginx configuration file in/etc/nginx/nginx.conf, specific settings please refer tonginx Battle Preparation-Optimization guide。 Notice two of these lines:
    1. include/etc/nginx/conf.d/*.conf;
    2. include/etc/nginx/sites-enabled/;
Copy the code under Nginx a virtual host is equivalent to a Web site, each virtual host configuration file is saved in the above two path. For ease of administration, I created a new conf configuration file under/etc/nginx/conf.d/. Open Nginx's default configuration file and modify it to support PHP:
    1. sudo nano/etc/nginx/sites-enable/default
Copy the code to locate the server module and press modify:
    1. root/usr/share/nginx/www; #网站根目录
    2. Index index.php index.html index.htm;
    3. server_name your_ip_address;
Copy the code down to location ~. php$, remove some comments
  1. Location ~. php$ {
  2. Fastcgi_split_path_info ^ (. +.php) (/.+) $;
  3. # # Note:you should has "cgi.fix_pathinfo = 0;" In php.ini
  4. #
  5. # # with php5-cgi alone:
  6. # Fastcgi_pass 127.0.0.1:9000;
  7. # with PHP5-FPM:
  8. Fastcgi_pass Unix:/var/run/php5-fpm.sock;
  9. Fastcgi_index index.php;
  10. Include Fastcgi_params;
  11. }
Copy code save modify exit and restart Nginx:
    1. sudo service nginx restart
Copy the code to create a new phpinfo.php:
    1. sudo nano/usr/share/nginx/www/phpinfo.php
Copy code input:
    1. <;? PHP phpinfo ();?>;
Copy code save exit, browser access ipaddress/phpinfo.php, can display PHP5-FPM configuration information correctly LNMP environment.


Recommended installation of phpMyAdmin;
    1. sudo apt-get install phpMyAdmin
    2. sudo ln-s/usr/share/phpmyadmin//usr/share/nginx/www
    3. sudo service Nginx reatsrt
During the copy code installation, you will be prompted for the MySQL password and set the root login password, the installation completes the Access Ip-address/phpmyadmin, in the local virtual machine, is the Http://127.0.0.1/phpmyadmin, manages the database,


Create a new virtual host (Add Web site): Copy/etc/nginx/sites-enable/default to/etc/nginx/conf.d/example.conf:
    1. sudo cp/etc/nginx/sites-enable/default/etc/nginx/conf.d/example.conf
Copy Code

Reference article:Debian 7 installs LNMP server using Dotdeb source


Third,install wordpress under Lnmp of course, you can use other blog programs, such as domestic typecho, but WordPress is easier to eat.  Download the latest version of WordPressor download the Chinese version of WordPress barchange the 3.8.1 to the newest designation, see Https://cn.wordpress.org/releases/#latest
    1. Wegt <a href= "http://cn.wordpress.org/wordpress-3.8.1-zh_CN.tar.gz" target= "_blank" >http://cn.wordpress.org /wordpress-3.8.1-zh_cn.tar.gz</a>
Copy Code decompression:
    1. TAR-ZXVF wordpress*.gz
Copy the code to move the extracted WordPress folder to a place you want to put, personal casual.


Create a database
Installed phpMyAdmin, at this time as long as the phpMyAdmin page to create a database called WordPress is good, other default. Otherwise, go to MySQL to create it. Go to MySQL:
    1. Mysql-u root-p
Copy the code to create a database named WordPress:
    1. Create DATABASE WordPress;
Copy the code later if you want to modify the contents of the WordPress database:
    1. Use WordPress;
Copy the code here involves the MySQL command statement, interested can study it, or put a phpmyadmin it.


Install WordPress For security reasons, modify the permissions of the Web root directory. I am used to directly extracted from the WordPress directory as a site directory.
    1. sudo chown www-data:www-data *-R
    2. sudo usermod-a-G www-data username
Copy Code Www-data is the default running user for NGIMX.
To create an nginx configuration file for WordPress:
    1. sudo nano/etc/nginx/conf.d/wordpress.conf
Copy the code and throw it in the following paragraph:
  1. server {
  2. Listen; #default_server;
  3. #listen [::]:80 default_server Ipv6only=on;
  4. Root here to write the site root directory;
  5. Index index.php index.html index.htm;
  6. # make site accessible from http://localhost/
  7. server_name 127.0.0.10; #换成自己的域名或者IP
  8. Location/{
  9. #try_files $uri $uri/= 404;
  10. Try_files $uri $uri//index.php?q= $uri & $args; #伪静态
  11. }
  12. Error_page 404/404.html;
  13. Error_page 502 503 504/50x.html;
  14. Location =/50x.html {
  15. root/usr/share/nginx/html;
  16. }
  17. Location ~ \.php$ {
  18. Fastcgi_split_path_info ^ (. +\.php) (/.+) $;
  19. Fastcgi_pass Unix:/var/run/php5-fpm.sock;
  20. Fastcgi_index index.php;
  21. Include Fastcgi_params;
  22. }
  23. }
Copying the code directly into the contents of the/etc/nginx/sites-available/default can also:
    1. sudo cp/etc/nginx/sites-available/default/etc/nginx/conf.d/wordpress.conf
Copy the code about WordPress pseudo-static rules, the above one, is the official WordPress, the Internet can also be found more than the more see:
    1. Location/{
    2. if (-f $request _filename/index.html) {
    3. Rewrite (. *) $1/index.html break;
    4. }
    5. if (-f $request _filename/index.php) {
    6. Rewrite (. *) $1/index.php;
    7. }
    8. if (!-f $request _filename) {
    9. Rewrite (. *)/index.php;
    10. }
    11. }
Copying the code is best to delete the/etc/nginx/sites-available/default and/etc/nginx/sites-enabled/default configuration files, otherwise it is prone to problems. Then restart Nginx:
    1. rm/etc/nginx/sites-available/default/*/etc/nginx/sites-enabled/defaul/*
Copy Code
    1. sudo service nginx restart
Copy Code

Enter the IP or domain name in the browser

Build WordPress blog from scratch under Linux

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.