Sunday, October 28, 2018

thumbnail

Install LAMP on Ubuntu 16.04


I am starting with the idea that you are already on your Ubuntu machine/VPS.

1. Acquire root privilages:
 sudo -i
2. Update system:
 apt update && apt upgrade 
3. Install Apache 2
 apt install apache2 
4. The KeepAlive setting allows Apache to utilize server-side memory, reducing latency for users on the hosted site. KeepAlive will make a website faster if the host has enough memory to support it. This is done by allowing Apache to reuse connections, instead of opening a new connection for every request.
 vi /etc/apache2/apache2.conf 
Make the changes as below (or you can edit it as per your needs):
 KeepAlive On
 MaxKeepAliveRequests 50
 KeepAliveTimeout 5
5.The default multi-processing module (MPM) is the prefork module. Mpm_prefork is the module that is compatible with most systems. Since the LAMP stack requires PHP, it may be best to stick with the default.
 vi /etc/apache2/mods-available/mpm_prefork.conf 
 <ifmodule mpm_prefork_module="">
 StartServers            4
 MinSpareServers         3
 MaxSpareServers         40
 MaxRequestWorkers       200
 MaxConnectionsPerChild  10000
 </ifmodule>
6. Disable the event module and enable prefork:
 a2dismod mpm_event 
 a2enmod mpm_prefork 
7. Restart Apache
 systemctl restart apache2 
8. Create a copy of the default Apache configuration file for the site:
 cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf 
9. Edit the new example.com.conf configuration file by uncommenting ServerName and replacing example.com with your site’s IP or Fully Qualified Domain Name (FQDN). Enter the document root path and log directories.
 vi /etc/apache2/sites-available/example.com.conf 
 <virtualhost>

 ServerName example.com
 ServerAlias www.example.com
 ServerAdmin webmaster@localhost
 DocumentRoot /var/www/html/example.com/public_html

 <directory /var/www/html/example.com/public_html>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Require all granted
 </directory>

 ErrorLog /var/www/html/example.com/logs/error.log
 CustomLog /var/www/html/example.com/logs/access.log combined

 </virtualhost>
10. Create the directories:
 mkdir -p /var/www/html/example.com/{public_html,logs} 
11. Link virtual host file from the sites-available directory to the sites-enabled directory:
 a2ensite example.com.conf 
12. Disable the default virtual host to minimize security risks:
 a2dissite 000-default.conf 
13. Reload Apache:
 systemctl reload apache2 
14. Install the mysql-server
 apt install mysql-server 
14. Log into MySQL:
 mysql -u root –p 
15. Create a database and a user with permissions for it.
 CREATE DATABASE dbname;
 GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password'; 
16. Exit MySQL
 quit 
17. Install PHP, the PHP Extension and Application Repository, Apache support, and MySQL support:
 apt install php7.0 libapache2-mod-php7.0 php7.0-mysql 
Optionally, install additional cURL, JSON, and CGI support:
 apt install php7.0-curl php7.0-json php7.0-cgi 
18. Edit the php configuration file
 vi /etc/php/7.0/apache2/php.ini 
 max_input_time = 30
 error_reporting = E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR                 
 error_log = /var/log/php/error.log
19. Create the log directory for PHP and give ownership to the Apache system user:
 mkdir /var/log/php
 chown www-data /var/log/php 
20. Restart Apache:
 systemctl restart apache2 
Now Let's check if the installed LAMP server working properly
21. Paste the following code into a new file in the documentroot,(/var/www/html/example.com/public_html)
 vi /var/www/html/example.com/public_html/info.php 
 <?php
 phpinfo();
 ?>
22. Restart apache2
 systemctl restart apache2 
23. Edit the /etc/hosts file on local machine and enter the server's IP address and domain name.
 vi /etc/hosts 
 ip address       example.com 
Navigate to example.com/info.php from local machine.

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

Search This Blog

Powered by Blogger.