Install Apache, PHP And MySQL On CentOS 7 (LAMP)
1、安装虚拟机(Centos 7 忽略)
2、安装apache
yum -y install httpd
systemctl enable httpd.service
systemctl start httpd.service
配置防火墙
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
3、安装PHP
yum -y install php
重启apache
systemctl restart httpd
编辑:vi /var/www/html/info.php
增加一下内容:
<?php phpinfo(); ?>
测试(可以获取PHP相关信息):
wget http://127.0.0.1/php.info
或者
4、安装mysql
yum -y install mariadb-server mariadb
systemctl enable mariadb
systemctl start mariadb
安全加固
mysql_secure_installation
验证登陆
mysql -u root -p
配置MariaDB的字符集,设置成utf8
配置文件/etc/my.cnf
在[mysqld]下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
配置文件/etc/my.cnf.d/client.cnf
在[client]下添加
default-character-set=utf8
配置文件/etc/my.cnf.d/mysql-clients.cnf
在[mysql]下添加
default-character-set=utf8
重启mysql数据库
systemctl restart mariadb.service
登陆mysql,查看字符集
MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
5、PHP和MySQL关联起来
yum -y install php-mysql
6、常用PHP模块
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
重启 apache,运行php.info 可以看到安装的模块信息
systemctl restart httpd.service
-- -- 收工 -- --