Liunx uses apache to deploy multiple web [use lnmpa records]


foreword

提示:废话较多
Because the project needs it, I plan to simply learn about the apache deployment project and find that the configuration is similar to nginx


1. Install the apache environment

1. Use lnmpa to install the environment with one click

As shown in the figure
insert image description here
, use xshell to log in to the liunx server, press Enter to execute

wget http://soft.vpser.net/lnmp/lnmp1.9.tar.gz -cO lnmp1.9.tar.gz && tar zxf lnmp1.9.tar.gz && cd lnmp1.9 && LNMP_Auto="y" DBSelect="5" Bin="n" DB_Root_Password="lnmp.org" InstallInnodb="y" PHPSelect="10" SelectMalloc="1" ApacheSelect="2" ServerAdmin="[email protected]" ./install.sh lnmpa

About 10 minutes, returned the results
php, apache, nginx are OK
mysql8.0 installation failed (directly dumbfounded)

2. Install mysql

After a long time of repairing, I finally executed the mysql installation command

yum install mysql

It was successfully installed directly...

Log in to mysql locally, but the connection fails (I know it's not that simple)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
insert image description here

After searching for a long time, I made various attempts, but mysql.sock could not be generated.
Finally, I found that this is only available for local links, and it is not very important. You can also specify ip links locally through the following

mysql -uroot -h 127.0.0.1 -p 

insert image description here
Open mysql remote connection to facilitate local connection

Modify root login to % (%: all ip can log in)
update user set Host = '%' where Host = 'localhost' and User='root';
flush privileges;

Exit mysql, restart mysql
systemctl stop mysqld.service
systemctl start mysqld.service

Add port 3306 to the firewall
firewall-cmd --zone=public --add-port=3306/tcp --permanent
restart the firewall
firewall-cmd --reload

//Firewall command
firewall-cmd --state ##Check the firewall status, whether it is running
systemctl status firewalld.service ##Check the firewall status
systemctl start firewalld.service ##Start the firewall
systemctl stop firewalld.service ##Temporarily close the firewall
systemctl enable firewalld.service ##Set boot firewall
systemctl disable firewalld.service ##Set to disable boot firewall
firewall-cmd --permanent --query-port=80/tcp ##Check if port 80 is open
firewall-cmd --reload ##Reload configuration, for example, after adding rules, you need to execute this command
firewall-cmd --get-zones ##List supported zones
firewall-cmd --get-services ##List predefined services
firewall-cmd --query-service ftp ##Check whether the ftp service is released, return yes or no
firewall-cmd --add-service=ftp ##temporarily open ftp service
firewall-cmd --add-service=ftp --permanent ##permanent open ftp service
firewall-cmd --remove-service=ftp --permanent ##Permanently remove ftp service
firewall-cmd --add-port=80/tcp --permanent ##Permanently add port 80
firewall-cmd --zone=public - -remove-port=80/tcp --permanent ##Remove port 80
iptables -L -n ##View rules, this command is the same
man firewall-cmd as iptables ##View help

If it is not important to security, you can turn off the firewall directly like me...
systemctl stop firewalld.service

(Remember to open port 3306 in the cloud server security group)
and you can log in to mysql locally

3. close nginx

To prevent nginx interference, simply stop

1. Stop the service
calmly This method is milder than stop, and requires the process to complete the current work before stopping.
nginx -s quit
2. Immediately stop the service
This method is relatively strong, regardless of whether the process is working or not, the process is stopped directly.
nginx -s stop
3.systemctl Stop
systemctl belongs to the Linux command
systemctl stop nginx.service
4.killall method to kill the process
Directly kill the process, use it when the above is invalid, the attitude is tough, simple and rude!
killall nginx

1. nginx starts
nginx directly
2. systemctl command starts
systemctl start nginx.service
3. View the record after startup
ps aux | grep nginx
4. Restart the Nginx service
systemctl restart nginx.service
5. Reload the configuration file
nginx -s reload
6. Check port number
netstat -tlnp
7. Check port number netstat -anp |grep port number
8. Check running id ps -A |grep name
9. Check nginx error sudo nginx -t

Second, change the apache configuration file

1. Create a virtual website configuration file

You can view the apache configuration file location in lnmp:
Apache directory: /usr/local/apache/
Apache configuration file: /usr/local/apache/conf/httpd.conf
Apache virtual host configuration file directory: /usr/local/apache/conf /vhost/
Apache default virtual host configuration file: /usr/local/apache/conf/extra/httpd-vhosts.conf
virtual host configuration file name: /usr/local/apache/conf/vhost/domain name.conf

Create your own domain name conf file and put it in the /usr/local/apache/conf/vhost/ directory.
insert image description here
insert image description here
Restart apache, and there will be a prompt for input errors. The following
service httpd restart
has a warning, because I changed the httpd.conf configuration, which does not affect the web operation.
insert image description here
Here you can access the site through the domain name

2. Configure httpd.cnf

After the visit, I found a problem. I went to visit through the domain name. If I directly input the domain name, the index.html file in httpd.cnf will be displayed first, instead of the index.html file under my corresponding domain name. This is definitely not what I need to change
httpd .cnf, add the content of the first red box, the main site will not be accessed through the domain name, but the virtual site corresponding to our domain name
insert image description here

3. Apache deploys multiple web

There are two methods,
1. Run multiple apaches, specify an ip for each, and distinguish them by ip (the public network ip is too rare, generally there is only one) 2.
Just run one apache, use a virtual host, and distinguish by domain name (recommended !)

Reference: https://blog.csdn.net/THMAIL/article/details/84326277

Guess you like

Origin blog.csdn.net/lyk520dtf/article/details/127515368