Ubuntu Server 11 安装 Nginx+PHP5.3+MySQL

发布于: 2 February, 2014
分享:

通过 apt-get 安装 Nginx

更新 Ubuntu 上面的 apt 源 sudo nano /etc/apt/sources.list 添加:deb http://nginx.org/packages/ubuntu/ lucid nginx 添加:deb-src http://nginx.org/packages/ubuntu/ lucid nginx sudo wget http://nginx.org/keys/nginx_signing.key sudo apt-key add nginx_signing.key sudo aptitude update 执行一下 apt-get update  更新一下tree  

Step 1.1 - 安装 Nginx

sudo apt-get install nginx 通过 apt-get 安装成功之后,默认网站目录为 /usr/share/nginx/www 默认 Nginx 配置文件路径为 /etc/nginx/nginx.conf sudo nginx -v //@查看当前Nginx版本  

Step 2 -安装 PHP 及附属模块

sudo apt-get install php5-common php5-cli php5-cgi php5-fpm php5-mcrypt php5-mysql php5-gd php5-memcache php5-xcache  

Step 2.1 - 手动编译PHP (apt-get  安装可跳过)

sudo apt-get install autoconf2.13 libssl-dev libcurl4-gnutls-dev libjpeg62-dev libpng12-dev libmcrypt-dev libmysql++-dev libfreetype6-dev libt1-dev libc-client-dev libbz2-dev mysql-client libevent-dev libxml2-dev ./configure --enable-fpm --enable-soap --with-mcrypt --enable-mbstring --with-openssl --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --with-pdo-mysql --with-libxml-dir=/usr/lib --with-mysqli=/usr/bin/mysql_config --with-curl --enable-zip --with-bz2 --with-imap=shared --with-imap-ssl --enable-sockets --with-zlib --enable-exif --enable-ftp --with-iconv --with-gettext --enable-gd-native-ttf --with-t1lib=/usr --with-freetype-dir=/usr --with-kerberos --prefix=/usr/local/php --with-fpm-user=www --with-fpm-group=www sudo make && make install  

Step 3 - 安装 MySQL Server 5.5

apt-get install mysql-server mysql-client  

Step 4 - 配置 Nginx 虚拟主机

创建网站目录 mkdir -p /var/www location / { root /var/www; index index.html index.htm index.php; } location ~ \.php$ { root /var/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; set $real_script_name $fastcgi_script_name; set $path_info ""; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)") { set $real_script_name $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; include /etc/nginx/fastcgi_params; #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_intercept_errors on; #fastcgi_ignore_client_abort off; #fastcgi_connect_timeout 36000; #fastcgi_send_timeout 36000; #fastcgi_read_timeout 36000; #fastcgi_buffer_size 128k; #fastcgi_buffers 4 256k; #fastcgi_busy_buffers_size 256k; #fastcgi_temp_file_write_size 256k; }   Step 5 - 配置 1. 配置 php-fpm sudo cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 修改php-fpm.conf, 默认的配置路径前缀为 /usr/local/php/var [global] pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = notice [www] listen = 127.0.0.1:9000 user = www group = www pm = dynamic //@pm=process manager pm.max_children = 2000 //@This value sets the limit on the number of simultaneous requests that will be served. pm.start_servers = 20 //@The number of child processes created on startup pm.min_spare_servers = 5 //@The desired minimum number of idle server processes. pm.max_spare_servers = 35 //@The desired maximum number of idle server processes.   配置开机启动 php-fpm cp /usr/local/src/php-5.4.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //@php-5.4.0 需替换为当前使用的php版本 sudo chmod 755 /etc/init.d/php-fpm //@修改权限 update-rc.d php-fpm defaults sudo /usr/local/php/sbin/php-fpm //@启动php-fpm   2. 配置 Nginx 虚拟主机 sudo nano /etc/nginx/nginx.conf //@可修改 www 用户名称 sudo nano /etc/nginx/sites-available server { location / { root /usr/share/nginx/www; index index.html index.htm index.php; } location ~ \.php$ { root /usr/share/nginx/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi_params; } }

修改 php.ini

首先拷贝 sudo cp /usr/local/src/php-5.3.10/php.ini-production /usr/local/php/lib/php.ini sudo nano /usr/local/php/lib/php.ini 重启php-fpm使php.ini生效 sudo /etc/init.d/php-fpm restart

3. php-fpm管理

kill -SIGINT `cat /usr/local/php/var/run/php-fpm.pid` //终止 /usr/local/php5/sbin/php-fpm //启动 kill -SIGUSR2 `cat /usr/local/php/var/run/php-fpm.pid` //重启 kill -SIGUSR1 `cat /usr/local/php/var/run/php-fpm.pid` //日志

4. Nginx管理

/usr/sbin/nginx -V //@查看编译配置选项 /usr/sbin/nginx //@启动 /usr/sbin/nginx -s reload //@平滑重启 /usr/sbin/nginx -t  //@测试

分享:

0 留言

留言

您的留言将被人工审核,请勿发表色情、反动言论。