Linux environment construction: CentOs + Apache + MySQL + PHP
Apache
1. Install Apache
yum install httpd -y
2. Modify the httpd configuration file, remove the # before ServerName and modify it to: ServerName localhost and save and exit##
vim /etc/httpd/conf/httpd.conf
3. Start httpd service##
systemctl start httpd
4. Test the Apache service under windows, use a browser to visit: http://192.168.81.133/ (this address is the server address of CentOs), and get the following Apache default welcome page for setting up the Apache service successfully##
MySQL
1. Download and install MySQL official Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2. Install MySQL with yum command
yum install mysql57-community-release-el7-10.noarch.rpm -y
3. Install MySQL server (this step may take some time, after the installation is completed, the previous mariadb will be overwritten)
yum install mysql-community-server -y
4. Start MySQL
systemctl start mysqld
5. View MySQL status##
systemctl status mysqld
6. Check the log file to find out the initial password of the root user##
grep "password"/var/log/mysqld.log
7. Enter the MySQL database and enter the initial password (you can't do anything at this time, because MySQL must modify the password before operating the database by default)
mysql -uroot -p
8. Modify the password, here set the login user root, the password is root123
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
There is a problem at this time. If the new password is set too simple, an error will be reported. The reason is that MySQL has a password setting specification, which is related to the value of validatepasswordpolicy. At this time, two values need to be set to use. Simple password:
mysql>set global validate_password_policy=0;
mysql>set global validate_password_length=1;
Then repeat step 8 again
9. Uninstall Yum Repository to prevent automatic update for each yum operation in the future##
yum remove mysql57-community-release-el7-10.noarch -y
PHP
1. yum install PHP
yum install php -y
yum install php-mysql -y
2. Restart Apache
systemctl restart httpd
3. Add the phpinfo.php test file in the Apache default website directory##
vim /var/www/html/phpinfo.php
4. Enter the following test code in phpinfo.php, save and exit##
5. Test the PHP service under windows, use a browser to visit: http://192.168.81.133/phpinfo.php (the address is the server address of CentOs), and get the following page, that is, the PHP service is successfully built##
6. Set boot up automatically##
systemctl enable httpd
systemctl enable mysqld
**7. Add php test file to test MySQL connection **
vim /var/www/html/test.php
<? php
$link=mysql_connect("localhost","root","root123");if(!$link)
echo "FAILD!Connection error, wrong username and password";else
echo "OK!Can connect";
echo "<br>";printf("MySQL server version:%s",mysql_get_server_info());
$link->close();?>
**8. Use a browser to access the test file: **http://192.168.81.133/test.php
Disclaimer: This article is original, the author is a game, please keep this statement and the attached article link when reprinting: http://www.duiyi.xyz/c%e5%ae%9e%e7%8e%b0%e9%9b%b7%e9%9c%86%e6%88%98%e6%9c%ba-65/