您的位置 首页 php

ubuntu系统下玩转php服务器环境

ubuntu系统搭建服务器运行环境,新手围观。

一、php nginx mysql 安装

#更新升级

apt-get update

apt-get upgrade

#安装 nginx 并重启

apt-get install nginx

/etc/init.d/nginx restart

#check version(说明安装成功)

nginx -v

展示nginx版本

#安装php mysql 及php扩展

sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql php5-fpm

sudo apt-get install php5-gd php5-curl

sudo apt-get install spawn-fcgi

#自定义站点根目录(这里以/var/www/html为例)

cd /var

mkdir www

cd www

mkdir html

chmod -R 777 html

cd html

vi p.php

二.配置nginx

# 修改nginx的配置文件:/etc/nginx/sites-available/default

vi /etc/nginx/sites-available/default

server_name localhost;

#修改站点根目录路径 (这里以/var/www/html为例)

root /var/www/html

#修改index的一行,添加index.php

index index.php index.html index.htm;

#去掉下面部分的注释用于支持 php 脚本:

location ~ .php$ {

fast cgi _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;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

if ( $host !~* xinmaochuangtou.com ){

return 404;

}

#设置php-cgi开机自启动

#为了让php-cgi开机自启动:Ubuntu开机之后会执行/etc/ rc .local文件中的脚本

#所以我们可以直接在/etc/rc.local中添加启动脚本。

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data-f /usr/bin/php-cgi

添加到语句:

exit 0

前面才行(如下)

#重启nginx

/etc/init.d/nginx restart

#重启服务器命令

reboot

#nginx 语法检查

nginx -t

三、目录授权

#针对目录所需要的权限对目录进行授权操作

#举个栗子 对网站根目录下的data目录 以及themes目授予最高操作权限

cd /var/www/html

sudo chmod -R 777 data

sudo chmod -R 777 themes

四、账号设置

#ftp账号设置

sudo groupadd -g 600 groupftp

sudo useradd -u 700 ftptest -g 600(ftptest为ftp账户名可随意设置)

sudo usermod -d /var/www/

passwd 123456(123456为ftp密码)

# mysql 账号设置

#设置本地访问数据库账号及密码

GRANT ALL PRIVILEGES ON *.* TO 数据库@localhostIDENTIFIED BY “密码”;

#设置 远程访问 数据库账号及密码

GRANT ALL PRIVILEGES ON *.* TO 数据库@”%” IDENTIFIED BY “密码”;

#修改mysql配置文件

cd /etc/mysql/

vi my.cnf、

#bind-address = 127.0.0.1

(ps:新手速来围观,老司机勿喷,如有不当之处愿大家多多指正,在下不胜感激。现在的阿里云系统好像自带搭建服务器功能而且php跟mysql都是最新版,愿能给想深入探讨的小伙伴带来帮助!)

文章来源:智云一二三科技

文章标题:ubuntu系统下玩转php服务器环境

文章地址:https://www.zhihuclub.com/78078.shtml

关于作者: 智云科技

热门文章

网站地图