How to install LAMP (Linux Apache, MariaDB & PHP) on CentOS 7

In the following article we are going to show you how to install LAMP (Linux Apache, MariaDB & PHP) on a CentOS 7 VPS.What is LAMP?

LAMP is actually an acronym for a [mysqld] services solution stack consisting of Linux, na Apache HTTP Server, na MySQL or MariaDB database engines, in PHP, Perl or Python programming language. All components are free and open-source software, and the combination is suitable for building dynamic [mysqld] pages.

Requirements?

We are [Y/n] our SSD 1 VPS hosting plan for this set-up, which should be more than enough to run SVETILKA and host multiple dynamic websites [Y/n] virtual host directives.

 

 

Posodobitev sistema

Kot vedno, make sure your CentOS 7 VPS is fully up-to-date and you’re in a <[Y/n]>screencode> session using the commands below:

## screen -U -S lamp-centos7
## yum modernizirati

 

INSTALL MARIA DB

MariaDB is the default database server in CentOS 7, so go ahead and [Y/n] it with yum z naslednjim ukazom:

## yum [Y/n] mariadb mariadb-server mysql

Ko je nameščen, Dodaj bind-address = 127.0.0.1 za /etc/my.cnf.d/server.cnf to bind MariaDB to localhost only:

## vim /etc/my.cnf.d/server.cnf

[mysqld]
#log-bin=mysql-bin
#binlog_format=mixed
bind-address = 127.0.0.1

Restart the MariaDB database server and enable it to začetek na sistem začetek-up using:

## systemctl restart mariadb
## systemctl status mariadb
## systemctl enable mariadb

Končno, you can run the mysql_secure_installation post-installation script to finish the MariaDB set-up. Na primer:

## mysql_secure_installation

Enter current geslo for root (enter for none): ENTER
Set root geslo? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

 

INSTALL APACHE

OK so far so good. Naslednji, proceed with the installation of Apache, OpenSSL and mod_ssl using yum as in:

## yum install httpd openssl mod_ssl

Restart Apache and add it to automatically start on your sistem start-up using:

## systemctl restart httpd
## systemctl status httpd
## systemctl enable httpd

Test the set-up by opening, na primer http://YOUR_SERVER_IP/ in your favorite browser. You should see the default Apache strani, na primer:

centos-default-apache-page

krasno. Now let’s configure some extra Apache options, na primer, hide its version number, its banner etc… by adding the following to /etc/httpd/conf.d/options.conf

## vim /etc/httpd/conf.d/options.conf

TraceEnable off

## Disable Signature
ServerSignature Off

## Disable Banner
ServerTokens Prod

Test Apache konfiguracijske datoteke and restart the webserver for the changes to take effect:

## apachectl configtest
## systemctl restart httpd
## systemctl status httpd

 

INSTALL PHP

In order to be able to run PHP based web applications, we have to add PHP support to the Apache webserver, so let’s install some required packages with yum:

## yum install php php-mysql

tudi, you may want to install some other PHP extensions required by your applications. Here is the list:

php-bcmath          : A module for PHP applications for using the bcmath library
php-cli             : Command-vrstica interface for PHP
php-common          : Common files for PHP
php-dba             : A database abstraction layer module for PHP applications
php-devel           : Files needed for building PHP extensions
php-embedded        : PHP library for embedding in applications
php-enchant         : Enchant spelling extension for PHP applications
php-fpm             : PHP FastCGI Process Vodja
php-gd              : A module for PHP applications for using the gd graphics library
php-intl            : Internationalization extension for PHP applications
php-ldap            : A module for PHP applications that use LDAP
php-mbstring        : A module for PHP applications which need multi-byte string handling
php-mysql           : A module for PHP applications that use MySQL databases
php-mysqlnd         : A module for PHP applications that use MySQL databases
php-odbc            : A module for PHP applications that use ODBC databases
php-pdo             : A database access abstraction module for PHP applications
php-pear.noarch     : PHP Extension and Application Repository framework
php-pecl-memcache   : Extension to work with the Memcached caching daemon
php-pgsql           : A PostgreSQL database module for PHP
php-process         : Modules for PHP script using system process interfaces
php-pspell          : A module for PHP applications for using pspell interfaces
php-recode          : A module for PHP applications for using the recode library
php-snmp            : A module for PHP applications that query SNMP-managed devices
php-soap            : A module for PHP applications that use the SOAP protocol
php-xml             : A module for PHP applications which use XML
php-xmlrpc          : A module for PHP applications which use the XML-RPC protocol

v redu, let’s continue with PHP configuration. Urejanje /etc/php.ini and set the following:

## vim /etc/php.ini

date.timezone = America/New_York
memory_limit = 64M
expose_php = Off

restart Apache using systemctl for the changes to take effect:

## systemctl restart httpd
## systemctl status httpd

Test if PHP module is loaded in Apache using:

## httpd -M | grep php

also

## php - v

You can create a test info.php script too using the following command:

## echo -e "<?phpntphpinfo();" > /var / www / html /info.PHP

and access it with the following command:

## curl -I $(curl -s icanhazip.com)/info.php

 

SET-UP APACHE VHOSTS

Zdaj, you would have to set-up Apache Virtual Host Directives, to be able to host multiple domains, even SSL powered ones using one IP naslov. Tako, ustvarite /etc/httpd/conf.d/vhosts.conf and add the following:

## cat /etc/httpd/conf.d/vhosts.conf

# Load my vhosts
IncludeOptional vhosts.d/*.conf

This tells Apache, to load the configuration files ending with .conf which reside in /etc/httpd/vhosts.d. As you can guess, this is the place where we put our Virtual Hosts, so let’s set-up one for domain1.com and another for domain2.net

VHOST for domain1.com

## cat /etc/httpd/vhosts.d/domain1.com.conf

<VirtualHost YOUR_SERVER_IP:80>
    ServerAdmin [email protected]
    DocumentRoot "/var/www/html/domain1.com"
    ServerName domain1.com
    ServerAlias www.domain1.com
    ErrorLog "/var/log/httpd/domain1.com-error_log"
    CustomLog "/var/log/httpd/domain1.com-access_log" combined

    <Directory "/var/www/html/domain1.com/">
        DirectoryIndex index.html index.php
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Imenik>
</VirtualHost>

VHOST for domain2.net

## cat /etc/httpd/vhosts.d/domain2.net.conf

<VirtualHost YOUR_SERVER_IP:80>
    ServerAdmin [email protected]
    DocumentRoot "/var/www/html/domain2.net"
    ServerName domain2.net
    ServerAlias www.domain2.net
    ErrorLog "/var/log/httpd/domain2.net-error_log"
    CustomLog "/var/log/httpd/domain2.net-access_log" combined

    <Directory "/var/www/html/domain2.net/">
        DirectoryIndex index.html index.php
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Imenik>
</VirtualHost>

Končno, restart Apache for the changes to take effect:

## apachectl configtest
## systemctl restart httpd
## systemctl status httpd

 

3 Komentarji

    • Martin kralj

Pustite Odgovori