腾讯云centOS7手动搭建LAMP并上传TP5项目

查看centOS版本命令: 

cat /etc/redhat-release

步骤1:登录 Linux 实例(此处利用putty登录)

步骤2:安装 Apache

    执行以下命令,安装 Apache。

   

yum install httpd -y

    依次执行以下命令,启动 Apache 并设置为开机自启动。

   

systemctl start httpd

   

 systemctl enable httpd

    在本地浏览器中访问以下地址,查看 Apache 服务是否正常运行。

    http://云服务器实例的公网 IP

    显示如下,则说明 Apache 安装成功。

查看apache的版本命令:

httpd -v

步骤3:安装配置 MariaDB

说明:mariadb不用修改初始密码,直接输入mysql命令即可进入;

    执行以下命令,查看系统中是否已安装 MariaDB。

   

 rpm -qa | grep -i mariadb

        返回结果类似如下内容,则表示已存在 MariaDB。

        为避免安装版本不同造成冲突,请执行下面命令移除已安装的 MariaDB。

       

yum -y remove 包名

    若返回结果为空,则说明未预先安装,则执行下一步。
    执行以下命令,在 /etc/yum.repos.d/ 下创建 MariaDB.repo 文件。

   

vi /etc/yum.repos.d/MariaDB.repo

    按 “i” 切换至编辑模式,并写入以下内容。

   

 # MariaDB 10.4 CentOS repository list - created 2019-11-05 11:56 UTC
    # http://downloads.mariadb.org/mariadb/repositories/
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.4/centos7-amd64
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1

        说明:

        您可前往 MariaDB 官网 获取其他版本操作系统的安装信息。

    按 “Esc”,输入 “:wq”,保存文件并返回。
    执行以下命令,安装 MariaDB。

   

 yum -y install MariaDB-client MariaDB-server

    这一步需要“点”时间

    依次执行以下命令,启动 MariaDB 服务,并设置为开机自启动。

   

systemctl start mariadb

   

 systemctl enable mariadb

    执行以下命令,验证 MariaDB 是否安装成功。

   

mysql

    显示结果如下,则成功安装。
    执行以下命令,退出 MariaDB。

   

\q

查看mysql的版本命令:

mysql -v

接下来设置mariadb的远程登录

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '*****';

接下来通过Navicat登录,要注意填ip地址不要填连接名...

步骤4:安装配置 PHP

    依次执行以下命令,更新 yum 中 PHP 的软件源。

   

 rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm

   

 rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

    执行以下命令,安装 PHP 7.0.33 所需要的包。

   

yum -y install php70w php70w-opcache php70w-mbstring php70w-gd php70w-xml php70w-pear php70w-fpm php70w-mysql php70w-pdo

    执行以下命令,修改 Apache 配置文件。

   

 vi /etc/httpd/conf/httpd.conf

    按 “i” 切换至编辑模式,并依次修改为如下所示的内容。

        在 ServerName www.example.com:80 下另起一行,输入以下内容:

        ServerName localhost:80

        将 <Directory> 中的 Require all denied 修改为 Require all granted
        将 <IfModule dir_module> 中内容替换为 DirectoryIndex index.php index.html
        在 AddType application/x-gzip .gz .tgz 下另起一行,输入以下内容:

        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps

    按 “Esc”,输入 “:wq”,保存文件并返回。
    执行以下命令,重启 Apache 服务。

   

systemctl restart httpd

验证环境配置

    执行以下命令,创建测试文件。

   

 echo "<?php phpinfo(); ?>" >> /var/www/html/index.php

    在本地浏览中访问以下地址,查看环境配置是否成功。

    http://云服务器实例的公网 IP/index.php

    显示结果若为php配置信息,则说明 LAMP 环境配置成功。

上传tp项目

当把tp项目上传上去之后,上传到/var/www/html文件夹里(我这里使用的腾讯云服务器centOS7),要修改httpd.conf

 vi /etc/httpd/conf/httpd.conf

 最后可能会遇到temp文件夹权限不够,那就用下面这句

chmod 777 /var/www/html/runtime/temp

 最后说明下database.php里面的mysql配置

后话

 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------

访问网站是出现了问题--只有首页可以访问,而其余页面不可以访问

观察url,当加上index.php发现可以访问,说明是伪静态的问题。

打开apache的配置文件httpd.conf

找到 #LoadModule rewrite_module modules/mod_rewrite.so

把前面#去掉。没有则添加,但必选独占一行,使apache支持 mod_rewrite 模块

找到

<Directory "D:/ApacheServer/web">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None
    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
</Directory>

AllowOverride None 换成 AllowOverride All 使apache支持 .htaccess 文件

重启apache服务器

观察网站入口文件同级目录下的.htaccess文件,

仔细观察

RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

 "/"前面是不是少了一个"?"

[吐血]...

tp5上传至服务器后验证码显示不正常,这样解决

 如果遇到mkdir() permission denied,需要赋予权限(可以直接给整个目录赋予权限)

sudo chmod -R 777 your_dir

最后附上搭建的成果

www.itforum.top

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值