Create an Apache VM in Gentoo
This tutorial describes additional settings for the LAMP environment, such as creating a VM on Apache, generating an SSL Certificate file and key, enabling the secure SSL protocol for HTTP transactions, and using the Apache CGI gateway, then you can run the Perl script or Bash script on your website.
Step 2: Create an Apache VM
This topic uses a fake Domain Name: gentoo. lan, enabled through local host files, website files from/var/www/gentoo. lan to provide-the DocumentRoot command without valid DNS records is used to demonstrate how to enable multiple virtual hosts on Gentoo using Apache Web Server.
1. First, open the Gentoo host file and edit it. Use your domain name to add a new line.
$ sudo nano /etc/hosts
Make it look like this at the end of the file.
127.0.0.1 localhost gentoo192.168.1.13 gentoo.lan
Add domain name in host file
2. Use the ping command to test your false domain. The domain should use its IP address to respond.
$ ping -c2 gentoo.lan
Verify Domain Name
3. activating an Apache VM is quite simple. Open the default Apache VM file located in the/etc/apache2/vhosts. d/path, and enter your new VM definition before the last statement... Command.
Includes your custom settings, such as the ServerName and DocumentRoot paths. Use the following file template as a guide to the new Vm and add it to the 00_default_vhost.conf file (for non-SSL websites ).
- $ Sudo nano/etc/apache2/vhosts. d/00_default_vhost.conf
- # Another VM statement ending with </VirtualHost> ###
- <VirtualHost *: 80>
- ServerName gentoo. lan
- DocumentRoot "/var/www/gentoo. lan"
- <Directory "/var/www/gentoo. lan"
- Options Indexes FollowSymLinks ExecCGI MultiViews
- # AllowOverride controls which commands can be placed in the. htaccess file.
- AllowOverride All
- # Control who can get content from the Server File
- Order allow, deny
- Allow from all
- </Directory>
- <IfModule mpm_peruser_module>
- ServerEnvironment apache
- </IfModule>
- </VirtualHost>
- # Other VM statements ###
- # End the last statement of the VM file ##
- </IfDefine>
Create an Apache VM in Gentoo
You may see from the file content graph that the file uses a lot of instructions and annotations, and retains the definition of the local host VM-you can use it as a guide.
4. after editing a file using a custom virtual host, restart Apache to make the settings take effect and make sure that you have created the DocumentRoot directory to prevent you from changing the command, the path does not exist by default (in this case, the path is changed to/var/www/gentoo. lan ). I also created a small PHP file to test the Web server configuration.
- $ sudo mkdir /var/www/gentoo.lan
- $ su "echo '<?php phpinfo(); ?>' > /var/www/gentoo.lan/info.php"
- $ sudo /etc/init.d/apache2 restart
5. Open your browser and point it to your virtual domain name http://gentoo.lan/info.php.
Verify PHP configuration
With this method, you can use an Apache Virtual Host to add a few non-SSL websites. But for a real Internet-oriented machine, make sure that your domain is registered and valid DNS server records are used.
To delete a VM, just comment out or delete the file 00_default_vhost.conf... Command.