在Ubuntu 14.04上部署 PHP 环境及 WordPress
软件及版本选择
Ubuntu 14.04
Ubuntu 是目前用户数量数一数二的发行版,背后有大土豪维护,可以说是轻量级用户的最佳选择。而 14.04 是目前最新的 LTS 版本,目前已经发布了半年了,基本是目前支持最好的版本。
Nginx
Nginx 是一个轻量级的,配置灵活,擅长并发的 Web 服务器。
PHP-FPM
PHP-FPM 是目前官方推荐的最佳的运行模式。
MariaDB
MySQL 的替代品,毕竟目前 MySQL 的创始人已经不建议我们使用 MySQL 了。
基本配置
通常当你创建了一台 VPS, 你会得到一个 IP 和一个 root 密码,所以,先用 ssh 登上你的服务器:
ssh root@106.186.21.33
# 如果有警告输入 yes 来确认,然后输入你的 root 密码
配置一下公钥登录,省着每次登录都要输入密码,非常建议像我一样把公钥上传到一个公开的地址,这样只要一条命令就可以设置好:
mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;
然后更新一下软件包列表,升级现有软件包:
apt-get updateapt-get upgrade
修改一下主机名,最好改成一个确实可以访问到这台服务器的域名:
vi /etc/hostnamevi /etc/hosts
安装软件包
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 服务器postfix: SMTP 服务器,用来支持从本地发送邮件php5-fpm: PHP 进程管理器,及 PHP 解释器mariadb-server: 类 MySQL 数据库memcached: 基于内存的缓存,很多程序会用到php-pear: PHP 的包管理器php5-mysql: PHP MySQL 数据库驱动php5-curl: 一个 HTTP 协议库php5-gd: 一个图像处理库php5-mcrypt: 一个加密算法库php5-memcache: Memcached 驱动python: 一个常用的脚本语言解释器make: 一个常用的构建工具screen: 一个常用的 Shell 会话管理工具git: 一个常用的版本控制工具wget, curl: 常用的文件下载工具zip, unzip: ZIP 压缩和解压工具iftop, iptraf, nethogs: 常用的流量监控工具vim: 一个常用的编辑器htop: 一个常用的进程监控工具
安装 WordPress
新建一个普通用户,并切换到该用户
adduser wordpresssu wordpresscd ~
下载 WordPress, 请自行到官网查看最新版本的下载地址:
wget http://cn.wordpress.org/wordpress-3.9-zh_CN.zip
解压文件:
unzip wordpress-*.zip
设置文件权限:
chmod -R 750 wordpress
删除安装包:
rm wordpress-*.zip
回到 root:
exit
配置 PHP-FPM
为 WordPress 创建一个进程池:
vi /etc/php5/fpm/pool.d/wordpress.conf
这是一份很典型的配置文件,通过监听 Unix Socket 来提供服务,动态调节进程数,最高 10 个进程,最低 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
配置 Nginx
删掉 Nginx 的默认站点:
rm /etc/nginx/sites-enabled/default
新建一个站点:
vi /etc/nginx/sites-enabled/wordpress
这份配置文件已将请求重写到 index.php, 可以直接在 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; }}
如果你希望把其他所有域名都跳转到你的站点,可以添加这么一段:
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; rewrite ^/(.*)$ http://jysperm.me permanent;}
然后我们需要修正 Nginx 和 PHP-FPM 配合的一个 Bug:
vi /etc/nginx/fastcgi_params
将 fastcgi_param SCRIPT_FILENAME 开头的行改为:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
为 Nginx 添加读取 WordPress 文件的权限:
usermod -G wordpress -a www-data
配置 MySQL
进入 MySQL 控制台:
mysql -p
# 需要输入你的 MySQL root 密码
# 创建数据库
CREATE DATABASE `wordpress`;
# 为 WordPress 新建用户
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'password';
# 授予权限
GRANT ALL PRIVILEGES ON `wordpress` . * TO 'wordpress'@'localhost';
# 退出
QUIT
重启
好了,已经配置完成了,我们直接重启服务器即可,这样所有服务都会重启并使用新的配置:
reboot

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
