我爱编程PHP实战PHP经验分享

Lamp:centos+apache+mysql+php配置教程

2017-08-07  本文已影响0人  molangwu

前言

本教程是讲述的是从到部署php项目到阿里云服务器上面。


配置环境

Contos: 7
Xshell版本:Xshell 5


教程开始

购买服务器

安装apache

安装mysql

命令:  
yum install mysql mysql-server。//安装mysql
 yum install mariadb-server -y //MariaDB代替了mysql数据库所以要装  
 systemctl start mariadb.service //启动服务  
 systemctl enable mariadb.service //开机启动服务  
 mysql -u root -p //登录mysql 
 UPDATE user SET      Password=PASSWORD('newpassword') where USER='root'; //更新root密码
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';//最新版MySQL请采用SQL命令
FLUSH PRIVILEGES;//刷新权限 
quit;//退出mysql
systemctl restart mariadb.service//重启mysql
mysql -uroot -p//使用root用户重新登录mysql

安装PHP,和PHP组件

命令:
yum install php

yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt

到此我们的apache、mysql、php都安装完了。在此重启一次apache和mysql

命令:
systemctl restart httpd.service  
systemctl restart mariadb.service   

文件目录

错误及解决办法

解决办法
mysql -uroot -p//登录root数据库

//允许用户testuser从ip为222.129.1.1的主机连接到mysql服务器,并使用testpassword作为密码
 grant all privileges on *.* to 'testuser'@'指定ip' identified by '数据库密码' with grant option;    
(若是允许所有ip:GRANT ALL PRIVILEGES ON *.* TO ‘数据库用户名’@'%’ IDENTIFIED BY ‘数据库密码’ WITH GRANT OPTION;)  
 flush privileges;   //刷新权限缓存  
 show privileges;  
 show grants for  'testuser'@'222.129.1.1'   
解决办法
//加 777 权限
sudo chmod -R 777 目录;

附加命令

cd 返回根目录
cd .. 返回上级目录
cd /目录名 可以到该目录下
cp 文件1名 文件2名   把文件1复制成文件2
vim 命令:
vim 文件名 打开文件(不能修改)
i 按i进行编辑
esc + : + wq 保存退出
esc + : + q! 不保存退出

systemctl is-enabled iptables.servicesystemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态systemctl --failed #显示启动失败的服务
注:*代表某个服务的名字,如http的服务名为httpd
例如在[CentOS](http://www.linuxidc.com/topicnews.aspx?tid=14) 7 上安装http
[root@CentOS7 ~]# yum -y install httpd启动服务(等同于service httpd start)systemctl start httpd.service停止服务(等同于service httpd stop)
systemctl stop httpd.service重启服务(等同于service httpd restart)
systemctl restart httpd.service查看服务是否运行(等同于service httpd status)
systemctl status httpd.service开机自启动服务(等同于chkconfig httpd on)systemctl enable httpd.service开机时禁用服务(等同于chkconfig httpd on)
systemctl disable httpd.service查看服务是否开机启动 (等同于chkconfig --list)

参考链接

lamp:centos+apache+mysql+php安装配置方法

Centos7与Fedora24安装mysql后无法启动,提示 Unit mysql.service failed to load:No such file or directory

CentOS 7 上systemctl 的用法

上一篇 下一篇

猜你喜欢

热点阅读