LAMP Server – Install and Configure a Linux Web Server

A classic in the Unix world: a LAMP web server (Linux Apache MySQL PHP) . It is very easy to install, and it works with minimal configuration, however, for safety reasons, it is recommended to change some settings. Here is the procedure under a system ubuntu / debian.

1. Install the LAMP packages

To install the packages needed to LAMP server from your deposits, a simple apt-get enough.
apt-get install -y apache2 mysql-server php5 php5-gd php5-mysql
It will specify a password for root mysql.

2. Configuring Apache

It should be noted that the apache server is on the same machine:

echo ServerName 127.0.0.1 >> /etc/apache2/apache2.conf && /etc/init.d/apache2 reload

3. Configure Mysql

For safety reasons and to prevent intrusion attempts by the root, it will replace the account by the new user (change ‘adminsql’ and ‘mdpsql’ by the desired values)

mysql -u root -p

GRANT ALL PRIVILEGES ON * TO adminsql @ '%' IDENTIFIED BY 'mdpsql' WITH GRANT OPTION.
DELETE FROM mysql.user WHERE user = 'root';
FLUSH PRIVILEGES;
quit;

Before leaving, we can verify that the changes have been taken into account by the query:

SELECT user,host FROM mysql.user;

4. Install Phpmyadmin

For those who want a graphic visualization of their BDD, it is possible to install phpMyAdmin via apt-get.
apt-get install -y phpmyadmin
The installer then asks some questions. Select Apache2 web server, configure the base with dbconfig-common, and does not inform the administrator password.Finally, Skip step when the installer announcement that an error occurred during the installation of the database.
By default, it tries to use the root account of MySQL already removed, it is therefore to restart setup phpmyadmin which offers learn more information.

dpkg-reconfigure phpmyadmin

I need to reinstall the database to phpmyadmin? Yes 
Connection method for the MySQL database phpMyAdmin: TCP / IP 
server host name for MySQL phpmyadmin: => 127.0.0.1 
port number for the MySQL service: => 3306 
Name of director of the database: => adminsql 
password of the administrator of the database: => mdpsql 
identifier for MySQL phpmyadmin: => phpmyadmin 
name of the MySQL database to phpmyadmin : => phpMyAdmin 
web server to reconfigure automatically: => apache2

Then, edit the configuration file and change these two lines to indicate the controluser:

/etc/phpmyadmin/config.inc.php

$ Cfg [ 'Servers'] [$ i] [ 'controluser'] = 'adminsql';
$ Cfg [ 'Servers'] [$ i] [ 'controlpass'] = 'mdpsql';

By default, phpMyAdmin is accessible to the url www.example.com/phpmyadmin .It is strongly recommended to change the path (eg http://www.example.com/pma )
To do this, edit the vhost changing the first line Alias.

/etc/phpmyadmin/apache.conf

Alias / pma / usr / share / phpmyadmin

5. Setting up a new site

We will create a new site on our LAMP server, by default they are in / var / www / but any other directory can be used, according to the unix permissions.
mkdir /var/www/example && echo '<?php phpinfo(); ?>' > /var/www/example/index.php
Then create the apache vhost, by copying the following content:

/ Etc / apache2 / sites-available / mysite

<VirtualHost *: 80>
ServerName www.example.com
DocumentRoot / var / www / mysite
CustomLog combined /var/log/apache2/example.log
ErrorLog /var/log/apache2/example-err.log
LogLevel warn
<Directory />
Order Allow, Deny
Allow from all
Options + Indexes -ExecCGI + FollowSymLinks
AllowOverride All
</ Directory>
</ VirtualHost>

Then turn it on and restart Apache.
a2ensite example && service apache2 reload

Voila, your LAMP server is configured, you can go to your site to make sure everything works.


Leave a Reply

Your email address will not be published. Required fields are marked *