LAMP环境搭建
2017-04-23 Server在阿里云CentOS 7.3服务器上部署Apache,MariaDB,PHP。
Environment
> CentOS --- 7.3.1611
> Apache --- 2.4.6
> MariaDB --- 5.5.52
> PHP --- 5.4.16/7.0.19
Apache
- 安装Apache:
$ sudo yum install httpd
- 启动Apache:
$ sudo systemctl start httpd.service
$ sudo systemctl enable httpd.service
MariaDB
- 安装MariaDB:
$ sudo yum install mariadb mariadb-server
- 设置默认中文编码为UTF-8:
$ sudo vim /etc/my.cnf
在[mysqld]
下加上:init_connect = 'SET collation_connection = utf8_general_ci,NAMES utf8' collation_server = utf8_general_ci character_set_client = utf8 character_set_server = utf8
- 启动MariaDB:
$ sudo systemctl start mariadb.service
$ sudo systemctl enable mariadb.service
- 基础配置:
$ mysql_secure_installation
- 登录mariadb:
$ mysql -u root -p
- 创建新用户:
MariaDB [(none)]> create user 'username'@'localhost' identified by 'password';
- 创建数据库try并赋予用户所有权限:
MariaDB [(none)]> create database try;
MariaDB [(none)]> grant all on try.* to 'username'@'localhost';
- 刷新权限表:
MariaDB [(none)]> flush privileges;
PHP 5
- 安装PHP:
$ sudo yum install php
- 测试PHP:
- 在
/var/www/html/
下创建index.php
,内容为:<?php phpinfo(); ?>
- 重启Apache服务:
$ sudo systemctl restart httpd.service
- 在浏览器地址栏输入IP地址后访问主页,如果出现类似的页面则说明PHP安装完成:
- 在
PHP 7
- 添加PHP 7的源:
$ sudo yum install epel-release
$ sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
- 安装PHP:
$ sudo yum install php70w
- 安装PHP扩展(根据自己的需要):
$ sudo yum install php70w-xml php70w-soap php70w-xmlrpc
$ sudo yum install php70w-mbstring php70w-json php70w-gd php70w-mcrypt
搜索其它扩展:
$ yum search php70
- 测试PHP:
- 在
/var/www/html/
下创建index.php
,内容为:<?php phpinfo(); ?>
- 重启Apache服务:
$ sudo systemctl restart httpd.service
- 在浏览器地址栏输入IP地址后访问主页,如果出现类似的页面则说明PHP安装完成:
- 在
phpMyAdmin
- 安装phpMyAdmin:
$ sudo yum install phpmyadmin
- 修改配置允许远程登录:
$ sudo vim /etc/httpd/conf.d/phpMyAdmin.conf
将两处<RequireAny> Require ip 127.0.0.1 Require ip ::1 </RequireAny>
都改为
<RequireAny> # Require ip 127.0.0.1 # Require ip ::1 Require all granted </RequireAny>
- 重启Apache服务:
$ sudo systemctl restart httpd.service
- 在浏览器地址栏输入
http://yourip/phpmyadmin
后就可以访问了。