https://www.zerostopbits.com/how-to-install-apache-mysql-and-php-on-centos-6-7/
How to Install Apache, MySQL, and PHP on CentOS 6.7
Keep in mind, this article is written with the assumption that you are running a freshly installed vps server, or dedicated server running CentOS 6.7.
1. Update and configure the system, and disable SELinux
While not strictly necessary, the first
thing we always do when deploying a vps server or dedicated server is
update the system. This process will download the latest kernel, any
software updates that might be pending, as well as the nano editor,
which makes life much easier when editing configuration files.
yum -y upgrade && yum -y install nano
Once that process has completed, lets go ahead and disable SELinux
nano /etc/sysconfig/selinux
Once you’re in the editor, find the following line:
SELINUX=enabled
And change it to:
SELINUX=disabled
We also want to make sure your server has
nameservers correctly configured. If running a VPS server, this is
usually done already.
nano /etc/resolv.conf
If the above command returns an empty
file, or a file with no nameserver entries in it, simply add the
following to add Google’s Open DNS Resolver’s to your server:
nameserver 8.8.8.8
nameserver 8.8.4.4
Now reboot your server;
shutdown -r now
and let’s move on to the next steps!
2. Install Apache, MySQL, PHP, and some additional packages
Now that your system is up-to-date, we can begin to install the basic components of your web server.
yum -y install httpd mysql mysql-server php wget ntp
This command will install the following packages on your system:
httpd-2.2
php-5.3
mysql-5.1
ntp-4.2
wget-1.12
While these packages are not the latest
available, they should suffice for most applications you intend on
running. However, if you need the latest and greatest, stay tuned for
our articles on how to upgrade apache 2.2 to 2.4, how to upgrade php 5.3 to 5.4, and how to upgrade mysql 5.1 to 5.5.
We installed the ntp package to make sure
your server is keeping time properly. To configure this package, it’s
as easy as doing the following:
chkconfig ntpd on
ntpdate pool.ntp.org
service ntpd start
3. Configure Apache, MySQL, and PHP
Great, you’ve got the basic packages installed and ready to go, whats next?
Let’s configure Apache to prepare it for some VirtualHost’s, so you can start adding your websites and domains to your server!
mkdir -p /var/www/virtual/
chown -R apache:apache /var/www/virtual/
chmod -R 755 /var/www/virtual/
That created the directory where your websites data will live. To further configure the VirtualHost, you can follow my guide on how to create a virtualhost in apache.
Now, we’re going to configure some basic Apache settings.
nano /etc/httpd/conf/httpd.conf
Find the following lines, and change them as noted below. You can use CTRL-W to search through the configuration file:
ServerName serverhostname.yourdomain.com:80 (enter your server hostname here)
DirectoryIndex index.html index.html.var index.php
ServerSignature Off
ServerTokens Prod
Save the configuration file using CTRL-O, and close the file with CTRL-X
Enter the following commands to start Apache, and make sure it starts on boot.
chkconfig httpd on
service httpd start
Chances are, you’re also going to need to open up port 80 on the iptables firewall. To do that, we need to do the following:
nano /etc/sysconfig/iptables
Find the following line:
-A INPUT -i lo -j ACCEPT
And add the below line immediately underneath:
-A INPUT -m tcp -p tcp --dport 80 -j ACCEPT
Hit CTRL-O to save, and CTRL-X to close the configuration file.
Now restart iptables for the changes to take effect:
service iptables restart
I’ve
Now let’s configure MySQL for a basic
environment. First, we need to “secure” the installation, thankfully,
MySQL comes packaged with a script that automates most of this process:
chkconfig mysqld on
service mysqld start
Now that MySQL has started, run the following script:
mysql_secure_installation
You want to make sure you set a root
password, remove anonymous user, disallow root login remotely, and
remove the test database. The output should look similar to below:
[root@vps ~]# mysql_secure_installation
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] y
... Success!
Disallow root login remotely? [Y/n] y
... Success!
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] y
... Success!
We could further tune and tweak MySQL at this point, but that is beyond the scope of this article.
Likewise, PHP and Apache can and should be further tuned depending on your application, but at this point, you should have a working webserver! You can test this by visiting http://your-ip-address
No hay comentarios:
Publicar un comentario