Content requirements for installing classes:
Lab Environment:
VMware Virtual Machine:
System version:centos6.8 (Gan35)
IP address:192.168.31.35 (Birdege)
1, using RPM package installation method to build a lamp environment, and test whether to parse the PHP page
Install lamp environment
Check if the installation package is installed
Rpm-qa | grep httpd
Rpm-qa | grep mysql*
Rpm-qa | grep php*
Yum-y install httpd mysql-server mysql php php-mysql
# HTTPD package is Apache service
# mysql-server is a MySQL database program
# MySQL is a client program for MySQL database
# php is a PHP program, after installation, httpd can use its generated libphp5.so parse PHP Web page
# Php-mysql is a PHP connection to the database program
After the installation is complete, start the httpd and mysqld services directly and perform MySQL initialization
Service httpd Start # launch HTTPD services
Chkconfig httpd on # add httpd boot up
Chkconfig mysqld on # add MySQL boot mysqld is mysql-server service program
Service mysqld Start # starts MySQL services
Mysql_secure_installation # Security initialization for MySQL and setting the root password
Enter current password to root (enter for none): # Enter directly
Set root Password? [y/n] Y # Reset Password
New Password: # Enter a password
Re-enter new password: # Enter again
Remove anonymous users? [y/n] Y # Delete anonymous user
Disallow Root login remotely? [y/n] Y # disable root user Login
Remove test database and access to it? [y/n] Y # Remove test data
Reload privilege tables now? [y/n] Y # Load Authorization table
Accessing the virtual machine IP address in the host browser
modify ServerName as follows;
Vim/etc/httpd/conf/httpd.conf
Switch to the/var/www/html directory to create a PHP test page
#/var/www/html is the root directory of the default publishing Web page for httpd service, specified in the httpd.conf file
Cd/var/www/html
Vim index.php # After installation, the HTTPD service supports PHP Web parsing by default. Do not modify the configuration file
Enter the following content:
<?php phpinfo ()?>
: Wq # Save exit.
Restarting the HTTPD service
Service httpd Restart
Access the virtual machine IP address with the lamp environment installed in the Windows host browser to see the effect
Ok! Lamp environment has been built
2, build a virtual host, and demonstrate three different scenarios of the browsing effect
Apache has three ways to build a virtual host:
1. IP 2. Domain 3. Port
First: Back up the Apache configuration file
Cd/etc/httpd/conf
CP httpd.conf Httpd.conf.bak
2.1 Open a virtual host and access different websites via different IP
Configure the network IP address, add a second IP address 192.168.31.66,
Ifconfig eth0:1 192.168.31.66
:
Prepare the test file
rm-rf/var/www/html/index.php
Mkdir/var/www/html/test35
Mkdir/var/www/html/test66
Cd/var/www/html
echo "The IP address 192.168.31.35" >> test35/index.html
echo "The IP address 192.168.31.66" >> test66/index.html
Editing a configuration file
Vim/etc/httpd/conf/httpd.conf
namevirtualhost *:80 # open Apache Virtual host
<virtualhost 192.168.31.35:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/test35
ServerName dummy-host.example.com
Errorlog Logs/dummy-host.example.com-error_log
Customlog Logs/dummy-host.example.com-access_log Common
</VirtualHost>
<virtualhost 192.168.31.66:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/test66
ServerName dummy-host.example.com
Errorlog Logs/dummy-host.example.com-error_log
Customlog Logs/dummy-host.example.com-access_log Common
</VirtualHost>
Restart Apache Service
Service httpd Restart
Access the following address in the host browser:
192.168.31.35
192.168.31.66
2.2 Open a virtual host and enable access to different websites via different ports
Modify the configuration file as follows:
Vim/etc/httpd/conf/httpd.con
Add the following line:
Listen Bayi # Add service listening Port 81
Modify <virtualhost > below
<virtualhost *:80>
ServerAdmin [email protected]
Documentroot/var/www/html/test35
ServerName dummy-host.example.com
Errorlog Logs/dummy-host.example.com-error_log
Customlog Logs/dummy-host.example.com-access_log Common
</VirtualHost>
<virtualhost *:81>
ServerAdmin [email protected]
Documentroot/var/www/html/test66
ServerName dummy-host.example.com
Errorlog Logs/dummy-host.example.com-error_log
Customlog Logs/dummy-host.example.com-access_log Common
</VirtualHost>
Restart Apache Service
Service httpd Restart
Access via host browser is as follows:
192.168.31.35:80
192.168.31.35:81
2.3 Open a virtual host and access different websites through different domains
In the Windows host, modify the Hosts file, add the domain name resolution information, so that the host can access the virtual machine through the domain name
Edit File C:\Windows\System32\drivers\etc\hosts
Add the following line:
192.168.31.35 www.test1.com
192.168.31.35 www.test2.com
Test the following in Cmd.exe:
Ping www.test1.com
Ping www.test2.com
Modify the configuration file as follows:
Vim/etc/httpd/conf/httpd.con
Delete the Listen 81 line added above # This line is useless here!
Modify the following line:
<virtualhost *:80>
ServerAdmin [email protected]
Documentroot/var/www/html/test35
ServerName www.test1.com
Errorlog Logs/dummy-host.example.com-error_log
Customlog Logs/dummy-host.example.com-access_log Common
</VirtualHost>
<virtualhost *:80>
ServerAdmin [email protected]
Documentroot/var/www/html/test66
ServerName www.test2.com
Errorlog Logs/dummy-host.example.com-error_log
Customlog Logs/dummy-host.example.com-access_log Common
</VirtualHost>
In the host browser, visit the following:
Www.test1.com
Www.test2.com
2-24-Source code Build Lamp Environment-Job (by small Gan Yi)