First, Apache
The Mac comes with an Apache environment.
Open terminal, enter sudo apachectl-v, view Apache version.
Enter sudo apachectl start to start Apache. After startup, enter http://localhost in the browser to view the content as "IT work!" The page.
Open Finder,shift+command+g to the/,--> library-->webserver-->documents-->index.html.en You can modify the page content.
Apache under the/etc directory, etc is a hidden directory, shift+command+g to etc can be found, there are apache2 folder, content and window.
Set up a virtual host
1. Run "" In terminal sudo vi /etc/apache2/httpd.conf
to open the Apche configuration file
2. Find "" In httpd.conf #Include /private/etc/apache2/extra/httpd-vhosts.conf
, remove the previous "" #
, save and exit.
3. Run " sudo apachectl restart
", after restarting Apache, the virtual host configuration function is turned on.
4. Run " sudo vi /etc/apache2/extra/httpd-vhosts.conf
", the configuration virtual host file httpd-vhost.conf is opened and the virtual host is configured. It is important to note that the file is enabled by default for two virtual hosts as an example:
<VirtualHost*:80>ServerAdmin [email protected] documentroot "/usr/docs/dummy-host.example.com" ServerName dummy-host.example. COM errorlog "/private/var/log/apache2/dummy-host.example.com-error_log" Customlog "/private/var/log/apache2/ Dummy-host.example.com-access_log "Common</VirtualHost> <VirtualHost*:80>ServerAdmin [email protected] documentroot "/usr/docs/dummy-host2.example.com" ServerName Dummy-host2.exampl e.com errorlog "/private/var/log/apache2/dummy-host2.example.com-error_log" Customlog "/private/var/log/apache2/ Dummy-host2.example.com-access_log "Common</VirtualHost>
Code
In fact, these two virtual hosts do not exist, and when no other virtual host is configured, it may result in the following prompt when accessing localhost:
ForbiddenYou don‘t have permission to access /index.php on this server
The simplest way to do this is to add the # to the front of each line and comment it out, so that you can refer to it without causing other problems.
5. Add the following configuration
<VirtualHost*:80>documentroot "/library/webserver/documents" ServerName localhost errorlog "/private/var/log/apache2/localhos T-error_log "Customlog"/private/var/log/apache2/localhost-access_log "Common</VirtualHost> <VirtualHost*:80>documentroot "/users/snandy/work" ServerName mysites errorlog "/private/var/log/apache2/sites-error_log" Customlog "/private/var/log/apache2/sites-access_log" Common<Directory/>Options Indexes followsymlinks multiviews allowoverride None Order deny, allow to from all</Directory></VirtualHost>
Code
Save the exit and restart Apache.
Second, Tomcat
The difference between Tomcat and Apache.
Apache is a Web server (static parsing, such as HTML), and Tomcat is a Java application server (dynamic parsing, such as JSP, PHP)
Tomcat is just a servlet (JSP also translated into a servlet) container that can be considered an Apache extension, but can be run independently of Apache
installation of Tomcat
1. Download Tomcat,
2. Unzip the compressed file into the Mac system: under the "/library" directory, rename the folder to Tomcat.
3. Modify file permissions: sudo chmod 755/library/tomcat/bin/*.sh
4. Execute the startup.sh under/library/tomcat/bin.
5. Set the manager's account number and password:
Edit "/library/tomcat/conf/tomcat-users.xml", join
<rolename= "Manager"/><username = "Tomcat" Password = "xxxx" Roles = "Manager" />
Code
6. Open http://localhost:8080
Mac build Java Environment (i)