How to install php 7 on centos 7

This tutorial exists for these OS versions

CentOS 7.6CentOS 7.4CentOS 7.3CentOS 7CentOS 6.5CentOS 6.2

On this page

1 Preliminary Note2 Installing MySquốc lộ / MariaDB3 Installing Apache4 Installing PHP4.1 Install PHPhường 5.44.2 Install PHP 7.04.3 Install PHP.. 7.14.4 Install PHP.. 7.25 Testing PHPhường / Getting Details About Your PHPhường. Installation6 Getting MySquốc lộ Support In PHP7 phpMyAdmin installation8 Download as virtual machine9 Links

This tutorial shows how lớn install an Apabịt web server on CentOS 7 server with PHP (mod_php) và MySQL database. The acronym LAMP is short for Linux, Apađậy, MySquốc lộ, PHP.This updated tutorial shows the installation of the lademo PHP.. versions (7.0, 7.1 and 7.2) on CentOS 7.4.

Bạn đang xem: How to install php 7 on centos 7

1 Preliminary Note

In this tutorial, I use the hostname with the IPhường p These settings might differ for you, so you have to replace them where appropriate.I will add the EPEL repo here lớn install lachạy thử phpMyAdmin as follows:rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*yum -y install epel-releaseTo edit files on the shell, I"ll install the nano editor. If you prefer vi for tệp tin editing, then skip this step.
yum -y install nano

2 Installing MySquốc lộ / MariaDB

MariaDB is a MySQL fork of the original MySQL developer Monty Widenius. MariaDB is compatible with MySQL và I"ve sầu chosen to use MariaDB here instead of MySquốc lộ. Run this comm& lớn install MariaDB with yum:
yum -y install mariadb-VPS mariadbThen we create the system startup liên kết for MySQL (so that MySquốc lộ starts automatically whenever the system boots) and start the MySquốc lộ server:systemctl start mariadb.servicesystemctl enable mariadb.serviceSet passwords for the MySQL root account:mysql_secure_installation< ~># mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order khổng lồ log inlớn MariaDB to lớn secure it, we'll need the currentpassword for the root user. If you've sầu just installed MariaDB, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none): OK, successfully used password, moving on...Setting the root password ensures that nobody toàn thân can log inlớn the MariaDBroot user without the proper authorisation.Set root password? New password: Re-enter new password: Password updated successfully!Reloading privilege tables.. ... Success!By mặc định, a MariaDB installation has an anonymous user, allowing anyonelớn log into lớn MariaDB without having to have a user tài khoản created forthem. This is intended only for testing, & lớn make the installationgo a bit smoother. You should remove sầu them before moving into aproduction environment.Remove anonymous users?  ... Success!Normally, root should only be allowed lớn connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely?  ... Success!By default, MariaDB comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving inlớn a production environment.Remove sầu test database và access to lớn it?  - Dropping demo database... ... Success! - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now?  ... Success!Cleaning up...All done! If you've sầu completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!< ~>#

3 Installing Apache

CentOS 7 ships with Apache 2.4. Apabít is directly available as a CentOS 7 package, therefore we can install it like this:yum -y install httpdHere a screenshot of the installation process.Install Apache http VPS on CentOSNow configure your system to start Apabít at boot time...systemctl start httpd.servicesystemctl enable httpd.serviceTo be able to lớn access the web hệ thống from outside, we have to open the HTTP. (80) & HTTPS (443) ports in the firewall. The mặc định firewall on CentOS is firewalld which can be configured with the firewalld-cmd commvà.firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=httpsfirewall-cmd --reloadNow direct your browser to lớn the IPhường address of your server, in my case, & you should see the Apabít placeholder page:Apađậy website hệ thống started on CentOS 7

4 Installing PHP

The PHP. version that ships with CentOS as default is quite old (PHPhường. 5.4). Therefore I will show you in this chapter some options khổng lồ install newer PHP versions like PHP 7.0 or 7.1 from Remày repository.Add the Rengươi CentOS repository.rpm -Uvh yum-utils as we need the yum-config-manager utility.yum -y install yum-utils& run yum updateyum updateNow you have sầu khổng lồ chose which PHP.. version you want to use on the VPS. If you lượt thích to lớn use PHPhường 5.4, then proceed lớn chapter 4.1. To install PHPhường 7.0, follow the commands in chapter 4.2, for PHPhường 7.1 chapter 4.3 và for PHP 7.1, use chapter 4.4 instead. Follow just one of the 4.x chapters và not all of them as you can only use one PHPhường version at a time with Apabít mod_php.

