How to deploy a CentOS 7 LAMP Stack

StartVM

Well-known member
Registered
Joined
Aug 5, 2016
Messages
241
Points
18
You can find many different tutorials online on how to compile a LAMP stack, but most of them lack content, and usually only give a few commands such as installing apache and php, etc. This tutorial covers everything you can/should do from the initial login to your VPS/Dedicated Server to the point you can start developing a website / move your current website.

NOTE: This tutorial is intended for quick deployment and does NOT include extra apache security and only basic server hardening.

/*
* Initial Server Setup
*/

Code:
# yum clean all
# yum -y update
# hostname localhost
# systemctl stop firewalld
# systemctl disable firewalld
/*
* Install CSF (3rd Party Firewall that is commonly used in web-hosting and is very customizable)
*/

Code:
# cd /usr/src
# rm -fv csf.tgz
# wget https://download.configserver.com/csf.tgz
# tar -xzf csf.tgz
# cd csf
# sh install.sh
// Configure CSF

Code:
# nano /etc/csf/csf.conf
// Save and close the file, then reboot the firewall

Code:
# csf -r
/*
* Change OpenSSH Default Port (Keep the hackers from ever connecting to your terminal)
*/

Code:
# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
# nano /etc/ssh/sshd_config
// Find the line that reads #Port 22
// Remove the hash (comment symbol) and change the 22 to a port you want
// Remember to open the new port in the CSF firewall "TCP_INCOMING"
// Save and close the file

Code:
# systemctl restart sshd.service
/*
* Install Apache
*/

Code:
# yum -y install httpd
/*
* Configure Apache Virtual Host (Tell the web server where the web directory is for your domain)
*/

// Replace example.com with your website's domain or any username you want
Code:
# mkdir -p /var/www/example.com/public_html
# chown -R $USER:$USER /var/www/example.com/public_html
# chmod -R 755 /var/www
# mkdir /etc/httpd/sites-available
# mkdir /etc/httpd/sites-enabled
# nano /etc/httpd/conf/httpd.conf
// Add the following line to the bottom of the file
Code:
# IncludeOptional sites-enabled/*.conf
// Save and close the file
Code:
# nano /etc/httpd/sites-available/example.com.conf
// Add the following to the configuration file and replace example.com with your servers domain name and/or username

Code:
<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog /var/www/example.com/error.log
    CustomLog /var/www/example.com/requests.log combined
</VirtualHost>
// Save and close the configuration file
Code:
# ln -s /etc/httpd/sites-available/example.com.conf /etc/httpd/sites-enabled/example.com.conf
# apachectl restart
/*
* Install CertBot (Uses lets-encrypt to create verified ssl certificates)
*/

Code:
# yum install epel-release
# yum install certbot
# yum install python-certbot-apache
# certbot --apache
// Follow the onscreen instructions to install an SSL Cert
Code:
# certbot renew --dry-run
# certbot renew --quiet
/*
* Install PHP 5.6 (Stable, supported PHP release)
*/
Code:
# yum -y update
# yum -y install epel-release
# wget https://dl.fedoraproject.org/pub/epe...t-7.noarch.rpm
# wget https://centos7.iuscommunity.org/ius-release.rpm
# rpm -Uvh ius-release*.rpm
# yum -y update
# yum -y install php56u php56u-opcache php56u-xml php56u-mcrypt php56u-gd php56u-devel php56u-mysql php56u-intl php56u-mbstring php56u-bcmath
/*
*Install MySQL (MariaDB is the CentOS 7 community version of MySQL)
*/
Code:
# yum -y install mariadb-server mariadb
# systemctl start mariadb
# mysql_secure_installation
// Follow the on-screen instructions

/*
*Install phpMyAdmin (Manage your database with an easy to use GUI)
*/
Code:
# yum -y install phpmyadmin
# nano /etc/httpd/conf.d/phpMyAdmin.conf
// Change the 4 instances of 127.0.0.1 to your external IP address
// Alias /phpMyAdmin /usr/share/phpMyAdmin
// Alias /phpmyadmin /usr/share/phpMyAdmin
// Comment out the 2 aliases and create a new one in a unique and secure location
Code:
# systemctl restart httpd.service
 
Last edited:

Moebuntu

Well-known member
Registered
Joined
Jul 1, 2016
Messages
103
Points
18
Good article!

But I found a thing you missed in your post, thats how to install mail server to send and receive emails on LAMP

I found difficult in configuring email server when installing LAMP. Can you shoot a guide on this?
 
Newer Threads
Replies
11
Views
3,888
fwh
Replies
1
Views
2,053
Replies
6
Views
3,134
Latest Threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top