For the purpose of this tutorial, we will use yourdomain.tdl as our domain. Anytime you see something like {yourdomain.tdl} or anything similar enclosed in curly braces, please replace with the text specific for your setup.
Install Apache Server on CentOS
- Install
[code]yum install httpd[/code]
- Set to startup Apache on boot
[code]chkconfig –levels 235 httpd on[/code]
- Open this configuration file /etc/httpd/conf/httpd.conf, uncomment the following line and save the file (i.e. remove the pound sign “#” at the beginning of the line, if there is one)
[code]NameVirtualHost *:80[/code]
- Restart Apache (you will get an error that says something like “NameVirtualHost *:80 has no VirtualHosts” that you can ignore. We will address this when we set up our virtual host later)
[code]service httpd restart[/code]
- Test by going to http://localhost/ in your browser. If successful, you should get the Apache sample page.
- For security, delete this file
Grant Existing User Document Root Permissions
This is optional, but it will setup an existing user with the ability to sftp files to the document root. The code below does the following…
- Adds the user to the apache group
- Changes the document root permissions (sets all to a group of “apache”)
- Sets the permissions (add “group write” ability on everything
[code]sudo usermod -a -G apache <username>
sudo chgrp -R apache /var/www/html
sudo chmod -R g+w /var/www/html
[/code]
Set ServerName
- Create a DNS A Record to your server’s ip for your server name (i.e. server.yourdomain.tdl)
- Edit /etc/hosts file and add your server name to the end of the first two lines and add it for your servers ip. It might look something like this if your server name is server.yourdomain.tdl and your ip is 12.345.6.78…
[code]
127.0.0.1 localhost localhost.localdomain server.yourdomain.tdl
::1 localhost localhost.localdomain server.yourdomain.tdl12.345.6.78 server.yourdomain.tdl
[/code] - Edit /etc/httpd/conf/httpd.conf and add the ServerName below the example line that is commented out. Example…
[code]
#ServerName www.example.com:80
ServerName server.yourdomain.tdl:80[/code]
Create a Virtual Host on CentOS
- Create the file /etc/httpd/conf.d/{yourdomain.tdl}.conf and edit the file as below…
[code]
<VirtualHost *:80>
# General
ServerAdmin {webmaster_email}
DocumentRoot /var/www/html/{yourdomain.tdl}/public_html/
ServerName www.{yourdomain.tdl}
ServerAlias {yourdomain.tdl}# Logging
ErrorLog logs/{yourdomain.tdl}-error.log
CustomLog logs/{yourdomain.tdl}-access.log common
</VirtualHost>
[/code] - Restart Apache
[code]service httpd restart[/code]
Point your domain to your server
The specific steps vary depending on what domain registrar you are using, but what you need to do is set up an A Record for you domain and point it to your server’s public IP. You can set up one or more of the following
- A Record for “@”: for none, as in yourdomain.tdl
- A Record for “www”: as in www.yourdomain.tdl
- A Record for “*”: for {anything}.yourdomain.tdl
You can use this wildcard DNS record without doing the other two previous A Records since it will encompass all of the above plus any other subdomains you decide to create now and in the future.
Below is a sample of what each of these might look like (replace the IP 123.456.7.890 with your public IP).
This may take a little while for the DNS to propagate. I usually see it come through within about 30 minutes, but it can take about 24-48 hours so be patient. You can check the status using this tool at https://www.whatsmydns.net/ to see if it’s working. It won’t tell you when it’s fully complete, but you can at the very least check to see if your new IP has started showing up.
Setup MySQL on CentOS
- Install MySQL
[code]yum install mysql-server mysql php-mysql[/code]
- Set MySQL to start on boot
[code]chkconfig –levels 235 mysqld on[/code]
- Start MySQL
[code]service mysqld start[/code]
- Log into MySQL
[code]mysql -u root[/code]
- Set root user password for all domains, drop the “any” users then exit
[sql]
SET PASSWORD FOR ‘root’@’127.0.0.1’ = PASSWORD(‘{NewPassword}’);
SET PASSWORD FOR ‘root’@’centos64’ = PASSWORD(‘{NewPassword}’);
SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘{NewPassword}’);DROP USER ”@’localhost’;
DROP USER ”@’centos64′;EXIT;
[/sql]The users you edit might be slightly different. You can run the following which will produce a list of root users and related hosts (example output below).
[code]
mysql> SELECT Host, User FROM mysql.user;
+———–+——+
| Host | User |
+———–+——+
| 127.0.0.1 | root |
| centos64 | |
| centos64 | root |
| localhost | |
| localhost | root |
+———–+——+
4 rows in set (0.00 sec)
[/code] - You may also want to refer to this tutorial… Create MySQL Database and Add New User (command line)
If you need to set up remote access to your SQL server, try this tutorial on how to allow remote access to MySQL server.
Setup PHP on CentOS
- Install PHP
[code]yum install php[/code]
- Create the test file /etc/www/html/www.{yourdomain.tdl}/public_html/phpinfo.php with the following contents
[php]<?php phpinfo(); ?>[/php]
- Test your new page by going to http://www.{yourdomain.tdl}/phpinfo.php in your browser. If successful, you should get a long page of all your PHP configurations that are currently set.
Setup phpMyAdmin on CentOS
This step isn’t necessary, but can be helpful if you are in need of a MySQL web interface.
- Install phpMyAdmin
[code]yum install phpmyadmin[/code]
- Restart Apache
[code]service httpd restart[/code]
- Test by going to http://localhost/phpmyadmin on your local machine’s browser. Login with your root credentials and you should be good to go.