LAMP on CentOS 6
- Ubuntu 22.04
- Ubuntu 20.04
- Ubuntu 18.04
- Debian 8
- Debian 11
- Debian 10
- CentOS 8
- CentOS 7
- Arch Linux
- Deprecated guides:
- Ubuntu 9.10
- Ubuntu 9.04
- Ubuntu 8.04
- Ubuntu 16.04
- Ubuntu 14.04
- Ubuntu 12.04
- Ubuntu 11.10
- Ubuntu 11.04
- Ubuntu 10.10
- Gentoo
- Fedora 20
- Fedora 19
- Fedora 15
- Fedora 14
- Fedora 13
- Fedora 12
- Fedora 11
- Debian 7
- Debian 6
- Debian 5
- CentOS 5
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
DeprecatedThis guide has been deprecated and is no longer being maintained.
A LAMP (Linux, Apache, MySQL, PHP) stack is a common web stack used to prepare servers for hosting web content. This guide shows you how to install a LAMP stack on a CentOS 6 system.
sudo
. If you’re not familiar with the sudo
command, you can check our
Users and Groups guide.Before You Begin
Ensure that you have followed the Getting Started and Securing Your Server guides, and the Linode’s hostname is set.
To check your hostname run:
hostname hostname -f
The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).
Update your system:
sudo yum update
Apache Web
Install and Configure
Install Apache 2:
sudo yum install httpd
Edit the
httpd.conf
under/etc/httpd/conf/
to adjust the resource use settings. The settings shown below are a good starting point for a Linode 2GB:Note Before changing any configuration files, it is advised that you make a backup of the file. To make a backup:
cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup
- File: /etc/httpd/conf/httpd.conf
1 2 3 4 5 6 7 8 9 10 11
KeepAlive Off ... <IfModule prefork.c> StartServers 4 MinSpareServers 20 MaxSpareServers 40 MaxClients 200 MaxRequestsPerChild 4500 </IfModule>
Configure Apache Virtual Hosts
There are different ways to set up virtual hosts; however, the method below is recommended. By default, Apache listens on all IP addresses available to it.
Create a file under
/etc/httpd/conf.d
calledvhost.conf
. Replace instances ofexample.com
with your own domain information:- File: /etc/httpd/conf.d/vhost.conf
1 2 3 4 5 6 7 8 9 10
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin webmaster@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/public_html/ ErrorLog /var/www/example.com/logs/error.log CustomLog /var/www/example.com/logs/access.log combined </VirtualHost>
Additional code blocks can be added to the file for any other domains you with to host on the Linode.
Note ErrorLog
andCustomLog
entries are suggested for more fine-grained logging, but are not required. If they are defined (as shown above), thelogs
directories must be created before you restart Apache.Create the directories referenced above:
sudo mkdir -p /var/www/example.com/public_html sudo mkdir /var/www/example.com/logs
Start Apache for the first time, and set it to run at boot:
sudo service httpd start sudo /sbin/chkconfig --levels 235 httpd on
You should new be able to view a default Apache page on your website.
Note Anytime you change an option in your
vhost.conf
file, or any other Apache configuration file, remember to reload the configuration with the following command:sudo service httpd reload
MySQL
Install and Configure
Install the MySQL package:
sudo yum install mysql-server
Start MySQL, and set it to run at boot:
sudo service mysqld start sudo /sbin/chkconfig --levels 235 mysqld on
Run
mysql_secure_installation
to secure MySQL. You will be given the option to change the root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases and reload privileges. It is recommended that you answer yes to these options:mysql_secure_installation
Create a MySQL Database
Log in to MySQL:
mysql -u root -p
Enter MySQL’s root password. You will then be presented with a MySQL prompt.
Create a database and user:
create database webdata; grant all on webdata.* to 'webuser' identified by 'password';
In the above example
webdata
is the name of the database,webuser
the user, andpassword
a strong password.Exit MySQL:
quit
With Apache and MySQL installed you are ready to move on to installing PHP.
PHP
Install and Configure
Install PHP:
sudo yum install php php-pear
If you wish to install MySQL support for PHP also install the
php-mysql
package:sudo yum install php-mysql
Edit
/etc/php.ini
for better error messages and logs, and upgraded performance. These modifications provide a good starting point for a Linode 2GB:- File: /etc/php.ini
1 2 3
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR error_log = /var/log/php/error.log max_input_time = 30
Note Ensure that all the lines noted above are uncommented. A commented line begins with a semicolon (;).Create the log directory for PHP and give the Apache user ownership:
sudo mkdir /var/log/php sudo chown apache /var/log/php
Restart Apache:
sudo service httpd restart
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on