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
- passwd
Copy Code
Add New User
Working with Root all the the while I think it's a pretty dangerous thing ...
- AddUser username
Copy Code
Username change to your own.
New user added to Sudo
is to add root permissions to the user.
- Nano/etc/sudoers
Copy Code
Locate the user privilege specification, and insert a row below
- 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:
- Apt-get Update
- Apt-get Upgrade
- 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
- Nano/etc/ssh/sshd_config
Copy Code
Find the port 22 line, such as 2222
- Port 2222
Copy Code
Disable remote connection of root account:
- Permitrootlogin No
Copy Code
Use SSH Protocol 2 only:
- Protocol 2
Copy Code
To add new user SSH access rights:
- Allowusers username #多用户空格隔开, denyusers is forbidden to access users
Copy Code
Speed up SSH login disable Usedns
- Usedns No
Copy Code
Save exit and restart SSH
- 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:
- 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
- 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.
- sudo apt-get install Nginx
Copy Code
Install PHP:
- sudo apt-get install php5-fpm php5-mysql
Copy the code so that all installations are complete
Start Nginx:
- 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:
- sudo killall apache2
Copy code to turn off Apache boot:
- 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:
- include/etc/nginx/conf.d/*.conf;
- 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:
- sudo nano/etc/nginx/sites-enable/default
Copy the code to locate the server module and press modify:
- root/usr/share/nginx/www; #网站根目录
- Index index.php index.html index.htm;
- server_name your_ip_address;
Copy the code down to location ~. php$, remove some comments
- Location ~. php$ {
- Fastcgi_split_path_info ^ (. +.php) (/.+) $;
- # # Note:you should has "cgi.fix_pathinfo = 0;" In php.ini
- #
- # # with php5-cgi alone:
- # Fastcgi_pass 127.0.0.1:9000;
- # with PHP5-FPM:
- Fastcgi_pass Unix:/var/run/php5-fpm.sock;
- Fastcgi_index index.php;
- Include Fastcgi_params;
- }
Copy code save modify exit and restart Nginx:
- sudo service nginx restart
Copy the code to create a new phpinfo.php:
- sudo nano/usr/share/nginx/www/phpinfo.php
Copy code input:
- <;? PHP phpinfo ();?>;
Copy code save exit, browser access ipaddress/phpinfo.php, can display PHP5-FPM configuration information correctly LNMP environment.
Recommended installation of phpMyAdmin;
- sudo apt-get install phpMyAdmin
- sudo ln-s/usr/share/phpmyadmin//usr/share/nginx/www
- 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:
- 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
- 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:
- 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:
- Mysql-u root-p
Copy the code to create a database named WordPress:
- Create DATABASE WordPress;
Copy the code later if you want to modify the contents of the WordPress database:
- 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.
- sudo chown www-data:www-data *-R
- 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:
- sudo nano/etc/nginx/conf.d/wordpress.conf
Copy the code and throw it in the following paragraph:
- server {
- Listen; #default_server;
- #listen [::]:80 default_server Ipv6only=on;
- Root here to write the site root directory;
- Index index.php index.html index.htm;
- # make site accessible from http://localhost/
- server_name 127.0.0.10; #换成自己的域名或者IP
- Location/{
- #try_files $uri $uri/= 404;
- Try_files $uri $uri//index.php?q= $uri & $args; #伪静态
- }
- Error_page 404/404.html;
- Error_page 502 503 504/50x.html;
- Location =/50x.html {
- root/usr/share/nginx/html;
- }
- Location ~ \.php$ {
- Fastcgi_split_path_info ^ (. +\.php) (/.+) $;
- Fastcgi_pass Unix:/var/run/php5-fpm.sock;
- Fastcgi_index index.php;
- Include Fastcgi_params;
- }
- }
Copying the code directly into the contents of the/etc/nginx/sites-available/default can also:
- 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:
- Location/{
- if (-f $request _filename/index.html) {
- Rewrite (. *) $1/index.html break;
- }
- if (-f $request _filename/index.php) {
- Rewrite (. *) $1/index.php;
- }
- if (!-f $request _filename) {
- Rewrite (. *)/index.php;
- }
- }
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:
- rm/etc/nginx/sites-available/default/*/etc/nginx/sites-enabled/defaul/*
Copy Code
- sudo service nginx restart
Copy Code
Enter the IP or domain name in the browser
Build WordPress blog from scratch under Linux