Nginx + PHP-FPM + MySQL + phpMyAdmin on Ubuntu (aliyun)

今天抽空在阿里云上部署安装了PHP的环境

主要有nginx, php5 php-fpm mysql phpmyadmin

本文来源于:http://www.lonelycoder.be/nginx-php-fpm-mysql-phpmyadmin-on-ubuntu-12-04/

Since 3 years I’m completely into Nginx. For some reason I was always struggling with Apache, and
that kept me from running my own server. But then a colleague told me about
Nginx, and how great it was. So I looked into it, and the things I read were
great. Compared to Apache, Nginx is smaller in size, it multiplies the
performance remarkably by recducing the RAM and CPU usage for real time
applications and it’s very flexible. Of course Apache will also have its
advantages, but the fact I can’t come up with one says enough (about me, or
Apache ;-)).

So today I’m going to show you how to setup Nginx with PHP 5 and MySQL on
Ubuntu 12.04. It’s really not that difficult. Let’s start with Nginx.





1

sudo apt-get install
nginx -y

That’s it. But now we want to configure Nginx. I normally use Sublime Text 2 as a
text editor, because VI hates me (or I hate VI, really hard to tell). But on a
remote server sublime is not really an option, so I will just use nano. Feel
free to use the editor you prefer.

You can download the config here.






1

2

3

cd /etc/nginx

sudo cp nginx.conf nginx.conf.backup

sudo nano nginx.conf





01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

user www-data;

# As a thumb rule: One per CPU. If you are serving a large amount

# of static files, which requires blocking disk reads, you may want

# to increase this from the number of cpu_cores available on your

# system.

#

# The maximum number of connections for Nginx is calculated by:

# max_clients = worker_processes * worker_connections

worker_processes 1;

# Maximum file descriptors that can be opened per process

# This should be > worker_connections

worker_rlimit_nofile 8192;

events {

    # When you need > 8000 * cpu_cores connections, you start optimizing

    # your OS, and this is probably the point at where you hire people

    # who are smarter than you, this is *a lot* of requests.

    worker_connections 8000;

}

error_log /var/log/nginx/error.log;

pid /var/run/nginx.pid;

