How to build centos php environment: first install apache and configure ServerName; then install mysql; then use the command "yum install php php-devel" to install php; finally restart the service.
Recommended: "centos Getting Started Tutorial"
CentOSBuild a PHP server The environment method
is as follows:
1. Install apache first:
yum install httpd
Configure ServerName
vi /etc/httpd/conf/httpd.conf
Change #ServerName www.example.com:80 to ServerName localhost:80
When the external machine enters the IP address of the server, you should see apache On the service page, there is no need to enter the port. Apache uses port 80 by default.
If it cannot be opened, port 80 may not be open for external access. Check:
/etc/init.d/iptables status
is followed by 80 and other information, otherwise Open it, pay attention to the position and statement state, there are two horizontal bars in front of the description -:
vim /etc/sysconfig/iptables
Join:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
Then restart and save the firewall :
service iptables restart /etc/rc.d/init.d/iptables save
Check again whether it is enabled:
/etc/init.d/iptables status
Start apache:
/etc/init.d/httpd start
2. Install mysql:
yum install mysql mysql-server
Start mysql:
/etc/init.d/mysqld start
3. Install php
yum install php php-devel
Restart apache to make php take effect
/etc/init.d/httpd restart
At this time, you can create a PHP file in the directory:/var/www/html/
Code:
<?php phpinfo(); ?>
Then access this file, you can see the PHP Some information, the path to the php.ini configuration file can be seen on this page
Install php extension
The code is as follows:
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
After installing the extension, you need to restart apache again
/etc/init.d/httpd restart
PHP code to test whether mysql link is successful
<?php $con = mysql_connect("10.0.@.@@","@@","@@"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $result = mysql_query("SELECT * FROM sys_user"); while($row = mysql_fetch_array($result)) { echo $row['UserName'] . " " . $row['PassWord'] . " " . $row['id']; echo "<br />"; } mysql_close($con); ?>
You can pass the above code into the directory /var/www/html/
and you can see the execution situation
Installation Directory introduction
Apache points the root directory of the website to /var/www/html Directory
The default main configuration file is /etc/ httpd/conf/httpd.conf
Configuration is stored in the /etc/httpd/conf.d/ directory
The above is the detailed content of centos php environment setup tutorial. For more information, please follow other related articles on the PHP Chinese website!

RedHat shut down CentOS8.x and launches CentOSStream because it hopes to provide a platform closer to the RHEL development cycle through the latter. 1. CentOSStream, as the upstream development platform of RHEL, adopts a rolling release mode. 2. This transformation aims to enable the community to get exposure to new RHEL features earlier and provide feedback to accelerate the RHEL development cycle. 3. Users need to adapt to changing systems and reevaluate system requirements and migration strategies.

CentOS stands out among enterprise Linux distributions because of its stability, security, community support and enterprise application advantages. 1. Stability: The update cycle is long and the software package has been strictly tested. 2. Security: Inherit the security features of RHEL, update and announce in a timely manner. 3. Community support: a huge community and detailed documentation to respond to problems quickly. 4. Enterprise applications: Support container technologies such as Docker, suitable for modern application deployment.

Alternatives to CentOS include AlmaLinux, RockyLinux, and OracleLinux. 1.AlmaLinux provides RHEL compatibility and community-driven development. 2. RockyLinux emphasizes enterprise-level support and long-term maintenance. 3. OracleLinux provides Oracle-specific optimization and support. These alternatives have similar stability and compatibility to CentOS, and are suitable for users with different needs.

CentOS is suitable for enterprise and server environments due to its stability and long life cycle. 1.CentOS provides up to 10 years of support, suitable for scenarios that require stable operation. 2.Ubuntu is suitable for environments that require quick updates and user-friendly. 3.Debian is suitable for developers who need pure and free software. 4.Fedora is suitable for users who like to try the latest technologies.

Alternatives to CentOS include AlmaLinux, RockyLinux, and OracleLinux. 1.AlmaLinux and RockyLinux rebuild RHEL 1:1, providing high stability and compatibility, suitable for enterprise environments. 2. OracleLinux provides high performance through UEK, suitable for users who are familiar with the Oracle technology stack. 3. When choosing, stability, community support and package management should be considered.

CentOS alternatives include RockyLinux, AlmaLinux, and OracleLinux. 1. RockyLinux and AlmaLinux provide stable distributions compatible with RHEL, suitable for users who need long-term support. 2. CentOSStream is suitable for users who focus on new features and development cycles. 3. OracleLinux is suitable for users who need enterprise-level support.

CentOS needs alternatives because CentOSStream no longer provides long-term support. Alternative options include: 1. RockyLinux, which provides 10 years of life cycle support, suitable for users who need stability. 2.AlmaLinux also provides 10 years of support and has strong community support. 3. OracleLinux, provides RHEL-compatible version, and flexible life cycle management.

The end of CentOS has had a significant impact on users, with users having the option of RHEL, AlmaLinux, Debian or Ubuntu as alternatives. 1. The migration cost is high, requiring time and money. 2. Community division affects open source projects. 3.RHEL provides commercial support, but it is costly. 4.AlmaLinux is similar to CentOS and has low migration costs. 5. Debian and Ubuntu need more time to adapt.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
