阿里云CentOS7搭建Apache+PHP+MySQL环境

最近要搭建一个阿里云的LMAP环境,选了CentOS7来做搭建。

1.Apache

Centos7默认已经安装httpd服务,只是没有启动。

如果你需要全新安装,可以yum install -y httpd

启动服务:systemctl start httpd.service

设置开机自动启动:systemctl enable httpd.service

Apache配置文件:/etc/httpd/conf/httpd.conf

项目默认存放目录为/var/www/html

你可以用vi来编辑或者用SFTP下载下来编辑。

检查并开放服务器的22端口:iptables -I INPUT -p tcp --dport 22 -j ACCEPT

vi /etc/httpd/conf/httpd.conf #编辑文件

ServerSignature On #添加,在错误页中显示Apache的版本,Off为不显示

Options Indexes FollowSymLinks #修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)

#AddHandler cgi-script .cgi #修改为:AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)

AllowOverride None  #修改为:AllowOverride All (允许.htaccess)

AddDefaultCharset UTF-8 #修改为:AddDefaultCharset GB2312 (添加GB2312为默认编码)

#Options Indexes FollowSymLinks #修改为 Options FollowSymLinks(不在浏览器上显示树状目录结构)

DirectoryIndex index.html #修改为:DirectoryIndex index.html index.htm Default.html Default.htm index.php(设置默认首页文件,增加index.php)

MaxKeepAliveRequests 500 #添加MaxKeepAliveRequests 500 (增加同时连接数)

:wq! #保存退出

systemctl restart httpd.service #重启apache

rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html #删除默认测试页

2、安装PHP5

安装PHP主程序:

yum -y install php

安装PHP组件,使PHP支持 MariaDB

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp

php-soap curl curl-devel

重启: systemctl restart httpd.service

3、安装mysql

CentOS7的yum源中默认是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。

1. 下载mysql的repo源

$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. 安装mysql-community-release-el7-5.noarch.rpm包

$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

安装这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。

3. 安装mysql

$ sudo yum install mysql-server

根据步骤安装就可以了,不过安装完成后,没有密码,需要重置密码。

4. 重置密码

重置密码前,首先要登录

$ mysql -u root

登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:
$ sudo chown -R root:root /var/lib/mysql

然后,重启服务:

$ service mysqld restart

接下来登录重置密码:

$ mysql -u root

mysql > use mysql;

mysql > update user set password=password(‘123456‘) where user=‘root‘;

mysql > exit;

5. 开放3306端口

$ sudo vim /etc/sysconfig/iptables

添加以下内容:

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

保存后重启防火墙:

$ sudo service iptables restart

mysql数据目录 /var/lib/mysql这样从其它客户机也可以连接上mysql服务了。

附录:

linux下phpMyAdmin 出现 “缺少 mysqli 扩展,请检查 PHP 配置。”

原因:mysqli这个扩展没有安装,或者你没有在php.ini里面加入extension=mysqli.d

解决方案:yum install php-mysql

然后重启apache

打包项目 tar -zcvf /home/files.tar.gz /files  打包

解压 tar -xzvf  files.tar.gz

以上所述是小编给大家介绍的阿里云CentOS7搭建Apache+PHP+MySQL环境,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。

发布了198 篇原创文章 · 获赞 32 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/wx_15323880413/article/details/104994487