西红柿番茄酱 發表於 2023-7-19 00:00:00

centos7.2搭建LAMP环境的具体操作方法

<p>
        <span><strong>一、apache、php、mysql安装</strong></span></p>
<p>
        <span><strong>1.安装php</strong></span></p>
<p>
        <strong>分步式安装:</strong></p>
<p>
        下载php:wget http://cn2.php.net/get/php-7.0.11.tar.gz/from/this/mirror<br>
        解压:tar -zxvf mirror<br>
        安装gcc:yum install -y gcc gcc+ libxml2-devel<br>
        编译:./configure --prefix=/usr/local/php7 --enable-fpm</p>
<p>
        也有比较简单的yum安装方式(在线安装,方便省事):</p>
<p>
        yum install -y php<span class="apple-converted-space"> </span>等待安装完成</p>
<p>
        再输入如下命令进行php组件安装:</p>
<p>
        yum install -y php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt</p>
<p>
        测试php是否正常安装,输入php echo<span class="apple-converted-space"> </span>“xxx”,若显示 could not open input file echo ,说明已经安装成功,或者写一个php文件执行一下即可</p>
<p>
        <span><strong>2.安装apache</strong></span></p>
<p>
        需要服务器联网</p>
<p>
        安装:yum install -y httpd</p>
<p>
        运行:/bin/systemctl start httpd.service</p>
<p>
        执行完运行命令之后是看不到效果的,这时候再输入查看apache服务状态命令来查看服务是否已经启动:</p>
<p>
        查看状态:service httpd status</p>
<p>
        apache开启服务:systemctl start httpd</p>
<p>
        apache停止服务:systemctl stop httpd</p>
<p>
        测试apache服务是否正常开启,在我们本地浏览器里输入云服务器的公网ip,我这里以118.89.32.6为例</p>
<p>
        <strong><img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/c69108fcaeb06600ed416cd18580ad77.jpg"></strong></p>
<p>
        如上所示,表示apache正常开启;</p>
<p>
        <span><strong>3.安装mysql</strong></span></p>
<p>
        <strong>wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm</strong><br><strong>rpm -ivh mysql-community-release-el7-5.noarch.rpm</strong><br><strong>yum install mysql-community-server</strong><br>
        成功安装之后重启mysql服务</p>
<p>
        <strong>service mysqld restart</strong></p>
<p>
        初次安装mysql是root账户是没有密码的<br>
        设置密码的方法:</p>
<p>
        输入mysql -uroot进入mysql数据库<br>
        mysql&gt;<span class="apple-converted-space"> set password for ‘root'@‘localhost' = password('mypasswd');<br>
        mysql&gt;<span class="apple-converted-space"> exit</span></span></p>
<p>
        远程授权连接mysql<br>
        mysql&gt;grant all privileges on *.* to 'root'@'%' identified by '你要设置的数据库密码' with grant option;<br>
        mysql&gt;flush privileges;</p>
<p>
        <span><strong>注解:</strong></span></p>
<p>
        <span>1.<strong>rpm</strong>: </span>是rpm package manager(rpm软件包管理器),一种用于互联网下载包的打包及安装工具,它包含在某些linux分发版中。它生成具有.rpm扩展名的文件。与dpkg类似。</p>
<p>
        <strong>对应命令:</strong></p>
<p>
        在terminal中,基本的安装指令如下:</p>
<p>
        rpm<span class="apple-converted-space"> -i xv-3.10a-13.i386.rpm</span></p>
<p>
        如果你的连网速度足够快,也可以直接从网络上安装应用软件,只需要在软件的文件名前加上适当的url路径。</p>
<p>
        作为一个软件包管理工具,rpm管理着系统已安装的所有rpm程序组件的资料。我们也可以使用rpm来卸载相关的应用程序。</p>
<p>
        rpm<span class="apple-converted-space"> -e xv</span></p>
<p>
        rpm的常用参数还包括:</p>
<p>
        -vh:显示安装进度;</p>
<p>
        -u:升级软件包;</p>
<p>
        -qpl:列出rpm软件包内的文件信息;</p>
<p>
        -qpi:列出rpm软件包的描述信息;</p>
<p>
        -qf:查找指定文件属于哪个rpm软件包;</p>
<p>
        -va:校验所有的rpm软件包,查找丢失的文件;</p>
<p>
        -qa:<span class="apple-converted-space"> 查找相应文件,如<span class="apple-converted-space"> rpm -qa mysql</span></span></p>
<p>
        <span>2.<strong>yum</strong>: </span>yum(全称为<span class="apple-converted-space"> yellow dog updater, modified)是一个在fedora和redhat以及centos中的shell前端软件包管理器。基于rpm包管理,能够从指定的服务器自动下载rpm包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。</span></p>
