【人麻了】centos6.5更换yum源+httpd安装+php56安装+执行shell无写入权限+卸载php

发布时间 2023-06-28 00:00:58作者: 郭小睿

平常都是用宝塔部署web测试环境,今天需要手动去给客户部署php项目运行环境。而且居然还是centos6.5的老系统了,我整个人都麻了...

更换yum源

为啥我人麻了???

报错:centos6 yum安装软件报错Cannot retrieve repository metadata (repomd.xml) for repository: epel 的解决办法
原因分析:官方已经停止更新centos6相关的源,可以使用其他源替代

/etc/yum.repos.d/CentOS-Base.repo修改为

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-6.10 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#released updates 
[updates]
name=CentOS-6.10 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#additional packages that may be useful
[extras]
name=CentOS-6.10 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6.10 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-6.10 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6

/etc/yum.repos.d/epel.repo修改为

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://mirrors.aliyun.com/epel/6/$basearch
failovermethod=priority
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
 
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/6/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=0
 
[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/6/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=0

执行

yum clean all
yum makecache

安装httpd

yum -y install httpd*

修改一下 /etc/httpd/conf/httpd.conf 配置文件,

#ServerName www.example.com:80

更改为

ServerName localhost:80
Listen 80 #这个表示默认端口是80端口,可以修改成别的

然后重启 httpd

service httpd restart

通过ip:端口号,访问即可

默认web目录在 /var/www/html 目录下

php56安装

此时你通过yum安装的php是5.3版本的,远古时代的php,我就不多说了。。。
我们需要追加CentOS 6.5的epel及remi源。

# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

以下是CentOS 7.0的源。(这条忽略,我顺便记录下)

# yum install epel-release
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

使用yum list命令查看可安装的包(Packege)。(也可以忽略,不用执行也行)

# yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

yum源配置好了,下一步就安装PHP5.6。

yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

安装完成后,使用php -v,查看版本号即可。

执行shell无写入权限

程序中需要执行shell命令,且有新的文件写入到当前目录。
遇到如下报错:

Permission denied

刚开始,我直接给项目目录下所有文件赋权限

chmod -R 777 ./*

但是没有效果,

然后执行了这条命令

chmod -R 777 www

然后OK了,简单说下这条命令的作用。

  • chmod 修改权限指令
  • -R 对目前目录下的所有档案与子目录进行相同的权限变更
  • 777 是所有用户都拥有最高权限

卸载php

最后记录下,如何卸载?

rpm -qa |grep php

注意:要先卸载没有依赖的。pdo是mysql的依赖项;common是gd的依赖项;

rpm -e xxx #卸载命令

正确的卸载顺序是: