阿里云ECS上手动安装LAMP,搭建个人网站的第一步,不看后悔

系统环境:centos7.2
安装前提:需要一点点linux系统操作基础
使用工具:putty、winscp(根据个人爱好)
一、更新系统
使用putty进入ecs,首先执行yum update命令更新自己的系统,确保常用的一些库是最新的。阿里云用的是自己的源,因此更新速度是很快的。
另外,centos7中用firewalld代替了原来的iptables服务,这里根据自己的喜好,我是关闭了firewalld使用iptales(看官自行选择是否走这一步)
1、关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
2、安装iptables防火墙
yum install iptables-services #安装
vi /etc/sysconfig/iptables #编辑防火墙配置文件
# firewall configuration written by system-config-firewall
# manual customization of this file is not recommended.
*filter
:input accept [0:0]
:forward accept [0:0]
:output accept [0:0]
-a input -m state --state established,related -j accept
-a input -p icmp -j accept
-a input -i lo -j accept
-a input -m state --state new -m tcp -p tcp --dport 22 -j accept
-a input -m state --state new -m tcp -p tcp --dport 80 -j accept #增加这行代码
-a input -m state --state new -m tcp -p tcp --dport 3306 -j accept #增加这行代码,开放3306端口,允许远程连接
-a input -j reject --reject-with icmp-host-prohibited
-a forward -j reject --reject-with icmp-host-prohibited
commit
:wq! #保存退出
systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
二、下载安装包
因为用的电脑是windows系统,因此没有在ecs里边采用wget的方式下载所需的包,而是在win里下载好后通过winscp上传到ecs上。建议将所有上传的包放到专门的一个文件夹里(因为我是一个严重强迫症患者^_^)。当然,大家也可以尝试着用wget方式下载包,速度因人而异^_^
我下载的包:
1、前边加上index.php
保存退出吧。
10、在自己定义的网站目录里建一个index.html试验下,o(∩_∩)o哈哈~
四、安装php
1、进入安装包所在目录
cd /xxx
2、执行解压缩操作
tar -xvf php-5.6.30
cd php-5.6.30
3、安装依赖库
yum install libxml2-devel gd-devel libmcrypt-devel libcurl-devel openssl-devel
4、配置编译文件
./configure --prefix=/web/php --with-apxs2=/web/httpd/bin/apxs --enable-cli --enable-shared --with-libxml-dir --with-gd --with-openssl --enable-mbstring --with-mcrypt --with-mysqli --with-mysql --enable-opcache --enable-mysqlnd --enable-zip --with-zlib-dir --with-pdo-mysql --with-jpeg-dir --with-freetype-dir --with-curl --without-pdo-sqlite --without-sqlite3
其中 with-apxs2的目录为你的apache对应的目录 /web/apache。我这里也是抄袭的配置,基本功能差不多都有,以后需要可以再配置。
5、编译安装
make -j8 && make install
6、做一些简单配置
cp php.ini-production /web/php/lib/php.ini
vim /web/php/lib/php.ini
找到date.timezone 修改其属性值= asia/shanghai
ok,大功告成。到自己的网站目录下建立个index.php文件
输入一下内容:再打开自己的网站看一下吧,o(∩_∩)o哈哈~
五、安装mysql
自己尝试了数次编译安装mysql,始终无法成功,索性用简单的yum安装来实行。
1、安装社区资源包。系统自带安装的mysql现在已经被mariadb所取代,这不是我们想要的结果,因此有必要进行这一步,安装mysql5姿势是要先安装带有可用的mysql5系列社区版资源的rpm包。
rpm -uvh http://dev.mysql/get/mysql-community-release-el7-5.noarch.rpm
2、查看当前可用的mysql安装资源
yum repolist enabled | grep mysql.*-community.*
看到:::
mysql-connectors-community/x86_64 mysql connectors community 17
mysql-tools-community/x86_64 mysql tools community 31
mysql56-community/x86_64 mysql 5.6 community server
这些显示的话说明这两步的操作成功了
3、安装mysql
yum -y install mysql-community-server
等待一段时间,看到“complete”时表示安装成功了。
4、配置mysql
这里有点复杂,因为安装的是社区包,所以数据库有一个默认的初始密码,首先要找到它
grep password /var/log/mysqld.log
找到a temporary password is generate for root@localhost: 这里就是初始密码,记下它
然后输入:mysql_secure_installation
首先提示你修改mysql的root密码,连续输入两次新密码。密码要够发杂,否则无法通过。
通过后,按照提示一步一步选择y或者n就好了。(英语还是要懂一点点的)
提示:安装好之后我发现mysql安装到了/var/lib/mysql目录下,而且好像已经设置成开机自动启动了,直接使用吧!
至此,一个lamp环境就搭建起来了。如果有什么问题,欢迎大家咨询。