1.安裝MYSQL
apt-get install mysql-server
提示用戶名密碼
root
root
2.安裝nginx
apt-get install nginx
啟動
service nginx start
查看
http://127.0.0.1跳出Welcome to nginx!說明配置成功
3.安裝PHP5
apt-get install php5-fpm php5-mysql
4.配置nginx.conf
配置/etc/nginx/nginx.conf
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
vim /etc/nginx/nginx.conf
搜索文字worker_processes找到worker_processes auto;改為worker_processes 4;
搜索文字keepalive_timeout找到keepalive_timeout 65;改為keepalive_timeout 2;
5.配置Nginx讓其使用php-fpm進(jìn)程
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
vim /etc/nginx/sites-available/default
更改如下蕉汪,直接復(fù)制替換
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name server_domain_name_or_IP;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
重新加載nginx
service nginx reload
5.配置PHP涎才,修改php.ini文件
gedit /etc/php5/fpm/php.ini
設(shè)置驾霜,取消分號;將1改為0
cgi.fix_pathinfo=0:
重新加載 PHP-FPM:
service php5-fpm reload
6.測試運(yùn)行
創(chuàng)建探針文件info.php到/usr/share/nginx/html目錄下
gedit /usr/share/nginx/html/info.php
phpinfo();
?>
瀏覽器訪問探針文件http://127.0.0.1/info.php
如果出現(xiàn)PHP版本信息說明配置成功
7.測試mysql
創(chuàng)建測試文件sqltest.php到/usr/share/nginx/html目錄下
gedit /usr/share/nginx/html/sqltest.php
$link=mysql_connect("localhost","root","root");
if(!$link) echo "FAILD!";
else echo "OK!";
?>
訪問http://127.0.0.1/sqltest.php
如果出現(xiàn)OK字符說明mysql配置成功。
如果在加一個(gè)域名,/etc/hosts下面需要加個(gè)域名友驮,需要在/etc/nginx/sites-enable/下面添加個(gè)文件(erp文件名)如例:
server {
listen?????? 80;
server_name? erp.me;
charset utf-8;
root /home/clg/project/kingfisher/public;
index index.php index.html;
#access_log? /var/log/nginx/log/host.access.log? main;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
#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/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /home/clg/project/kingfisher/public/;
# fastcgi_pass?? 127.0.0.1:9000;
fastcgi_index? index.php;//注意這里要吧上面的9000注銷了嫂沉,在下面加上php5-fpm.sock這一行代碼
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
fastcgi_param? SCRIPT_FILENAME? $document_root$fastcgi_script_name;
include??????? fastcgi_params;
}
}