How to set up php running environment on centos7

PHPz
Release: 2023-03-21 17:18:01
Original
1875 people have browsed it

CentOS 7 is an old Linux operating system. Its stability and security are loved by the majority of server users. If you want to set up a php running environment on CentOS 7, this article will introduce you to a simple and easy-to-understand method.

  1. Install Apache

First, we need to install a web server on CentOS 7, here we choose Apache.

Enter the following command in the terminal:

sudo yum install httpd
Copy after login

After the installation is complete, start Apache:

sudo systemctl start httpd
Copy after login

If you want Apache to start automatically after booting, you can use the following command:

sudo systemctl enable httpd
Copy after login
  1. Install PHP

Next, we need to install PHP on CentOS 7 so that Apache can support PHP.

Enter the following command in the terminal:

sudo yum install -y php php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml
Copy after login

After the installation is complete, restart Apache:

sudo systemctl restart httpd
Copy after login
  1. Test PHP

In order to verify that we have successfully installed PHP, we can create a new index.php file in the /var/www/html directory and add the following code:

Copy after login

After saving, access the server IP through the browser You can see the detailed information of phpinfo() at the address.

So far, we have successfully set up the PHP running environment on CentOS 7.

  1. Install MariaDB

If you want to use MySQL database, then we can install MariaDB on CentOS 7.

Enter the following command in the terminal:

sudo yum install mariadb mariadb-server
Copy after login

After the installation is complete, start MariaDB:

sudo systemctl start mariadb
Copy after login

If you want MariaDB to start automatically after booting, you can use the following command:

sudo systemctl enable mariadb
Copy after login

Then, enter MariaDB:

sudo mysql -u root
Copy after login

There is no password by default, just press Enter to log in.

  1. Testing MariaDB

To verify that we have successfully installed MariaDB, we can enter the following command in the terminal:

show databases;
Copy after login

If the execution is successful, all database information will be listed. There is a test database by default.

Finally, we can enter the following command to exit MariaDB:

exit
Copy after login

Summary

The above is how to build a php running environment on CentOS 7. Installing services such as Apache, PHP, and MariaDB can facilitate our website development and deployment. At the same time, it also demonstrates the power of the Linux operating system, which is a skill that every developer needs to master.

The above is the detailed content of How to set up php running environment on centos7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!