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.
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
After the installation is complete, start Apache:
sudo systemctl start httpd
If you want Apache to start automatically after booting, you can use the following command:
sudo systemctl enable httpd
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
After the installation is complete, restart Apache:
sudo systemctl restart httpd
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:
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.
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
After the installation is complete, start MariaDB:
sudo systemctl start mariadb
If you want MariaDB to start automatically after booting, you can use the following command:
sudo systemctl enable mariadb
Then, enter MariaDB:
sudo mysql -u root
There is no password by default, just press Enter to log in.
To verify that we have successfully installed MariaDB, we can enter the following command in the terminal:
show databases;
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
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!