<p>
        <strong>对应命令:</strong></p>
<p>
        <strong>安装软件(以foo-x.x.x.rpm为例)</strong>:yum install foo-x.x.x.rpm</p>
<p>
        <strong>删除软件</strong>:yum remove foo-x.x.x.rpm或者yum erase foo-x.x.x.rpm</p>
<p>
        <strong>升级软件</strong>:yum upgrade foo或者yum update fo</p>
<p>
        <strong>查询信息</strong>:yum info foo</p>
<p>
        <strong>搜索软件(以包含foo字段为例)</strong>:yum search foo</p>
<p>
        <strong>显示软件包依赖关系</strong>:yum deplist foo</p>
<p>
        -e<span class="apple-converted-space"> 静默执行<br>
        -t<span class="apple-converted-space"> 忽略错误<br>
        -r[分钟]<span class="apple-converted-space"> 设置等待时间<br>
        -y<span class="apple-converted-space"> 自动应答yes<br>
        --skip-broken<span class="apple-converted-space"> 忽略依赖问题<br>
        --nogpgcheck<span class="apple-converted-space"> 忽略gpg验证</span></span></span></span></span></span></p>
<p>
        check-update<span class="apple-converted-space"> 检查可更新的包<br>
        clearn<span class="apple-converted-space"> 清除全部<br>
        clean packages<span class="apple-converted-space"> 清除临时包文件(/var/cache/yum<span class="apple-converted-space"> 下文件)<br>
        clearn headers<span class="apple-converted-space"> 清除rpm头文件<br>
        clean oldheaders<span class="apple-converted-space"> 清除旧的rpm头文件<br>
        deplist<span class="apple-converted-space"> 列出包的依赖<br>
        list<span class="apple-converted-space"> 可安装和可更新的rpm包<br>
        list installed<span class="apple-converted-space"> 已安装的包<br>
        list extras<span class="apple-converted-space"> 已安装且不在资源库的包<br>
        info<span class="apple-converted-space"> 可安装和可更新的rpm包 信息<br>
        info installed<span class="apple-converted-space"> 已安装包的信息(-qa<span class="apple-converted-space"> 参数相似)<br>
        install<span class="apple-converted-space"> 安装包<br>
        localinstall<span class="apple-converted-space"> 安装本地的<span class="apple-converted-space"> rpm包<br>
        update<span class="apple-converted-space"> 更新包<br>
        upgrade<span class="apple-converted-space"> 升级系统<br>
        search[关键词]<span class="apple-converted-space"> 搜索包<br>
        provides[关键词]<span class="apple-converted-space"> 搜索特定包文件名<br>
        reinstall<span class="apple-converted-space"> 重新安装包<br>
        repolist<span class="apple-converted-space"> 显示资源库的配置<br>
        resolvedep<span class="apple-converted-space"> 指定依赖<br>
        remove<span class="apple-converted-space"> 卸载包</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p>
        <span>3.<strong>wget</strong>:</span></p>
<p>
        wge<strong>t</strong> 是一个从网络上自动下载文件的自由工具,支持通过<span class="apple-converted-space"> http、https、ftp<span class="apple-converted-space"> 三个最常见的 tcp/ip协议 下载,并可以使用<span class="apple-converted-space"> http<span class="apple-converted-space"> 代理。"wget"<span class="apple-converted-space"> 这个名称来源于<span class="apple-converted-space"> “world wide web”<span class="apple-converted-space"> 与<span class="apple-converted-space"> “get”<span class="apple-converted-space"> 的结合。</span></span></span></span></span></span></span></span></span></p>
<p>
        所谓自动下载,是指<span class="apple-converted-space"> wget<span class="apple-converted-space"> 可以在用户退出系统的之后在继续后台执行,直到下载任务完成。</span></span></p>
<p>
        如果以上两行命令都执行成功,显示complete,则可以使用navicat 之类的来管理mysql<strong><span class="15">数据库</span></strong></p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/7093821f9a4f2bc5f8f9183d52dafe52.jpg"></p>
<p>
        <span><strong>二、配置apache、php</strong></span></p>
<p>
        <span><strong>2.1配置apache</strong></span></p>
<p>
        使用httpd -v<span class="apple-converted-space"> 命令查看apache的配置文件httpd.conf文件所在目录:</span></p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/206cbe16c9806742347442adaba808aa.jpg"></p>
<p>
        如红色圈出的所示,apache配置文件在etc/httpd/conf/目录下</p>
<p>
        进入该目录,cd /etc/httpd/conf</p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/bafb4567f5dc166a1c5097f4afe17684.jpg"></p>
