mwjhw216 发表于 2017-12-25 14:28:37

Centos7 用yum命令安装LAMP环境(php+Apache+Mysql)以及php扩展

  1、yum -y update    // 更新系统
  yum -y install gcc g++ gcc-c++
  2、安装mysql
  2.1)yum -y install mariadb-client mariadb-server mariadb-devel
  2.2)启动:systemctl start mariadb.service
  2.3)设置开机自启:systemctl enable mariadb
  2.4)设置root密码:
  ① systemctl stop mariadb.service
  ② mysqld_safe --skip-grant-tables
  ③ mysql -u root(另开shell)
  ④ use mysql;
  ⑤ update user set password=password("123456") where user='root';
  ⑥ delete from user where user = '';
  ⑦ flush privileges;
  2.5)设置root远程访问:
  ① use mysql;
  ② update user set host='%' where user='root' and host='localhost';
  ③ flush privileges;
  ④ exit;
  ⑤ systemctl restart mariadb.service
  ⑥ firewall-cmd --zone=public --add-port=80/tcp --permanent    #添加80端口
  ⑦ firewall-cmd --zone=public --add-port=3306/tcp --permanent    #添加3306端口
  ⑧ systemctl start firewalld    #重新启动防火墙
  ⑨ systemctl enable firewalld    #开机自启防火墙
  3、安装apache
  3.1)yum -y install httpd
  3.2)启动:systemctl start httpd.service
  3.3)设置开机自启:systemctl enable httpd
  3.4)配置虚拟主机:在/etc/httpd/conf.d/目录下建新vhost.conf,新增内容:
  <VirtualHost *:80>
  DocumentRoot "/var/www/html/"
  ServerName 192.168.8.100
  ErrorLog "/var/log/httpd/error.log"
  CustomLog "/var/log/httpd/access.log" common
  </VirtualHost>
  <VirtualHost *:80>
  DocumentRoot "/var/www/html/CodeIgniter-3.1.2/"
  ServerName www.100ci.com
  ErrorLog "/var/log/httpd/100ci-error.log"
  CustomLog "/var/log/httpd/100ci-access.log" common
  </VirtualHost>
  附:yum安装nginx
  # rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  # yum info nginx
  # yum install -y nginx
  # systemctl start nginx
  # systemctl enable nginx
  4、安装php7
  4.1)请参考 https://webtatic.com/packages/php71/
  4.2)rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  4.3)rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  4.4) yum -y install php71w php71w-opcache php71w-common php71w-fpm php71w-gd php71w-mbstring php71w-mcrypt php71w-odbc php71w-pecl-redis php71w-pecl-memcached php71w-mysqlnd php71w-devel
  4.5)安装完php,重启httpd,systemctl restart httpd
  4.6)如果php中有冲突的包,执行yum -y remove 包名
  5、安装phpredis扩展
  5.1)yum -y install redis php-redis
  5.2)重启httpd,systemctl restart httpd
  6、部署成功
页: [1]
查看完整版本: Centos7 用yum命令安装LAMP环境(php+Apache+Mysql)以及php扩展