Installing and configuring Apache, PHP, MySQL on CentOS (+ PMA and FTP)

And so, to our hands got a new server with a newly-installed CentOS.

The challenge is to make it into a full-fledged Web server.

All activities we carry out from under the root user.
1. update system.

# yum update
2. set your favorite editors.

Personally I like to use mcedit, which is embedded in the Midnight Commander, on this his and put:

# yum-y install mc
3. configure the firewall (iptables).

Not to go into many complex settings, simply disable it with the following command
CentOS: 6 # service iptables stop & & chkconfig iptables off
CentOS 7: # systemctl stop firewalld & & systemctl disable firewalld
4. Apache SSL Ustanalvivaem.

# yum-y install httpd mod_ssl

Edit the Apache config
Open in your favorite editor file/etc/httpd/conf/httpd.conf.
You can edit the mcedit (# mcedit/etc/httpd/conf/httpd.conf) or, for your convenience, use the following program: WinSCP (windows) or Coda (for MacOS X), that allow you to work with files on the server using SFTP (SSH, same files only).

In the ServerName write ip address or server name.

Line IncludeOptional conf.d/*.conf transfer at the very end of the file.
And we add to it the main virtualhost:
< VirtualHost *: 80 > ServerName webmaster@server.ru ServerAdmin/var/www/html DocumentRoot 127.0.0.1

< VirtualHost *: 80 >
Servername 127.0.0.1
Serveradmin webmaster@server.ru
DocumentRoot/var/www/html

Yet I comment out the line # CustomLog logs/access_log combined

Set AutoPlay in Apache:
CentOS 6: # chkconfig httpd on
CentOS 7: # systemctl enable the httpd service.

Run Apache:
CentOS: 6 # service httpd start
CentOS 7: # systemctl start the httpd service.

Create a test page:
# echo ‘

It Works!

‘ >/var/www/html/index.html

# echo ‘

It Works!

‘ >/var/www/html/index.html

Check the result by opening a browser on the other machine, the IP address of the server:

http://IP-adres_servera/

If the text box It Works! now, keep on
5. install PHP with some extras. components

# yum-y install php-common php-gd php-mbstring php-xml

Restart Apache:
CentOS: 6 # service httpd restart
CentOS 7: # systemctl restart the httpd service.

Check The PHP:
Create a php script that outputs information about php:
# echo ‘ ‘ >/var/www/html/inf.php

# echo ‘ ‘ >/var/www/html/inf.php

Look at the address http://IP-адрес_сервера/inf.php
If the information is displayed, continue on.
6. install MySQL or MariaDB.

Due to the fact that MariaDB is gaining more and more popularity for their outstanding features and full compatibility with mysql applications, consider both options:

Put MySQL

# yum-y install mysql mysql-server

Set MySQL auto-start:
CentOS 6: # chkconfig mysqld on
CentOS 7: # systemctl enable mysqld

Start MySQL:
CentOS: 6 # service mysqld start
CentOS 7: # systemctl start mysqld

Set the root MySQL password:
# mysqladmin-u root password ‘ new-password ‘
Where new-password — your new root password for MySQL.
Or put the MariaDB

# yum install-y mariadb-server: mariadb

Writhe in MariaDB AutoPlay:
CentOS 6: # chkconfig mariadb on
CentOS 7: # systemctl enable mariadb

Run The MariaDB:
CentOS: 6 # service mariadb start
CentOS 7: # systemctl start mariadb

Then you need to run a simple script safe installation, which will remove some dangerous default settings and will complicate access to the system database. Start the interactive script:
# mysql_secure_installation
The system will ask the current root password. But because the system MySQL just installed, the password yet, so just press enter. Then you are asked whether you want to set a password, type Y, and then follow the instructions.
For all other questions, simply press enter.

Let’s connect and check

Install the php module for work with databases
# yum-y install php-mysql

Check MySQL (or MariaDB):
Create and edit test file mysqltest.php
mcedit/var/www/html/mysqltest.php #
Copy the following code into it:

is unfortunately not available in mySQL server

“;
exit ();
}
If (! @mysql_select_db ($dbname, $dbcnx)) {
echo “

is unfortunately not available

database”;
exit ();
}
$ver = mysql_query (“SELECT VERSION ()”);
If (! $ver) {
echo “Error in query

“;
exit ();
}
echo retrieves ($ver, 0);
?>

Reserve. Check:
http://IP-адрес_сервера/mysqltest.php (after successful validation script, you may want to remove)
If the MySQL Server version was hatched, then continue.
7. configure the hosts in Apache.

Once we have verified that all of the major Web services we have work well, you can proceed to create directories of sites.
We will have this structure:
the sites directory is/home/
/home/site1.ru/— directory for a particular site
/home/site1.ru/www/-the files of this site
/home/site1.ru/logs/— logs of this site
/home/site1.ru/tmp/-temporary files of this site

And so, we create in/home/directory sites and each folder the logs, tmp, www.

After that set our hosts in Apache config:
/etc/httpd/conf.d/— in this directory will create a separate config file for each site (so convenient).
Download site1 .conf:
< VirtualHost *: 80 > ServerName site1.ru ServerAlias www.site1.ru DocumentRoot/home/site1.ru/www < Directory/home/site1.ru/www > Options FollowSymLinks AllowOverride All Require all granted # error log ErrorLog/home/site1.ru/logs/error.log # # the log messages is turned off by default, to enable clear # #CustomLog/home/site1.ru/logs/access.log # php # common safety options # 1 php_admin_value register_globals php_admin_flag date timezone. ‘ Europe/Moscow ‘ php_admin_value open_basedir/home/site1.ru php_admin_value max_execution_time 60 php_admin_value upload_max_filesize 50 m php_admin_value upload_php_admin_value/home/site1.ru/tmp session tmp_dir session.save_path/home/site1.ru/tmp

< VirtualHost *: 80 >
Servername site1.ru
ServerAlias www.site1.ru
DocumentRoot/home/site1.ru/www
< Directory/home/site1.ru/www >
Options FollowSymLinks
Allowoverride All
Require all granted

# error log
Errorlog/home/site1.ru/logs/error.log
#
# log of hits is turned off by default, to enable clear #
#CustomLog/home/site1.ru/logs/access.log common
#
# php safety options
#
php_admin_flag register_globals 1
php_admin_value date timezone. ‘ Europe/Moscow ‘
php_admin_value open_basedir/home/site1.ru
php_admin_value max_execution_time 60
php_admin_value upload_max_filesize 50 m
php_admin_value upload_tmp_dir/home/site1.ru/tmp
php_admin_value session session.save_path/home/site1.ru/tmp

The same file is created for each site from the directory/home/
After that, restart Apache:
CentOS: 6 # service httpd restart
CentOS 7: # systemctl restart httpd
If Apache does not start all of a sudden, you can always view the error log in/var/log/httpd/

Note:
If you encounter an error file or directory access, you must make sure that the file/etc/sysconfig/selinux to SELINUX is disabled, if not, restart the server and run the command # reboot.

Check:
To check it is not necessary to change the NS record of a domain, just edit the hosts file on the computer that you are configuring. In windows it usually lies in C:\Windows\System32\drivers\etc\ in nix systems in/etc/

Adding to the line:
192.168.1.5 site1.ru
Where 192.168.1.5 is the ip address of your server.
Next, create the/home/site1.ru/www/file index.html with any text.
Oktryvaem browser http://site1.ru/
If you see the content, then keep.
8. install and configure PhpMyAdmin (PMA)

To be manually. To do this, we will need a download manager wget.
If you don’t, then put:
# yum-y install wget
Go to http://www.phpmyadmin.net/home_page/downloads.php and copy the link to the latest version of PhpMyAdmin mul′tiâzyčnuû compressed .zip (at the moment it is http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.2.8/phpMyAdmin-4.2.8-all-languages.zip).
Go to/var/www/html/:
# cd/var/www/html/
Download The PMA:
# wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.2.8/phpMyAdmin-4.2.8-all-languages.zip
In a phpMyAdmin-4.2.8-all-languages.zip archive, unpack it:
# unzip phpMyAdmin-4.2.8-all-languages.zip
Rename the folder phpMyAdmin-4.2.8-all-languages in the pma:
mv phpMyAdmin-# 4.2.8-all languages-pma
Delete the phpMyAdmin-4.2.8-all-languages.zip file because it is no longer needed:
# rm phpMyAdmin-4.2.8-all-languages.zip

In theory, we have a fully working PhpMyAdmin should be available at the address: