大佬教程收集整理的这篇文章主要介绍了阿里云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
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源
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
保存后重启防火墙:
这样从其它客户机也可以连接上R_346_11845@ysqL服务了。
@H_423_0@mysqL数据目录 /var/lib/MysqL附录:
linux下phpR_346_11845@yAdmin 出现 “缺少 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环境,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!
以上是大佬教程为你收集整理的阿里云CentOS7搭建Apache+PHP+MySQL环境全部内容,希望文章能够帮你解决阿里云CentOS7搭建Apache+PHP+MySQL环境所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。