文档.txt
阿里云服务器买好后,用命令行搭建php+apach+mysql+nginx服务
1.安装Php7服务
sudo yum install php70u-fpm -y
启动Php
sudo systemctl start php-fpm
2.安装Nginx
sudo yum install nginx -y
启动Nginx
sudo systemctl start nginx
3.安装Mysql
sudo yum install mariadb101u-server -y
启动Mysql
sudo systemctl start mariadb
查看php版本
php -v
查看MySQL版本
mysql -V
mysql --version
查看Apache版本
httpd -v
apachectl -v
查看Nginx版本
nginx -v
远程控制服务器,并添加新用户
1.添加一个用户名: username
adduser username
2.给用户username设置密码
passwd username
3.然后设置密码
4.让用户username拥有root权限
gpasswd -a username wheel
配置nginx虚拟主机
1.先进入到 nginx 配置文件目录:
[root@ ~ ]# cd /etc/nginx/conf.d/
2.创建新的配置文件test.conf
[root@ ~ ]# touch test.conf
3.把下面的代码放入配置文件中
server {
listen 80;
server_name test.com;
root /home/www/test;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
4.重启 nginx 或者重新加载 nginx 可以让配置文件生效。
sudo systemctl reload nginx
或者
/usr/sbin/nginx -s reload
5.用浏览器打开虚拟主机配置的域名(test.com),看看是否能打开你指定的目录里的内容。
访问php页面,出现502 Bad Gateway nginx/1.12.2;解决方案:
可能没有安装PHP或PHP-FPM
yum install php php-fpm
启动php-fpm
systemctl start php-fpm
遇到的问题:
[root@localhost ~]# systemctl start mysql.service
Failed to start mysql.service: Unit mysql.service not found.
MariaDB代替了mysql数据库,MariaDB数据库管理系统是MySQL的一个分支,
因此用上述命令启动不起来,正确的方法如下
# yum install mariadb-server -y //如果已安装可以省略
# systemctl start mariadb.service //启动服务
# systemctl enable mariadb.service //开机启动服务
# mysql -u root -p //登录mysql
Httpd:
[root@ ~]# service httpd start
Redirecting to /bin/systemctl start httpd.service
[root@ ~]# /bin/systemctl start httpd.service
[root@ ~]# systemctl stop httpd //停止httpd服务
[root@ ~]# systemctl start httpd //开启httpd服务
[root@ ~]# systemctl resstart httpd //重启httpd服务