Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

HTTP protocol (2) configure Web server LAMP

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

In previous courses, we used Appserv or PHPStudy to build a Web service environment. Here we introduce how to build a real LAMP (Linux+Apache+ MySQL + PHP) environment through CentOS7.5. When deploying LAMP, the general order in which software is installed is Linux → Apache → PHP → MySQL.

Both the software name and the corresponding service name of Apache are httpd, and Apache is not installed by default in CentOS7. Therefore, you first need to install and start the httpd service and set it to boot and run automatically.

[root@Server ~] # yum install httpd [root@Server ~] # systemctl start httpd [root@Server ~] # systemctl enable httpd

Since a default Web site has been set up in Apache, you can access the default site by entering the IP address of the Web server on the client. If you cannot access it, you need to execute the "setenforce 0" command to shut down SELinux.

Then install the PHP,PHP installation package on the system with the name php. It should be noted that PHP is not a stand-alone service, but is regarded as a functional module of Apache, so after installing PHP, we only need to restart the httpd service to take effect.

[root@ localhost ~] # yum install php` [root@ localhost ~] # systemctl restart httpd

Let's test whether the Web server can support PHP dynamic pages. Generate a PHP test page test.php in the website home directory "/ var/www/html", with only one phpinfo () function in the page code. When the client accesses the test.php page, the function is executed on the server first, and then the result of the function execution is returned to the client.

[root@ localhost ~] # vim / var/www/html/test.php

Then visit the test page in the client browser, and if the page shown in the figure appears successfully, it proves that Apache can support PHP dynamic web pages.

Before we proceed with installing MySQL, we need to install another package, php-mysql, which PHP can operate on the MySQL database only after it has been installed. Of course, this package can also be installed with the PHP package.

[root@ localhost ~] # yum install php-mysql

Let's install MySQL on the system. It should be noted that the installation package of MySQL is no longer provided by default in the CentOS7 system, this is because MySQL has been acquired by Oracle, although MySQL is still open source, but there is a risk of being closed at any time, so it is replaced by mariaDB, which is fully compatible with MySQL database software, and is also a thorough open source software.

The installation package for the mariaDB service, called mariadb-server,mariaDB, exists as a stand-alone service in CentOS, so after installing the software, you still need to start the service and set it to boot and run automatically.

[root@ localhost ~] # yum install mariadb- server` [root@ localhost ~] # systemctl start mariadb [root@ localhost ~] # systemctl enable mariadb

Next, we also need to do some initialization of mariaDB, mainly to set the administrator password of mariaDB. The administrator account of mariaDB is also called root, but it is not the root user in Linux, they just have the same name. You can use the mysqladmin command in CentOS to set a password for the administrator account of mariaDB:

[root@ localhost ~] # mysqladmin-u root password "123"

Then you can use the client tool mysql to log in to mariaDB. After successfully logging in, you can enter the interactive mode of mariaDB, and use the quit or exit command to exit.

[root@CentOSServer] # mysql-uroot-pEnter password: Welcome to the MariaDB monitor. Commands end with; or\ g.Your MariaDB connection id is 154Server version: 5.5.56-MariaDB MariaDB ServerCopyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.MariaDB [(none)] >

Let's test whether PHP can be used to connect to the mariaDB database. Still create a test page, test2.php, in the main directory of the site, with the following code. This code means that as a root user, use the password "123" to connect to the mariaDB database on the local server, and if the connection is successful, output "success", otherwise output "fail".

By visiting the test page on the client side, if "success" appears, all the previous configurations are successful.

At this point, a fully functional LAMP platform has been built.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report