Ubuntu上搭建PHP+Mysql+Nginx环境
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-26 08:43:06 浏览: 评论:0
Ubuntu上搭建PHP+Mysql+Nginx环境(apt-get方式)
ubuntu版本:Ubuntu 10.04 LTS
1、首先使用apt-get下载Nginx,php,mysql,phpmyadmin,spawn-fcgi.
sudo apt-get install nginx php5-cgi php5-cli mysql-server-5.1 phpmyadmin spawn-fcgi,期间可能要输入mysql的密码,按照提示一步一步安装就是了.
OK后,你在Firefox中访问http://127.0.0.1/或者http://localhost/应该就能看见Nginx的欢迎界面了.
2、此时Nginx并不能跑PHP程序,需要修改一些配置文件.
$ cd /etc/nginx
$ sudo vim fastcgi_params,修改如下:
- fastcgi_ignore_client_abort on;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param QUERY_STRING $query_string;
- fastcgi_param REQUEST_METHOD $request_method;
- fastcgi_param CONTENT_TYPE $content_type;
- fastcgi_param CONTENT_LENGTH $content_length;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- fastcgi_param SCRIPT_NAME $fastcgi_script_name;
- fastcgi_param REQUEST_URI $request_uri;
- fastcgi_param DOCUMENT_URI $document_uri;
- fastcgi_param DOCUMENT_ROOT $document_root;
- fastcgi_param SERVER_PROTOCOL $server_protocol;
- fastcgi_param GATEWAY_INTERFACE CGI/1.1;
- fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
- //开源代码phpfensi.com
- fastcgi_param REMOTE_ADDR $remote_addr;
- fastcgi_param REMOTE_PORT $remote_port;
- fastcgi_param SERVER_ADDR $server_addr;
- fastcgi_param SERVER_PORT $server_port;
- fastcgi_param SERVER_NAME $server_name;
修改Nginx 配置文件nginx.conf
sudo vim nginx.conf,最后如下:
- user codebean codebean;#用户和用户组
- worker_processes 2;
- error_log /var/log/nginx/error.log;
- pid /var/run/nginx.pid;
- events {
- worker_connections 1024;
- # multi_accept on;
- }
- http {
- include /etc/nginx/mime.types;
- access_log /var/log/nginx/access.log;
- sendfile on;
- #tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- tcp_nodelay on;
- gzip on;
- gzip_disable "MSIE [1-6].(?!.*SV1)";
- include /etc/nginx/conf.d/*.conf;
- include /etc/nginx/sites-enabled/*;
- }
3、接下来我们来配置一个默认站点:
cd /etc/nginx/sites-available
sudo vim default
修改后如下:
- server {
- listen 80 default; #default表示是默认站点
- server_name localhost; #访问的名称
- root /var/www/nginx-default; #网站根目录
- access_log /var/log/nginx/localhost.access.log;
- location / {
- index index.php index.html index.htm;
- }
- location ~ .php$ {
- include fastcgi_params; #这个很重要
- }
- }
接下来你在目录/var/www/nginx-default新建一个index.php,输入:
phpinfo();然后重启nginx服务和开启fastcgi:
$ sudo /etc/init.d/nginx restart
$ /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 /usr/bin/php-cgi
再访问http://127.0.0.1/或者http://localhost/看看.
Tags: Ubuntu PHP+Mysql+Nginx环境
相关文章
- ·ubuntu下安装php5+pdo(2013-11-13)
- ·如何在Ubuntu 18.04和16.04上安装PHP(7.3,7.2和7.0)?(2020-02-05)
- ·如何通过PPA在Ubuntu上安装PHP7(2020-02-11)
- ·如何在Ubuntu上启用和禁用PHP模块(2020-02-15)
- ·在Ubuntu 14.04上部署 PHP 环境及 WordPress(2021-04-10)
- ·Ubuntu中搭建Nginx、PHP环境最简单的方法(2021-05-15)
- ·Ubuntu12下编译安装PHP5.3开发环境(2021-05-18)
- ·Ubuntu下安装PHP的mongodb扩展操作命令(2021-06-08)
- ·ubuntu下配置nginx+php+mysql详解(2021-06-17)
- ·老司机传授Ubuntu下Apache+PHP+MySQL环境搭建攻略(2021-07-18)
- ·Ubuntu彻底删除PHP7.0的方法(2021-10-20)
- ·Ubuntu中支持PHP5与PHP7双版本的简单实现(2021-10-25)
- ·在Ubuntu 18.04上安装PHP 7.3 7.2和7.0的方法(2021-11-16)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)