Linux: Install LAMP stack on debian

Hi ,

this post describes the steps to install a lamp stack on debian linux. This is the base for many content management systems like Joomla, WordPress or Drupal.

LAMP means linux as operating system, apache as webserver,  mysql as database and PHP as script language. To install all packages login as root.

Refresh package list from repositories

root@debdevt:~# apt-get update

Install apache 2

root@debdevt:~# apt-get -y install apache2

The config of the default site (http) is defined in file
/etc/apache2/sites-available/000-default.conf
Add a

HostnameLookups Off

directive to do not resolve IP Addresses to hostnames in logfile.
Note: If wordpress permalinks returns 404 file not found errorpages add a

<Directory /var/www/html>
AllowOverride All
</Directory>

directive into the virtualhost section of /etc/apache2/sites-available/000-default.conf. Also check that module mod_rewrite is enabled.
root@debdevt:~# a2query -m rewrite

if not enable it
root@debdevt:~# a2enmod rewrite
and check if the .htaccess file in the root directory of your wordpress installation is writeable for the user www-data.
root@debdevt:/var/www/html/blog# ls -la /var/www/html/blog/.htaccess
-rw-rw---- 1 www-data root 246 Feb 24 22:32 /var/www/html/blog/.htaccess

respectively for https
/etc/apache2/sites-available/default-ssl.conf
Note: https is disabled by default due to missing certificates. Here you can find an how to generate a selfsigned certificate for an apache webserver.

Start apache. On Debian 7 Wheezy
root@debdevt:~# service start apache2
On Debian 8 Jessie type
root@debdevt:~# systemctl start apache2
if the start on jessie fails check systemd log
root@debdevt:~# journalctl -xn

Install MySQL. During the installation you will be prompted for the mysql root password. Choose a secure password and notice it in a secure location.

root@debdevt:~# apt-get -y install mysql-server

Secure your MySQL database installation

root@debdevt:~# mysql_secure_installation
Remove anonymous users? [Y/n] y
... Success!
Disallow root login remotely? [Y/n] y
... Success!
Remove test database and access to it? [Y/n] y
- Dropping test database...
Reload privilege tables now? [Y/n] y
... Success!

Open MySQL Console

root@debdevt:~# mysql -u root -p

Create a database named cms and a user with full permission on the datebase with Username cmsuser and password cmspassword

mysql> create database cms;
mysql> CREATE USER 'cmsuser'@'localhost' identified by 'cmspassword';
mysql> grant all on cms.* to 'cmsuser'@'localhost';

Install php

root@debdevt:~# apt-get -y install php5 libapache2-mod-php5 php5-mcrypt php5-mysql php-pear

Check PHP. Create a php file in your webserver root


cat > /var/www/html/phpinfo.php <<EOF
<?php
phpinfo();
?>
EOF

Time to check the LAMP stack. Open a browser and navigate to
http://IPorHostnameOfyourLAMP/phpinfo.php
this should show a php status site.

PHP State

PHP State

If phpinfo site is shown correctly delete the file
root@debdevt:~# rm /var/www/html/phpinfo.php

Not necessary but useful: Enable apache PHP logging for apache.
Create a directory for logs

root@debdevt:~# mkdir /var/log/php
root@debdevt:~# chown www-data /var/log/php

Edit /etc/php5/apache2/php.ini and set

error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off 
log_errors = On 
error_log = /var/log/php/error.log  

To import a database exported by myPhpAdmin for example. Open the sql file and alter the database name at the top of the file

CREATE DATABASE IF NOT EXISTS `DATABASE_AT_WEBHOSTER` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `DATABASE_AT_WEBHOSTER`;

to

CREATE DATABASE IF NOT EXISTS `cms` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `cms`;

and import the database

root@debdevt:~# mysql -u cmsuser -p < exported_database.sql

That’s it.

Michael

Advertisment to support michlstechblog.info

Time limit is exhausted. Please reload CAPTCHA.

Original Theme by Schiy · Powered by WordPress