LAMP–Linux(Mariadb)+Apache+Mysql+PHP环境是经常用到的组合,以下内容在Centos7.3虚拟机上进行配置,以做学习记录:
- 首先确认虚拟机操作系统的版本:
uname -a
&
cat /etc/redhat-release
-
yum -y update
#更新下系统和内核,如虚拟机有限制可略(更新成功后可以看到版本前后差别)ps:#
yum upgrade
大规模更新中使用,区别是连同旧的、淘汰的RPM包一同升级
- 安装Apache
yum install httpd httpd-devel
- 启动Apache服务,在Centos中要使用:
systemctl start httpd
or CentOS6.x
service httpd start|stop|status|restart
&
chkconfig httpd on
#将Apache加入开机启动 查看下Apache的状态:
systemctl status httpd
Active:(running)
- 打开浏览器,输入IP地址,查看是否安装成功,记着把Centos7的防火墙关了哦,查看防火墙状态:
systemctl status firewalld.service
&
systemctl stop firewalld.service
&
systemctl disable firewalld.service
#禁止防火墙开机启动
- 安装MYSQL :
yum install mariadb mariadb-devel mariadb-server
CentOS6.x:
yum install -y mysql-server mysql mysql-devel
在centos最新的内核中已经将mysql替代成了Mariadb
- 启动Mariadb服务:
systemctl start mariadb
CentOS6.x:
service mysqld start
chkconfig mysqld on
#根据向导初始化mysql的一些参数 :
mysql_secure_installation
- 输入当前数据库root密码,初始为空,直接回车,是否设置root密码:“Y”,是否删除匿名用户:“Y”后面的选项根据自己的需求选择
- 设置mysql允许远程登陆:
mysql -u root -p
& 设置root允许远程登陆,这样就可以通过mysql管理工具进行远程管理:
GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
- 安装PHP使其支持MariaDB:
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash php-fpm php
FOR CENTOS7.X & PHP7.0
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmyum install php71w-common mod_php71w php71w-opcache php71w-gd php71w-mysql php71w-mbstring php71w-pecl-redis php71w-pecl-memcached php71w-devel php71w-bcmath php71w-ldap
CentOS6.x:
yum install php php-fpm 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
- 启动php-fpm:
systemctl start php-fpm.service
CentOS6.x
service php-fpm start
重启Apache服务:
systemctl restart httpd
CentOS6.x:
service httpd restart
将php-fpm加入开机启动:
chkconfig php-fpm on
- 完成,新建一个PHP探针检测下,最好重启下服务器,确保Apache、php、mysql的服务都能够随机启动