http {

    charset utf-8;

    # Set the mime-types via the mime.types external file

    include mime.types;

    # And the fallback mime-type

    default_type application/octet-stream;

    # Click tracking!

    access_log /var/log/nginx/access.log;

    # Hide nginx version

    server_tokens off;

    # ~2 seconds is often enough for HTML/CSS, but connections in

    # Nginx are cheap, so generally it‘s safe to increase it

    keepalive_timeout 20;

    # You usually want to serve static files with Nginx

    sendfile on;

    tcp_nopush on; # off may be better for Comet/long-poll stuff

    tcp_nodelay off; # on may be better for Comet/long-poll stuff

    server_name_in_redirect off;

    types_hash_max_size 2048;

    gzip
on;

    gzip_http_version 1.0;

    gzip_comp_level 5;

    gzip_min_length 512;

    gzip_buffers 4 8k;

    gzip_proxied any;

    gzip_types

        # text/html is always compressed by HttpGzipModule

        text/css

        text/plain

        text/x-component

        application/javascript

        application/json

        application/xml

        application/xhtml+xml

        application/x-font-ttf

        application/x-font-opentype

        application/vnd.ms-fontobject

        image/svg+xml

        image/x-icon;

    # This should be turned on if you are going to have pre-compressed copies (.gz) of

    # static files available. If not it should be left off as it will cause extra I/O

    # for the check. It would be better to enable this in a location {} block for

    # a specific directory:

    # gzip_static on;

    gzip_disable "msie6";

    gzip_vary on;

    include /etc/nginx/conf.d/*.conf;

    include /etc/nginx/sites-enabled/*;

}

Change the default site config. You can download the config here.





1

2

sudo cp sites-available/default
sites-available/default.backup

sudo nano sites-available/default





01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

server {

    listen 80 default; ## listen for ipv4; this line is default and implied

    listen [::]:80 default ipv6only=on; ## listen for ipv6

    # Make site accessible from http://localhost/ or server IP-address

    server_name localhost;

    server_name_in_redirect off;

    charset utf-8;

    access_log /usr/share/nginx/access.log;

    error_log /usr/share/nginx/error.log;

    root /usr/share/nginx/www;

    index index.php index.html index.htm;

    location / {

        # First attempt to serve request as file, then

        # as directory, then trigger 404

        try_files $uri $uri/ =404;

    }

}

Now we need to reload Nginx.






1

sudo service nginx reload

Try http://localhost/ (or http://your-server-ip-address)
and hopefully you will see the welcome page of Nginx. Nice! Next, MySQL. Just
follow the on screen instructions.





1

sudo apt-get install
mysql-server mysql-client -y

To have a secure installation, we execute the following command:






1

sudo mysql_secure_installation

Follow the instructions. Start by entering your MySQL root password. If you
did not set one yet, do it! It’s just that easy. So we can continue with
PHP.





1

sudo apt-get install
php5-fpm php5-cli php5-mysql -y

If you don’t want to run PHP from console, you can skip php5-cli. If you are
planning to use the Symfony2 framework I would suggest you keep it, you will
need it. By default fpm and cli use their own php.ini configuration file. I
usualy want them to use the same one. If you want that too, do the
following:





1

2

3

cd /etc/php5/cli

sudo mv php.ini php.ini.backup

sudo ln -s ../fpm/php.ini

Once php-fpm is installed, we need to configure Nginx again.






1

2

cd /etc/nginx

sudo nano nginx.conf

Add the following to the http {} part.





1

2

3

4

# Upstream to abstract back-end connection(s) for PHP

upstream php {

    server unix:/tmp/php5-fpm.sock;

}

Prepare the default site so it can serve PHP pages (needs to be in the server
{} part).





1

sudo nano /etc/nginx/sites-available/default





01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

# pass the PHP scripts to FPM socket

location ~ \.php$ {

    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    

    fastcgi_pass php;

    fastcgi_index index.php;

    fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www$fastcgi_script_name;

    fastcgi_param DOCUMENT_ROOT /usr/share/nginx/www;

    # send bad requests to 404

    fastcgi_intercept_errors on;

    include fastcgi_params;

}

Open /etc/php5/fpm/pool.d/www.conf and look for the following line ..






1

2

cd /etc/php5/fpm/pool.d

sudo nano www.conf





1

listen = 127.0.0.1:9000

.. and change it into ..





1

listen = /tmp/php5-fpm.sock

Save and restart both Nginx and PHP-FPM.






1

2

sudo service nginx restart

sudo service php5-fpm restart

Create a PHP file in your web root.





1

nano /usr/share/nginx/www/index.php





1

2

3

4

5

<?php

phpinfo();

?>

Save the file and refresh http://localhost/ (or http://your-server-ip-address).
If everything goes well you have a nice page with your PHP configuration
explained, if not you can replace “/tmp/php5-fpm.sock” by
“/var/run/php5-fpm.sock” in both /etc/nginx/nginx.conf and
/etc/php5/fpm/pool.d/www.conf and reload nginx and php5-fpm (possible solution
by Flávio Moringa, thnx Flávio!).

The final thing to do is install phpMyAdmin.






1

sudo apt-get install
phpmyadmin -y

Go to your web root and link phpMyAdmin.





1

2

cd /usr/share/nginx/www

sudo ln -s /usr/share/phpmyadmin

Now you should be able to go to http://localhost/phpmyadmin (or
http://your-server-ip-address/phpmyadmin). In a production environment I try not
to use phpMyAdmin, and if I really need it I use another alias. For
example poiul. It makes it harder for others to find it.

时间: 2024-07-29 09:34:07

Nginx + PHP-FPM + MySQL + phpMyAdmin on Ubuntu (aliyun)的相关文章

记录一次自己对nginx+fastcgi(fpm)+mysql压力测试结果

nginx + fastcgi(fpm) 压力测试: CentOS release 5.9 16核12G内存 静态页面: 并发1000,压测200秒,测试结果: 系统最大负载5.47 成功响应: 2563065, 502:0, 失败:0 PHP页面(对mysql进行一次带索引的查询,数据库记录500条): 并发1000,压测200秒,测试结果: 系统最大负载15.66 成功响应: 114368, 502:712, 失败:58715 并发200,压测200秒,测试结果: 系统最大负载25.81 成

LNMP搭建(CentOS 6.3+Nginx 1.2.0+PHP 5.3.15(fpm)+ MySQL 5.5.35)

Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过三年了.Igor 将源代码以类BSD许可证的形式发布. 系统环境: # cat /etc/redhat-release CentOS release 6.3 (Final) 1.安装所需的第三方库 yum -y install gcc

ubuntu-12.04.2-desktop-amd64 安装整合 nginx + php + mysql + phpmyadmin + tomcat

最近需要做jsp项目,部署在ubuntu 下,周末抽时间配置了nginx + php + mysql + phpmyadmin + tomcat 环境,从windows 的C# 转过来, 多少有些不适应, 估计要走全栈的方向了. 顺便整理了一下入门的配置方法, 完全在控制台下完成. 1.1  Common Start Terminal Ctrl+Alt+T 使用root用户 sudo –sH 查看进程 linux命令ps aux|grep xxx 软连接 ln -s 源地址  目的地址 比如把l

Memcache缓存服务器(Nginx+php+Memcache+MySQL)

一.MemCache简介: MemCache是一个自由.源码开放.高性能.分布式的分布式内存对象缓存系统,用于动态Web应用以减轻数据库的负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高了网站访问的速度.MemCaChe是一个存储键值对的HashMap,在内存中对任意的数据(比如字符串.对象等)所使用的key-value存储,数据可以来自数据库调用.API调用,或者页面渲染的结果.MemCache设计理念就是小而强大,它简单的设计促进了快速部署.易于开发并解决面对大规模的数据缓

[Ubuntu] Autostart nginx, php-fpm and mysql in Ubuntu14.04

[nginx] Step 1 Download the shell script wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx Step 2 chmod +x /etc/init.d/nginx Step 3 modify the code marked with red color to your configure PATH=/usr/local/sb

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

之前在Ubuntu12.04上搭建过PHP开发环境,按照这里http://budongzhenren.blog.51cto.com/2288320/991365安装的.但是系统换成14.04后,再用这个方法安装一直不成功,让我很郁闷,折腾了好久,后来才发现在12.04上安装Nginx,默认的网站根目录在 /usr/share/nginx/www,而在14.04上,默认的网站根目录是 /usr/share/nginx/html. 在Ubuntu14.04上搭建PHP环境的步骤参考这里:http:/

Http服务器基本配置[Windows + Nginx + MySQL + phpMyAdmin]

闻说Nginx向来有性能高.并发性强.占用内存少的优势,更有“反向代理”和“负载均衡”的特点.而使用Nginx+PHP作开发环境,性能更是比Apache+PHP高数倍.本文以各程序当前最新的版本为例,介绍在Windows(x64)下搭建Nginx+PHP+MySQL+phpMyAdmin经典开发环境的方法. 1. 应用软件包以初始路径设置 Nginx(当前最新1.7.9):http://nginx.org/download/:5 PHP(当前最新5.6.6RC1):http://windows.

Linux下Nginx+PHP+Mysql环境搭建过程(图文)

一.使用yum命令,安装所需的程序库        1.命令内容                yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses

Nginx学习笔记——搭建Linux +Nginx+PHP+Mariadb(MySql)开发环境

1.安装Nginx 源安装 本人安装环境是Deepin(Ubuntu的衍生版),所以最简单的方法就是执行 sudo apt-get install nginx 或者CentOS下: yum install nginx 编译安装 http://nginx.org/ 下载最新版1.9.5,支持HTTP/2模块,号称更快更安全,并且可以向下兼容,具体细节查看NGINX_HTTP2_White_Paper_v4.pdf 依赖关系:openssl-1.0.0s,pcre-8.36,zlib-1.2.8 分