LAMP stack is a group of open source software that installed together to let you run a web server to host dynamic websites. “L” stand for Linux, “A” stand for Apache (to host Web server), “M” stand for MySQL(to store database) but in RHEL 7, MariaDB will in place of MySQL by default. “P” stand for PHP(to process dynamic content). This brief tutorial will explain how to install LAMP on CentOS 7 / RHEL 7 / Oracle Linux 7.
How to Install LAMP on CentOS 7 / RHEL 7 / Oracle Linux 7
The LAMP stack is just short reference for Linux, Apache, MySQL/MariaDB and PHP :
L = Linux
A = Apache
M = MariaDB /MySQL
P = PHP
If you’re a newbie, these steps can help to install web server and database server on linux operating system. It is very simple to install install LAMP on CentOS 7 / RHEL 7 / Oracle Linux 7. You just need to follow these steps one by one.
1. Install Apache web server, Mariadb database and PHP packages :
When come to the question, how to install web server i ? The answer is very easy,
[root@centos7 ~]# sudo yum install mariadb mariadb-server httpd php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap -y
2. Start Apache web server and Mariadb database. Make it auto start at boot :
[root@centos7 ~]# sudo systemctl start httpd.service [root@centos7 ~]# sudo systemctl enable httpd.service [root@centos7 ~]# sudo systemctl start mariadb [root@centos7 ~]# sudo systemctl enable mariadb.service
3. Settings for MariaDB.
[root@centos7 ~]# sudo mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
4. Browse to your server ip http://IPaddress.
Follow the instruction in welcome.conf before proceed to configure the virtual host :
[root@centos7 ~]# vi /etc/httpd/conf.d/welcome.conf
5. Configure Apache Virtual host :
a. Create DocumentRoot directory for new domain :
[root@centos7 ~]# mkdir -p /var/www/html/ehowstuff
b. Create vhost.conf to place Name-based virtual host. For example, the default domain is centos7.ehowstuff.local and you wish to add the new virtual host www.ehowstuff.local, which points at the same IP address.
[root@centos7 ~]# vi /etc/httpd/conf.d/vhost.conf
Add the following. Please note that “NameVirtualHost *:80” no longer valid in Apache 2.4.x :
#Create new default domain <VirtualHost *:80> DocumentRoot /var/www/html ServerName centos7.ehowstuff.local </VirtualHost> # for virtual domain <VirtualHost *:80> DocumentRoot /var/www/html/ehowstuff ServerName www.ehowstuff.local ServerAdmin email@example.com ErrorLog logs/www.ehowstuff.local-error_log CustomLog logs/www.ehowstuff.local-access_log combined </VirtualHost>
6. To debug apache configuration :
[root@centos7 ~]# httpd -S
VirtualHost configuration: *:80 is a NameVirtualHost default server centos7.ehowstuff.local (/etc/httpd/conf.d/vhost.conf:2) port 80 namevhost centos7.ehowstuff.local (/etc/httpd/conf.d/vhost.conf:2) port 80 namevhost centos7.ehowstuff.local (/etc/httpd/conf.d/vhost.conf:2) port 80 namevhost www.ehowstuff.local (/etc/httpd/conf.d/vhost.conf:7) port 80 namevhost www.ehowstuff.local (/etc/httpd/conf.d/vhost.conf:7) ServerRoot: "/etc/httpd" Main DocumentRoot: "/var/www/html" Main ErrorLog: "/etc/httpd/logs/error_log" Mutex proxy: using_defaults Mutex authn-socache: using_defaults Mutex default: dir="/run/httpd/" mechanism=default Mutex mpm-accept: using_defaults Mutex authdigest-opaque: using_defaults Mutex proxy-balancer-shm: using_defaults Mutex rewrite-map: using_defaults Mutex authdigest-client: using_defaults PidFile: "/run/httpd/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="apache" id=48 Group: name="apache" id=48
7. To get more information about apache :
[root@centos7 ~]# httpd -V
Server version: Apache/2.4.6 (CentOS) Server built: Jan 12 2015 13:22:31 Server's Module Magic Number: 20120211:23 Server loaded: APR 1.4.8, APR-UTIL 1.5.2 Compiled using: APR 1.4.8, APR-UTIL 1.5.2 Architecture: 64-bit Server MPM: prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/etc/httpd" -D SUEXEC_BIN="/usr/sbin/suexec" -D DEFAULT_PIDLOG="/run/httpd/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf"
8. Check php version :
[root@centos7 ~]# php -v
PHP 5.4.16 (cli) (built: Oct 31 2014 12:59:36) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
I hope this article gives you some ideas and essential guidance on how to install LAMP on CentOS 7 / RHEL 7 / Oracle Linux 7.