Xem thêm: angiosart h 50

4.1 Install PHP.. 5.4

To install PHP 5.4, run this command:yum -y install php

4.2 Install PHP 7.0

We can install PHPhường 7.0 & the Apabít PHPhường. 7.0 module as follows:yum-config-manager --enable remi-php70yum -y install php php-opcache

4.3 Install PHP 7.1

If you want khổng lồ use PHPhường 7.1 instead, use:yum-config-manager --enable remi-php71yum -y install php php-opcache

4.4 Install PHPhường. 7.2

If you want to use PHPhường. 7.2 instead, use:yum-config-manager --enable remi-php72yum -y install php php-opcacheIn this example and in the downloadable virtual machine, I"ll use PHP. 7.2.We must restart Apabịt to lớn apply the changes: systemctl restart httpd.service

5 Testing PHP. / Getting Details About Your PHPhường. Installation

The document root of the mặc định trang web is /var/www/html. We will create a small PHP.. tệp tin (info.php) in that directory and Hotline it in a browser to lớn kiểm tra the PHP installation. The tệp tin will display lots of useful details about our PHP.. installation, such as the installed PHP version.nano /var/www/html/info.phpNow we điện thoại tư vấn that file in a browser (e.g.ường 7.2 installed on CentOS 7As you see, PHPhường 7.2 is working, and it"s working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP.. MySQL is not listed there which means we don"t have MySquốc lộ support in PHPhường yet.

6 Getting MySQL Support In PHP

To get MySquốc lộ support in PHPhường, we can install the php-mysqlnd package. It"s a good idea khổng lồ install some other PHPhường. modules as well as you might need them for your applications. You can search for available PHP5 modules lượt thích this:yum search phpPiông xã the ones you need & install them like this:yum -y install php-mysqlnd php-pdoIn the next step I will install some comtháng PHP modules that are required by CMS Systems like Wordpress, Joomla, and Drupal:yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-develNow restart Apabịt web server: systemctl restart httpd.serviceNow reload in your browser và scroll down khổng lồ the modules section again. You should now find lots of new modules lượt thích curl etc there.:AdvertisementMySquốc lộ tư vấn added to PHPhường 7.2 on CentOSIf you don"t need the php info output anymore, then delete that file for security reasons.rm /var/www/html/info.php

7 phpMyAdmin installation

phpMyAdmin is a website interface through which you can manage your MySQL databases.phpMyAdmin can now be installed as follows:yum -y install phpMyAdminNow we configure phpMyAdmin. We change the Apache configuration so that phpMyAdmin allows connections not just from localhost (by commenting out the  stanza and adding the "Require all granted" line):nano /etc/httpd/conf.d/phpMyAdmin.conf<...>Alias /phpMyAdmin /usr/share/phpMyAdminAlias /phpmyadmin /usr/share/phpMyAdmin AddDefaultCharset UTF-8 # Apađậy 2.4# # Require ip Require ip ::1# Require all granted # Apađậy 2.2 Order Deny,Allow Deny from All Allow from Allow from ::1 Options none AllowOverride Limit Require all granted<...> Next, we change the authentication in phpMyAdmin from cookie lớn http:nano /etc/phpMyAdmin/config.inch.php<...>$cfg<'Servers'><$i><'auth_type'> = 'http'; // Authentication method (config, http or cookie based)?<...>Restart Apache:systemctl restart httpd.serviceAfterwards, you can access phpMyAdmin under installed on CentOS 7.4

8 Download as virtual machine

This setup is available as virtual machine download in ova/ovf format (compatible with VMWare & Virtualbox) for subscribers.Login details for the VMThe Linux root password is: MySQL root password is: obatambeienwasirherbal.comPlease change both passwords on the first login.The IP address of the VM is

9 Links

Apache: http://httpd.apađậ PHP: MySQL: CentOS: phpMyAdmin: BrehmAbout Till BrehmOver đôi mươi years experience as Software Developer & Linux System Administrator. Till Brehm is the founder and lead developer of the ISPConfig Hosting Control Panel software (since 2000) and he founded in 2005 as a place to lớn chia sẻ Linux knowledge with other Linux enthusiasts.