2

I am trying to set up a web server to host Moodle on and I've been running into problems when trying to install PHP7.

I am currently using VirtualBox to host CentOS 7.4. By default, CentOS comes packaged with PHP 5.4.16. Now, from what I have read, the options for upgrading and installing from scratch are different. I have tried to follow multiple sites that guide towards getting PHP7 but have had no luck. The majority of guides tell you to install two repositories, Remi and EPEL. The main problem I have is that every time I install epel, yum either breaks or prevents me from installing another package.

[root@localhost ~]# yum update
Loaded plugins: fastestmirror, langpacks
Could not retrieve mirrorlist http://mirrorlist.centos.org/? 
release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"


One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:

 1. Contact the upstream for the repository and get them to fix the problem.

 2. Reconfigure the baseurl/etc. for the repository, to point to a working
    upstream. This is most often useful if you are using a newer
    distribution release than is supported by the repository (and the
    packages for the previous distribution release still work).

 3. Run the command with the repository temporarily disabled
        yum --disablerepo=<repoid> ...

 4. Disable the repository permanently, so yum won't use it by default. Yum
    will then just ignore the repository until you permanently enable it
    again or use --enablerepo for temporary usage:

        yum-config-manager --disable <repoid>
    or
        subscription-manager repos --disable=<repoid>

 5. Configure the failing repository to be skipped, if it is unavailable.
    Note that yum will try to contact the repo. when it runs most commands,
    so will have to try and fail each time (and thus. yum will be be much
    slower). If it is a very temporary problem though, this is often a nice
    compromise:

        yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

 Cannot find a valid baseurl for repo: base/7/x86_64

I have tried many ways of fixing this. Some of the main ways are:

yum clean all
yum --enablerepo=base clean metadata
rm -rf /var/cache/yum

I did get around this once or twice by using

yum --enablerepo=epel clean metadata

and also

sed -i "s/mirrorlist=https/mirrorlist=http/" /etc/yum.repos.d/epel.repo

I know there are more ways that I have tried, but I cannot remember all of them. Moral of the story is that they don't usually help. Sometimes yum works fine and I will run yum clean all, and it stops functioning again.

Method 2:

Another method I tried was installing the rpm packages from their respective websites. I used WinSCP to transfer the files to my VM and then used yum to install them. Everything works well and I got epel and remi to install. But then yum doesn't work properly.

Sometimes it will install packages, but some will not install. I've set the yum timeout value higher and other packages get through, but some still do not. Then I clean up the yum cache and once again I see the message with five options.

Method 3: I found documentation on installing PHP 7 from https://wiki.centos.org/HowTos/php7 and I thought it must work because this is the supported way.

I followed along right up until the first part.

root @ centos7-vm: ~ # yum -y install centos-release-scl.noarch

I will either get the error message stating the package could not be downloaded from a mirror or if yum is already giving me issues, it will show the five options to clean yum.

Method 4:

Building PHP from source was another option I attempted. I navigated to http://php.net/downloads.php and downloaded the tarball and used WinSCP to get it on my machine.

I extracted the files and then navigated into the php directory.

I attempted to get things going by using ./configure, but it stated I needed gcc.

I tried to install gcc with yum install gcc, but could not install all of the packages.

I made a new VM and instantly tried installing gcc, but still not luck.

Summary

Sometimes I understand why yum does not work, other times I'm slamming my head on my desk.

Is there a standardized method of getting PHP 7 on CentOS? Can anyone link an accurate guide?

What is the reason that CentOS comes packaged with PHP 5.4 and not 7?

I feel like I have tried almost everything, but I know there is some webpage that I just haven't found yet. I think I did about all the research I possibly could for today.

I'm sure my question is probably not structured the best and might be a little confusing, but I've been working on this for about 6-7 hours now.

This is my first post, so I apologize if it is not perfect.

Community
  • 1
  • 1
  • 2
    How are you breaking yum by installing php7 packages? I use IUS's repos. Yum install and good to go. – ficuscr May 08 '18 at 19:04
  • @ficuscr My thoughts exactly... – MonkeyZeus May 08 '18 at 19:05
  • I've done that but with Python major upgrades... – ficuscr May 08 '18 at 19:05
  • @importedtea, not a great SO question... try another tutorial, its a few simple commands. If you get stuck on something more specific ask again. Good luck! You'll get it. – ficuscr May 08 '18 at 19:10
  • Plus 1 for [IUS](https://ius.io/), and your yum problem has nothing to do with PHP, your yum is broken. – Sammitch May 08 '18 at 19:11
  • Honestly, I think the problem is from trying too many guides. See, I honestly thought it wouldn't be hard and that's why I'm confused. I will look into IUS. I know the problem doesn't have to do with PHP specifically, but more of the process of getting to PHP. Thank you. – importedtea May 08 '18 at 19:17
  • Suppose question is does yum update work before you try and add php7 packages? I assume you are removing needed dependencies or removing needed base repositories from list. – ficuscr May 08 '18 at 19:17
  • The problem is trying to get the repo first. That is what I don't understand. I'll explain what I just did. I created a new VM and instantly tried to install epel-release. It worked. Then I run yum update and that is when I get the message with the five options. Also, is this a good link to follow to get the IUS repo? https://www.certdepot.net/rhel7-how-to-install-the-ius-community-repository/ – importedtea May 08 '18 at 19:48
  • https://ius.io/Usage/ if really stuck, #ius on freenode. – ficuscr May 08 '18 at 20:18
  • So, I ended up finding out why I had such an issue. It seems I had a problem with DNS and that is why the mirrors would not work sometimes. I took your recommendation of IUS and got that going and the PHP packages were a breeze. I feel kinda silly for posting a question now because of how easy it was. Thank you all for your help. – importedtea May 09 '18 at 13:35
  • To install PHP LEMP, follow the steps [https://stackoverflow.com/questions/56198160/how-do-i-change-the-default-php-base-version-on-shell](https://stackoverflow.com/questions/56198160/how-do-i-change-the-default-php-base-version-on-shell) – Paulo Boaventura Nov 15 '20 at 02:42

1 Answers1

0

in my vps, I just added remi repo,

$ wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
$ rpm -Uvh remi-release-7.rpm

or

$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

then you enable on /etc/yum.repos.d/ on remi.repo, and remi-php72.repo files.

later you update, and install php and its libraries.

epel is not necesary, but is in the official repo. you just got to do a

$ yum install epel-release

and enable the file in /etc/yum.repos.d/

have you check some logs files? to see if there's any errors

Erwin
  • 183
  • 1
  • 10
  • 1
    Remi will break your system because Remi doesn't care if he breaks your system because it's your own fault for using his repo. IUS is a rock-solid repo whose stated goal is to *never* break your system. – Sammitch May 08 '18 at 19:27