Nginx,MySQL,PHP-FPM的安装和配置

2 篇文章 0 订阅

笔者通过几天的努力,找个各种资料,终于配置成功,不是说过程有多难,旨在找到一个简便的,易懂的可扩展的配置方法,虽然目前也不一定是最好的方案,但应该也算是很简单快速在linux配置nginx,mysql和php-fpm的配置方法了,Install and configure Nginx, MySQL & PHP-FPM in Debian Wheezy/Jessie这篇文章有部分参考,结构也与其类似,但安装方法不同,他那个还是比较复杂的,大家可以参考,主要分为如下过程:

  1. 配置sources.list更新apt
  2. 安装mysql
  3. 安装nginx
  4. 安装php-fpm

1. 配置和更新apt

默认情况下,无需修改sources.list文件,如果你安装过很多东西,把你的apt源弄乱了或安装了一些不兼容不能使用的软件,已经卸载,但源还在的话,你可以先删除/etc/apt/sources.list.d目录下的一些无用的源,然后修改你的/etc/apt/sources.list文件为默认源,可以 ubuntu源debian源里找到一些配置源,如我的debian的源为:
deb http://ftp.us.debian.org/debian stable main non-free
deb http://ftp.debian.org/debian/ wheezy-updates main non-free
deb http://security.debian.org/ wheezy/updates main non-free
配置好后,更新系统即可
apt-get update
apt-get upgrade
apt-get dist-upgrade

2. 安装MySQL数据库

使用apt安装mysql数据库,安装过程中需输入两次管理员密码
apt-get install mysql-server
安装成功后,可以用如下命令来测试:
mysql -u root -p
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql> create database wordpress default character set utf8 collate utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
这里,我的MySQL保持了默认的配置选项,如果以后须需要的话再进行修改吧。。

3. 安装和配置nginx

nginx 在ubuntu和debian下的安装也可以用apt来实现
apt-get install nginx
这里要说明一下,由于在测试过程中反复安装卸载了n次,有一次不小心删了/etc/nginx文件,卸载后安装配置文件没有再次出现,是同于没有卸载完造成的,应该卸载如下3个程序,然后再重新安装即可
apt-get remove nginx nginx-common nginx-full
配置nginx,首先修改/etc/nginx/nginx.conf,先备份一份配置文件,然后注释如下第一行
cp /etc/nginx/nginx.conf{,.orig}
# include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
在conf.d下添加caches.conf文件,用来对静态文件进行配置,并在其他文件中引用该配置,实际发布时,静态文件不再修改时,可将expires设置为max,开发时可设置为no-store
## caches
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
        access_log off;
        # expires max;
        add_header Cache-Control no-store;
}

location ~* \.(js)$ {
        access_log off;
        log_not_found off;
        # expires 7d;
        add_header Cache-Control no-store;
}

location ~* \.(woff|svg)$ {
        access_log off;
        log_not_found off;
        expires 30d;
}

location ~ /\.ht {
        deny all;
}
重新cp一份/etc/nginx/sites-available/default配置文件,在sites-enabled下创建连接,然后对其进行修改(example.cg为你的域名,当然也可以是其他随意值,但这样对应,容易辨识和分类,以后修改方便,如果你为了测试没有域名,可以修改host,做一个假的)
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/local.cg
sudo ln -s /etc/nginx/sites-available/local.cg /etc/nginx/sites-enabled/local.cg
最后,example.cg文件的内容如下,其中很多是默认的,修改了一些项,如网站根目录root,index中加入index.php,server_name改为你的域名,开启php,引入静态文件的配置项
server {
        #listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

        root /var/www/local.cg;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name local.cg;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #       root /usr/share/nginx/www;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "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;
        }

        ## caches
        include /etc/nginx/conf.d/caches.conf;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

安装php-fpm

使用apt安装php-fpm,并重启服务
apt-get install php5-fpm php5-cli php5-mysql
service nginx restart
service php5-fpm restart

附一个安装配置完成后,装上wordpress的图片

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值