1. Update your system
Before you begin, make sure to update your system on CentOS. To do this, open a terminal and run the following command:
sudo yum update
This command will list all the packages on your system that need to be updated. Press the Y key to update.
2. Install Apache
Many web applications run on one of the most popular web servers - Apache. To install Apache on CentOS, run the following command:
sudo yum install httpd
This command will install Apache on your system. After installation, run the following command to start the Apache service:
sudo systemctl start httpd
Enter the IP address or domain name of your server in your web browser, and you should be able to see the Apache default page.
3. Install MySQL
Providing data storage for many web applications is MySQL, a popular relational database. To install MySQL on CentOS, run the following command:
sudo yum install mysql-server mysql
With this command, you can install MySQL server and MySQL client on your system. After installation, please run the following command to start the MySQL service:
sudo systemctl start mysqld
To create a new user in MySQL, please run the following command:
sudo mysql_secure_installation
This command will prompt you to create the root user password, configure your MySQL server to improve its security. Just follow the prompts.
4. Install PHP
PHP is a server-side scripting language used to develop dynamic web applications. To install PHP on CentOS, run the following command:
sudo yum install php php-mysql
This command will install PHP and its extensions on your system. To ensure that PHP can communicate with the MySQL server, you need to install the php-mysql extension.
5. Test installation
To ensure that all components are installed successfully, you can create a test file to verify that they are functioning properly. Run the following command in the terminal to create a file:
sudo vi /var/www/html/info.php
Enter the following in the file:
<?php phpinfo(); ?>
Save and exit the file. Please enter the server's IP address or domain name into your web browser, followed by the file name of the desired file. Taking the file name as an example, if your file name is info.php, you can type in the browser:
http://your_server_ip/info.php
If you see PHP information, it means that you have successfully installed Apache, PHP and MySQL.
The above is the detailed content of How to install apache+php+mysql on centos. For more information, please follow other related articles on the PHP Chinese website!