How to set up a LAMP stack

A Linux, Apache, MySQL and PHP (LAMP) stack is a model for a web server software solution. Linux is an operating system, Apache is an HTTP server, MySQL is a database and PHP is a programming language. LAMP is available for most Linux distributions, and is commonly used in web servers to build web applications and dynamic websites. Assuming your server is already running a Linux-based operating system such as CentOS, setting up a LAMP stack primarily consists of installing Apache, MySQL and PHP, if those components are not already in place.

DIFFICULTY Basic - 1 | Medium - 2 | Advanced - 3
TIME REQUIRED 30 min
RELATED PRODUCTS CentOS-based VPS or dedicated servers

Here is a quick tutorial on how to set up a LAMP stack. This procedure requires you to have root privileges. (Some of these components may already be installed in your environment; this tutorial is appropriate if you have to install all of these components.) You will need to be logged in as root to complete this tutorial.

Set up Apache

Install Apache by executing the following yum command from a terminal window:

# yum install httpd

Start the Apache service with the following command:

# service httpd start

Configure the Apache service to start automatically when you boot your server by using the following command:

# chkconfig httpd on

Verify the Apache server is running by pointing your web browser to localhost.

Set up MySQL

Install MySQL with the following command:

# yum install mysql-server

Start the MySQL service with this command:

# service mysqld start

Configure the MySQL service to start automatically when you boot your server by using the following command:

# chkconfig mysqld on

Secure your installation of MySQL with the following command:

# /usr/bin/mysql_secure_installation

You will be prompted for MySQL's root password. This account doesn't have a password since you've just installed MySQL, so just press Enter. Answer Y when prompted to set the root password, and follow the instructions. Choose the default value of Y for the remaining questions. The installation process will reload MySQL to implement your changes.

Set up PHP

Install php with the following command:

# yum install php php-mysql

Create the file /var/www/html/info.php with the following line:

Restart the Apache server with the following command:

service httpd restart

Point your web browser to localhost/info.php. If PHP has been properly installed, the info.php


Var den här artikeln till hjälp?
Tack för din feedback. Ring vårt supportnummer eller starta chattalternativet ovan om du vill prata med en medarbetare på kundtjänst.
Vi är glada att vi kunde hjälpa till! Finns det något mer vi kan göra för dig?
Det var tråkigt att höra. Berätta vad som var krångligt eller varför lösningen inte hjälpte dig med problemet.