Installing LAMP on CentOS
How to set up Apache, MySQL, and PHP on a server without a control panel.
LAMP is a classic open-source stack for running web applications. The name is an acronym for the four components that make it up:
- 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 cache
Before installing anything, refresh the package repository metadata:
yum makecache
Installing Apache
yum install httpd
Installing MySQL
yum install mysql-server mysql-client
Once installed, start the service and set a root password:
/etc/init.d/mysqld start
/usr/bin/mysqladmin -u root password 'your-password'
Installing PHP
yum install php php-mysql
This installs PHP along with a base set of extensions and the Apache PHP module.
Setting up virtual hosts
If you're planning to host more than one site on this server, you'll need a separate VirtualHost block for each one.
On CentOS, virtual host configs live in /etc/httpd/sites-enabled/. Create that directory:
mkdir /etc/httpd/sites-enabled/
Then tell Apache to load all config files from that directory by adding this line to the main Apache config:
Include sites-enabled/*.conf
Create a config file for your domain — naming it after the domain keeps things tidy:
touch /etc/httpd/sites-enabled/mysite.com.conf
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 user full 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
Create 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's directory and download your CMS of choice — here's WordPress as an example:
cd /var/www/sites/mysite.com
wget https://wordpress.org/latest.zip
Extract the archive:
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 DNS isn't set up yet, use your server's IP address instead.
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!