Nginx,MySQL,PHP-FPM的安装和配置
来源:互联网 发布:帝国时代2 mac版 编辑:程序博客网 时间:2024/04/29 20:07
笔者通过几天的努力,找个各种资料,终于配置成功,不是说过程有多难,旨在找到一个简便的,易懂的可扩展的配置方法,虽然目前也不一定是最好的方案,但应该也算是很简单快速在linux配置nginx,mysql和php-fpm的配置方法了,Install and configure Nginx, MySQL & PHP-FPM in Debian Wheezy/Jessie这篇文章有部分参考,结构也与其类似,但安装方法不同,他那个还是比较复杂的,大家可以参考,主要分为如下过程:
- 配置sources.list更新apt
- 安装mysql
- 安装nginx
- 安装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-freedeb http://ftp.debian.org/debian/ wheezy-updates main non-freedeb http://security.debian.org/ wheezy/updates main non-free配置好后,更新系统即可
apt-get updateapt-get upgradeapt-get dist-upgrade
2. 安装MySQL数据库
使用apt安装mysql数据库,安装过程中需输入两次管理员密码
apt-get install mysql-server安装成功后,可以用如下命令来测试:
mysql -u root -pmysql> 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
## cacheslocation ~* \.(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.cgsudo 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-mysqlservice nginx restartservice php5-fpm restart
附一个安装配置完成后,装上wordpress的图片
0 0
- Nginx,MySQL,PHP-FPM的安装和配置
- Mac 下 Nginx、MySQL、PHP-FPM 的安装配置
- Mac 下 Nginx、MySQL、PHP-FPM 的安装配置
- nginx+php-fpm在Linux下的安装和配置
- 配置nginx、mysql、php-fpm的方法
- nginx,php-fpm的安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- nginx php-fpm安装配置
- 深入模板编程笔记二
- CSS实现平铺滚动效果
- 第十一周项目一 函数版星号图1
- 第十一周项目3 (1)求n!
- STL 容器
- Nginx,MySQL,PHP-FPM的安装和配置
- 每天学一点设计模式-工厂方法模式
- UVA - 562 Dividing coins (01背包)
- 第11周项目三程序的多文件组织
- C++ Builde 2010 MDI 调用 DLL 子窗体
- 第12周项目3-用递归法求解(1)
- 能够识别图片文字的软件有吗
- 使用php实现openfire的用户数据注册
- 探索Fragment(2)---数据交互