Installing LAMP on Debian / Ubuntu
How to set up Apache, MySQL, and PHP on a server without a control panel.
LAMP is the classic open-source stack for hosting web applications. The name breaks down into four components:
- Linux — the operating system
- Apache — the web server
- MariaDB / MySQL — the database system
- PHP — the server-side scripting language
Important: don't install LAMP components manually on servers that already have a control panel (cPanel, Hestia, etc.) — it will likely cause conflicts and could result in data loss.
Update the package index
apt-get update
Install Apache
apt-get install apache2
Install MySQL
apt-get install mysql-server mysql-client
During installation, you'll be prompted to set a root password for MySQL. Pick something strong — this is the first line of defence for your database.
Install PHP
apt-get install php5 php5-mysql
This installs PHP, a base set of extensions, and the libapache2-mod-php5 Apache module so PHP works out of the box with your web server.
Setting up virtual hosts
If you're hosting more than one site on this server, each one needs its own VirtualHost configuration.
On Debian/Ubuntu, site configs live in /etc/apache2/sites-enabled/. Name the file after the domain to keep things organised:
touch /etc/apache2/sites-enabled/mysite.com
Open the file in a text editor and add the following:
<VirtualHost 111.111.111.111:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/sites/mysite.com
CustomLog /var/www/httpd-logs/mysite.com.access.log combined
ErrorLog /var/www/httpd-logs/mysite.com.error.log
AddType application/x-httpd-php .php
</VirtualHost>
- Replace
111.111.111.111with your server's actual IP address - Replace
mysite.comwith your domain name
Creating a database
Connect to MySQL:
mysql -u root -p
Create a database and grant a dedicated user access to it:
create database db;
grant all privileges on db.* to 'user'@'localhost' identified by 'password';
db— your database nameuser— the database usernamepassword— the user's password
Creating site directories and installing a CMS
Set up the directories for your site files and logs:
mkdir /var/www/sites/
mkdir /var/www/sites/mysite.com
mkdir /var/www/httpd-logs
touch /var/www/httpd-logs/mysite.com.access.log
touch /var/www/httpd-logs/mysite.com.error.log
Navigate to your site directory and download your CMS — here's WordPress as an example:
cd /var/www/sites/mysite.com
wget https://wordpress.org/latest.zip
unzip latest.zip
If your domain's DNS is already pointing to this server, open the site in a browser using your domain name to continue the installation. If not, use your server's IP address in the meantime.
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!