<p>
        要修改的内容:</p>
<p>
        <strong>1、添加#加载php处理模块</strong></p>
<p>
        loadmodule php5_module modules/libphp5.so#添加php等后缀的处理</p>
<p>
        addtype application/x-httpd-php .php</p>
<p>
        <strong>2、修改</strong></p>
<p>
        directoryindex index.html</p>
<p>
        改成</p>
<p>
        directoryindex index.php index.html</p>
<p>
        <strong>3、修改默认访问路径</strong></p>
<p>
        documentroot = “/var/www”</p>
<p>
        方便起见,之后的所有directory<span class="apple-converted-space"> 都修改为/var/www</span></p>
<p>
        修改完所有的配置之后,点击esc键 再按住shift+;进入底行模式,输入wq<span class="apple-converted-space"> 保存退出。</span></p>
<p>
        <span><strong>2.2配置php.ini</strong></span></p>
<p>
        <strong>1、输入php --ini命令查看php.ini文件路径:此处不再上图,太马达。</strong></p>
<p>
        <strong>2、找到extension最多的地方,将前面的;去掉使php支持mysql,并且配置时要指定--with-mysql的值,如果之前安装时未配置,需要重新配置,编译,安装</strong></p>
<p>
        ;extension=php_mysql.dll</p>
<p>
        要使用phpmyadmin或mysqli函数打开,并且配置时要指定--with-mysqli的值,如果之前安装时未配置,需要重新配置,编译,安装</p>
<p>
        ;extension=php_mysqli.dll</p>
<p>
        要php支持png,jpg,gif等(phpcmsv9必须)打开</p>
<p>
        ;extension=php_gd2.dll</p>
<p>
        大字符集,支持多字符集之间的转换打开</p>
<p>
        ;extension=php_mbstring.dll</p>
<p>
        php5默认&lt;?php echo date("y-m-d h:i:s");?&gt;时间与北京时间相差八小时(少八小时)</p>
<p>
        为什么呢?php5系列版本新增了时区设置,默认为格林威治时间,与中国所在的东8区正好相差8个小时,查找</p>
<p>
        ;date.timezone =</p>
<p>
        将;去掉,并修改成date.timezone = prc</p>
<p>
        除了e_notice类型的错误(notice)不报告,其他的都报告,查找error_reporting = e_all</p>
<p>
        改成error_reporting = e_all &amp; ~e_notice</p>
<p>
        <strong>3、找到extension_dir</strong></p>
<p>
        去掉前面的分号,修改为extension_dir = “你的php安装目录/ext”</p>
<p>
        php安装目录查看:</p>
<p>
        <strong>4、在linux中输入rpm -ql php 查看php安装目录:</strong></p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/92e4c01c24d444e1cb653fe5969181a8.jpg"></p>
<p>
        修改完所有的配置之后重启apache:</p>
<p>
        systemctl stop httpd</p>
<p>
        systemctl start httpd</p>
<p>
        或者:</p>
<p>
        systemctl restart httpd</p>
<p>
        <span><strong>三、一键安装:(方便省事^_^)</strong></span></p>
<p>
         </p>
<p>
        需要一键安装包,我这里使用的是阿里云提供的安装包:<img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/895e1b061ba67a182f21912734befeca.jpg"></p>
<p>
        打开xshell ,进入xftp界面:将本地安装包拖入远程服务器root目录下:</p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/1b2032226d5767c57c4a775ec9000272.jpg"></p>
<p>
        切换到xshell窗口,进入root目录下 :cd /root</p>
<p>
        依次键入以下命令安装:</p>
<p>
        chmod -r 777 sh-1.5.5</p>
<p>
        cd sh-1.5.5</p>
<p>
        ./install.sh</p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/e5f5226c9437741c52dc69219b0723d5.jpg"></p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/90264959004d071c2284a87d8b1bcf52.jpg"></p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/a7feff4f45d6c62d7122358c07730947.jpg"></p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/a543288320ec81ef8af8d029a4ad6fbf.jpg"></p>
<p>
        剩余的配置步骤同上面一样,具体目录如下:</p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="centos7.2搭建LAMP环境的具体操作方法" alt="centos7.2搭建LAMP环境的具体操作方法" src="https://zhuji.jb51.net/uploads/img/202305/0dcf046f1079334f7cb84bd37fcc8004.jpg"></p>
<p>
        之后便可以通过xftp上传自己的项目到网站根目录了。</p>
<p>
        以上这篇centos7.2搭建lamp环境的具体操作方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。</p>
頁: [1]
查看完整版本: centos7.2搭建LAMP环境的具体操作方法