Apache
Install and Configure Apache
1.Install Apache 2.4:
#sudo apt-get install apache2
2.Open /etc/apache2/mods-available/mpm_prefork.conf in your text editor and edit the values as needed. The following is optimized for a 2GB Linode:
# prefork MPM # StartServers: number of server processes to start # MinSpareServers: minimum number of server processes which are kept spare # MaxSpareServers: maximum number of server processes which are kept spare # MaxRequestWorkers: maximum number of server processes allowed to start # MaxConnectionsPerChild: maximum number of requests a server process serves <IfModule mpm_prefork_module> StartServers 4 MinSpareServers 20 MaxSpareServers 40 MaxRequestWorkers 200 MaxConnectionsPerChild 4500 </IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Note:These settings are good starting points, but they should be adjusted to best suit your deployment’s needs.
3.On Debian 8, the event module is enabled by default. This should be disabled, and the prefork module enabled:
#sudo a2dismod mpm_event #sudo a2enmod mpm_prefork
4.Restart Apache:
#sudo systemctl restart apache2
Configure Name-Based Virtual Hosts
There can be as many virtual hosts files as needed to support the amount of domains hosted on the Linode.
1.Create directories for your websites and websites’ logs, replacing example.com with your own domain name:
#sudo mkdir -p /var/www/html/example.com/public_html #sudo mkdir /var/www/html/example.com/logs
Repeat the process if you intend on hosting multiple websites on your Linode.
2.Create an example.com.conf file in /etc/apache2/sites-available with your text editor, replacing instances of example.com with your own domain URL in both the configuration file and in the file name:
<VirtualHost *:80> ServerAdmin webmaster@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/html/example.com/public_html/ ErrorLog /var/www/html/example.com/logs/error.log CustomLog /var/www/html/example.com/logs/access.log combined </VirtualHost>
Repeat this process for any other domains you host:
<VirtualHost *:80> ServerAdmin webmaster@example.org ServerName example.org ServerAlias www.example.org DocumentRoot /var/www/html/example.org/public_html/ ErrorLog /var/www/html/example.org/logs/error.log CustomLog /var/www/html/example.org/logs/access.log combined </VirtualHost>
3.Symbolically link your virtual hosts files from the sites-available directory to the sites-enabled directory. Replace the filename with your own:
#sudo a2ensite example.com.conf #sudo a2ensite example.org.conf
Note:Should you need to disable a site, you can use
#a2dissite example.com
4.Restart Apache:
#sudo systemctl restart apache2
MySQL
MySQL is a relational database management system (RDBMS) and is a popular component of many applications.
Install MySQL
1.Install MySQL:
#sudo apt-get install mariadb-server
Input a secure password when prompted by the installation.
2.Run mysql_secure_installation to remove the test database and any extraneous user permissions added during the initial installation process:
#sudo mysql_secure_installation
It is recommended that you select yes (y) for all questions. If you already have a secure root password, you do not need to change it.
Set Up a MySQL Database
Next, you can create a database and grant your users permissions to use databases.
1.Log in to MySQL:
#mysql -u root -p
Enter MySQL’s root password when prompted.
2.Create a database and grant your users permissions on it. Change the database name (webdata) and username (username). Change the password (password):
>create database webdata; >grant all on webdata.* to 'username' identified by 'password'; >flush privileges;
3.Exit MySQL:
>quit
PHP
PHP makes it possible to produce dynamic and interactive pages using your own scripts and popular web development frameworks.
Install PHP
PHP 7.3 is the latest version available and has the longest period of support offered as of this guide’s publishing:
1.Add the sury.org repository, which packages PHP 7.3 for Debian 8:
#sudo apt install lsb-release apt-transport-https ca-certificates #sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg #echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.3.list #sudo apt update
2.Install PHP 7.3 and the PHP Extension and Application Repository:
#sudo apt-get install php7.3 php-pear
Configure PHP
1.Open /etc/php/7.3/apache2/php.ini in your text editor and edit the following values. These settings are optimized for the 2GB Linode:
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR error_log = /var/log/php/error.log max_input_time = 30
Note:Ensure that all values are uncommented, by making sure they do not start with a semicolon (;).
2.Create the log directory for PHP and give the Apache user ownership:
#sudo mkdir /var/log/php #sudo chown www-data /var/log/php
3.If you need support for MySQL in PHP, then you must install the php7.3-mysql package:
#sudo apt-get install php7.3-mysql
4.Restart Apache:
#sudo systemctl restart apache2
Install Let’s Encrypt
Install Let-Encrypt
#cd /usr/local/bin #wget https://dl.eff.org/certbot-auto #chmod a+x certbot-auto #./certbot-auto
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
来源:https://www.linode.com/docs/web-servers/lamp/lamp-on-debian-8-jessie/#apache