ECS服务器部署–centos7下安装apache+mysql+php7

购买了ECS,自己动手进行线上环境安装部署
一、安装Apache
1.查看httpd包是否可用
yum list | grep httpd
2.安装Apache
yum install httpd
3.配置servername
查找配置文件 find / -name httpd.conf
编辑配置文件 vim /etc/httpd/conf/httpd.conf
修改这行: ServerName localhost:80

4.启动
systemctl start httpd
附:
查看状态 systemctl status httpd
重启 systemctl restart httpd
停止 systemctl stop httpd
5.设置开机启动
chkconfig httpd on
二、安装MySQL
1.安装MySQL源
2.安装MySQL
yum install mysql-community-server
3.启动MySQL
systemctl start mysqld
4.获取密码
grep ‘temporary password’ /var/log/mysqld.log
localhost:后面就是密码 A temporary password is generated for root@localhost:password
5.进入MySQL
mysql -uroot -p
6.修改密码
ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘custome_password’
7.开放远程访问权限
查看数据库 show databases;
使用名为mysql的数据库 use mysql;
update user set host = ‘%’ where user = ‘root’; #百分号相当于*号,意为全部放行,也可改为IP地址
8.MySQL权限管理
create user ‘myuser’@’%’ IDENTIFIED BY ‘*********’;
创建一个用户为myuser,因为用的%所以任何IP都可以登录,但登录后却无法看到数据库,新增用户所有权限默认关闭。
grant all on *.* to myuser; #设置该用户所有数据库所有表拥有所有权限
grant select on A_database.* to myuser; #设置该用户只有A数据库里的所有表的select操作。
grant insert on A_database.user to myuser; #设置该用户只有A数据库里的user表的insert操作
使修改即时生效 flush privileges
撤销权限
revoke insert on A数据库.user from myuser;
撤销后查看各权限是否由Y变为N show grants for myuser;
三、PHP7安装
1、下载包
2、解压
tar -zxvf php-7.2.9.tar.gz
3、进入解压包安装一些必要的依赖
cd php-7.2.9
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel
4、安装gcc
yum install gcc
5、安装其他包
yum -y install libxslt-devel*
yum -y install perl*
yum -y install httpd-devel
find / -name apxs 得到的路径是:/usr/bin/apxs
于是得到–with-apsx2的路径是/usr/bin/apxs
5.配置
./configure –prefix=/usr/local/php7 –with-curl –with-freetype-dir –with-gd –with-gettext –with-iconv-dir –with-kerberos –with-libdir=lib64 –with-libxml-dir –with-mysqli –with-openssl –with-pcre-regex –with-pdo-mysql –with-pdo-sqlite –with-pear –with-png-dir –with-xmlrpc –with-xsl –with-zlib –enable-fpm –enable-bcmath -enable-inline-optimization –enable-gd-native-ttf –enable-mbregex –enable-mbstring –enable-opcache –enable-pcntl –enable-shmop –enable-soap –enable-sockets –enable-sysvsem –enable-xml –enable-zip –enable-pcntl –with-curl –with-fpm-user=nginx –enable-ftp –enable-session –enable-xml –with-apxs2=/usr/bin/apxs
6.编译安装
make & make install
7、查看安装的版本
php -v
8、修改Apache配置:
vim /etc/httpd/conf/httpd.conf
DocumentRoot “/var/www/html”
找到
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在后面添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php7
搜索<IfModule dir_module>下面这一块添加上index.php
<IfModule dir_module>
 DirectoryIndex index.html index.php
</IfModule>
搜索有没有下面这一行:
LoadModule php7_module modules/libphp7.so
如果没有 请手动添加 否则 会出现运行php文件变成下载
在末尾增加配置域名
<VirtualHost *:80>
 DocumentRoot /var/www/html
 ServerName www.***.com #你的域名
 ServerAlias ***.com
</VirtualHost>
保存后重启Apache.

发表评论