Deploy the PHP environment and WordPress on Ubuntu14.04

Source: Internet
Author: User
Tags image processing library mcrypt install wordpress
Ubuntu is really fun. Like command line, simple interface, different from Window. Changing the environment occasionally and learning the way of thinking in Linux is a good practice. I have also tried Ubuntu before, and want to learn some development in Linux (mainly dealing with code software and version selection ).

Ubuntu 14.04

Ubuntu is one of the most popular versions of Ubuntu. it is well maintained and can be said to be the best choice for lightweight users. 14.04 is the latest LTS version and has been released for six months. it is basically the best version currently supported.

Nginx

Nginx is a lightweight, flexible configuration, and good at concurrent Web servers.

PHP-FPM

PHP-FPM is currently the best run mode officially recommended.

MariaDB

After all, the founder of MySQL does not recommend that we use MySQL.

Basic configuration

Generally, when you create a VPS, you will get an IP address and a root password. Therefore, first use ssh to log on to your server:

ssh root@106.186.21.33

# If there is a warning, enter yes to confirm, and then enter your root password
Configure the public key to log on, saving the need to enter a password every time you log on. we recommend that you upload the public key to a public address just like me, so that you can set it with one command:

mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;

Update the software package list to upgrade the existing software package:

apt-get updateapt-get upgrade

Change the host name to a domain name that can access this server:

vi /etc/hostnamevi /etc/hosts

Install software package

Apt-get install nginx postfix php5-fpm mariadb-server memcachedapt-get install php-pear php5-mysql php5-curl php5-gd php5-mcrypt php5-memcacheapt-get install python make screen git wget zip unzip iftop vim curl htop iptraf nethogsnginx: web server postfix: SMTP server, used to support sending mail from local php5-fpm: PHP process manager, and PHP interpreter mariadb-server: class MySQL database memcached: memory-based cache, many programs will use php-pear: PHP package manager php5-mysql: PHP MySQL database driver php5-curl: an HTTP protocol library php5-gd: an image processing library php5-mcrypt: an encryption algorithm library php5-memcache: memcached driver python: a common script language interpreter make: a common build tool screen: a common Shell session management tool git: a common version control tool wget, curl: common file download tools: zip, unzip: ZIP compression and decompression tools iftop, iptraf, nethogs: common traffic monitoring tools vim: a common editor htop: a common process monitoring tool

Install WordPress

Create a common user and switch

adduser wordpresssu wordpresscd ~

To download WordPress, go to the official website to view the latest version:

wget http://cn.wordpress.org/wordpress-3.9-zh_CN.zip

Decompress the file:

unzip wordpress-*.zip


Set file permissions:

chmod -R 750 wordpress


Delete the installation package:

rm wordpress-*.zip


Return to root:

exit


Configure PHP-FPM

Create a process pool for WordPress:

vi /etc/php5/fpm/pool.d/wordpress.conf


This is a typical configuration file that provides services by listening to Unix sockets and dynamically adjusts the number of processes. The maximum number of processes is 10, and the minimum number of processes is 3:

[wordpress]user = wordpressgroup = wordpresslisten = /home/wordpress/phpfpm.socklisten.owner = wordpresslisten.group = wordpresslisten.mode = 0660pm = dynamicpm.max_children = 10pm.min_spare_servers = 3pm.max_spare_servers = 5slowlog = /home/wordpress/phpfpm.slowlogrequest_slowlog_timeout = 5srequest_terminate_timeout = 15sphp_admin_value[error_log] = /home/wordpress/phpfpm_error.logphp_admin_flag[log_errors] = On

Configure Nginx

Delete the default Nginx site:

rm /etc/nginx/sites-enabled/default


Create a site:

vi /etc/nginx/sites-enabled/wordpress

This configuration file has rewritten the request to index. php. you can directly use the "Fixed Link" function in WordPress:

server {  listen 80;  server_name jysperm.me;  root /home/wordpress/wordpress;  index index.html index.php;  autoindex off;  location / {    try_files $uri $uri/ /index.php;  }   location ~ \.php$ {     fastcgi_pass unix:///home/wordpress/phpfpm.sock;    include fastcgi_params;    fastcgi_index index.php;  }}

If you want to redirect all other domain names to your site, you can add the following section:

server {  listen 80 default_server;  listen [::]:80 default_server ipv6only=on;  rewrite ^/(.*)$ http://jysperm.me permanent;}


Then we need to fix a Bug that works with Nginx and PHP-FPM:

vi /etc/nginx/fastcgi_params


Change the line starting with fastcgi_param SCRIPT_FILENAME:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


Add the following permissions to read WordPress files for Nginx:

usermod -G wordpress -a www-data


Configure MySQL

Log on to the MySQL console:

mysql -p


# Enter your MySQL root password

# Creating a database

CREATE DATABASE `wordpress`;

# Create a user for WordPress

CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'password';

# Granting permissions

GRANT ALL PRIVILEGES ON `wordpress` . * TO 'wordpress'@'localhost';

# Exit
QUIT
Restart

Now that the configuration is complete, restart the server directly, so that all services will be restarted and the new configuration will be used:

Reboot

Related Article

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.