Featured image of post Ubuntu 安裝 php

Ubuntu 安裝 php

  1. 安装 apt 源管理工具、添加 nginx 和 php 的安装源
1
2
3
apt-get install python-software-properties
add-apt-repository ppa:nginx/stable
add-apt-repository ppa:ondrej/php5
  1. 更新系统软件
1
apt-get update
  1. 安装 mysql
1
apt-get install mysql-server mysql-client
  1. 安装 php 及对 mysql 的支持
1
apt-get install php5-fpm php5-mysql
  1. 根据实际需要,选择性的安装 php 的各类功能模块
1
2
3
4
5
6
apt-get install php-pear php5-dev php5-curl
apt-get install php5-gd php5-intl php5-imagick
apt-get install php5-imap php5-mcrypt php5-memcache
apt-get install php5-ming php5-ps php5-pspell
apt-get install php5-recode php5-snmp php5-sqlite
apt-get install php5-tidy php5-xmlrpc php5-xsl
  1. 安装 nginx
1
apt-get install nginx
  1. 修改 nginx 默认站点配置文件
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
vim /etc/nginx/sites-available/default

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
Built with Hugo
主题 StackJimmy 设计