Author: Michael J. Fuhrman
Viewers: 81
Last month viewers: 25
Categories: PHP Tutorials
Read this article to learn how to setup a Fedora based Web server machine (without a desktop GUI) using Linux, Apache, MySQL, PHP and using Samba to serve sites using files shared by separate machines.
Requirements
This tutorial assumes that several systems will be used titled Server, User Desktop (or Client), File Server, and VM Server. One or more of these systems can be hosted as VM Guest.
The Web Server will be a Fedora 18 Web Server (no GUI desktop). The Client will be a Fedora 18 with the Mate desktop experience.
The VM environment used in this article is Oracle VM VirtualBox 4.1.22 in Fedora 15. The VM Server will represent the Fedora 15 host running Oracle VM VirtualBox 4.1.22.
Conventions
[value] := is a variable that will be captured by the user as the information Web server is setup and configured.
Command Format := provides the reader with an example of the command and parameters where the command line or file name may be variable.
> := the greater than symbol will preceed any shell command. If a command generates output, the output will be displayed after the command.At the [Environment] ... := tells the reader which environment they should be working in for the instructions to follow. There are three (3) environments in this tutorial: Client, VM Server, Web Server.
Instructions
At the Client ...
Open a shell window and type
>whoami
JohnDoe
save the [UID] shown .. example "JohnDoe" .. this will be used where ever UID is requested.
At the VM Server ...
Download the Fedora 18 network install.
Using Oracles VM VirtualBox create a VM:
- VM Name = WEBSERVER_DEV- OS = Linux
- Version = Fedora (64 bit)
- Base Memory Size = 1GB
- Create new hard disk
- VDI (VirtualBox Disk Image)
- Dynamically Allocated
- Virtual Disk file Size = 20GBSelect Create
Open Settings and set the Network Adapter to Bridge Adapter
Place the IP Address in the General / Description for instance to 192.168.0.250 .
Select Storage
Connect the ISO image as a CD to the VM
Select OK
Start the image from the Oracle VM VirtualBox Manager so that you can see the image boot and work with it.
Suggestion: Avoid remoting to the VM Server since the mouse movements and clicks have to traverse 3 systems. If possible perform the install at the VM Server until you can ssh into the Web Server.
At the Web Server ...
Install the Fedora 18 network ISO image
Select the Language
Select Next
Select Network Configuration
Select Configure
Select IPv4 Settings
Set Method = Manual
Select Add
Set Address = 192.168.0.250
Set Netmask = 255.255.255.0
Set Gateway = 192.168.0.1
Set DNS Server = 192.168.0.1
Select Save
Select Done
Select Software Selection
Select Minimal Install
Select Done
Select Installation Destination
Select Done
Select Begin Installation
Set the root password
Select Complete
Select Reboot
After Rebooting
Clear CheckBox from Devices | CD | IDE | ISO
Reboot the image
Log in as root
Add a user to the system to allow ssh, http and samba to connecto to the server.
>useradd [UID]
>passwd [UID]
Add the user to the Web Development Group .. webdevs
>groupadd webdevs
>usermod -a -G webdevs [UID]
Check the IP Address of the VM
> ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: p2p1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:17:0c:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.101/24 brd 192.168.0.255 scope global p2p1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe17:c02/64 scope link
valid_lft forever preferred_lft forever
save the [Adapter Name] = "p2pl"
save the [IP Address] = 192.168.0.101
If you wish to change the IP Address, execute the following commands.
>cd /etc/sysconfig/network-scripts
>ls -l
-rw-r--r--. 1 root root 254 Feb 20 09:53 ifcfg-lo
-rw-r--r--. 1 root root 330 Jun 13 01:31 ifcfg-p2p1
...
Command Format: vi ifcfg-[Adapter Name]
>vi ifcfg-p2pl
set .. IPADDR0 = 192.168.0.250
confirm .. GATEWAY0 = 192.168.0.1
confirm .. DNS1 = 192.168.0.1
save the changes and exit VI
>service network restart
>ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: p2p1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:17:0c:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.250/24 brd 192.168.0.255 scope global p2p1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe17:c02/64 scope link
valid_lft forever preferred_lft forever
>route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.0.1 0.0.0.0 UG 0 0 0 p2p1
192.168.0.0 * 255.255.255.0 U 0 0 0 p2p1
>ping yahoo.com
PING yahoo.com (98.138.253.109) 56(84) bytes of data.
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=1 ttl=48 time=79.9 ms
Press Ctrl+C to end the ping command.
At the Client Desktop ...
>ssh [IP Address]
Enter the password for the UID
This confirms that the web server can be connected via ssh.
>exit
To disconnect from the web server. The next step will be to restart the web server in a headless state and reconnect to it, to finish the installation.
At the Web Server ...
Shutdown the web server via one of two means ..
1) send an ACPI Power Down signal
2) issue a shutdown command
>shutdown
The web server will as headless, and connect via ssh.
At the VM Server ...
Disconnect the ISO image from the VM
Start a terminal client
>VBoxManage vmstart "WEBSERVER_DEV" --type headless
Wait about 2 minutes, then attempt to connect with the client.
If you can't connect to the Web server, issue this command and then restart the VM in the VM Server's desktop to trouble shoot.
>VBoxManage vmcontrol "WEBSERVER_DEV" acpipowerbutton
or
>VBoxManage vmcontrol "WEBSERVER_DEV" poweroff
At the Client Desktop ...
>ssh [IP Address]
Enter the password for the UID
>su
Enter the root user password
Note: see the Resources below for a website on installing Apache, PHP and mySQL in Fedora 18 Linux.
Install mySQL
>yum install mysql mysql-server
... out put truncated ...
>systemctl enable mysqld.server
>service mysqld start
>mysql_secure_installation
... answer mysql questions ...
Enter current password for root (enter for none): [first time install,
press Enter
Set root password? [Y/n] y
New password: [example: root]
Re-enter new password: [example: root]
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
Record the root user password for MySQL .. [MySQL root password]
Install Apache
>yum install httpd
>cd /etc/httpd/conf
vi httpd.conf
Locate "Listen 80"
Insert after this line ...
SetEnv PHP_ENV "DEV"
... or "QA" or "PROD"
Note: If you intend to build a full Production environment, this environment variable will help you write resuable code that is independent of the server the code is running on, as your PHP code can check this environment variable and determine which settings are appropriate. Such as which mySQL server to connect with.
Save changes and exit
>systemctl enable httpd.server
>service httpd start
>cd /var/www
>usermod -a -G webdevs apache
>chgrp -R webdevs html
>chmod -R g+w html
>ls -l
drwxrwxr-x. 2 root webdevs 4096 Jun 16 12:38 html
>firewall-cmd --add-service http --permanent
>firewall-cmd --add-service http
Note: the first firewall-cmd updates the iptables. The second firewall-cmd
opens the power in the current firewall. If you wish, you can restart
the firewall to test iptables was updated correctly.
>service firewalld restart
At the Client ...
Open a web browser
Browse to 192.168.0.250
Confirm the Apache / Fedora test page appears
At the Web Server ...
Install PHP and its Modules
>yum search php
... produces a list of PHP installs and Modules ...
Choose Wisely young Jedi
>yum install php [and other PHP extensions]
>cd /etc/
>ls -l | grep "php"
...
php.ini
...
>vi php.ini
Set
short open tag = ONasp tags = ON
display erros = ON
display start up errors = ON
NOTE: see URL below for hints on search in vi
Save changes and exit
>service httpd restart
>cd /var/www/html
>vi info.php
paste the following code:
<?
phpinfo();
?>
Save changes and exit vi
At the Client Desktop ...
Open a web browser
Browse to 192.168.0.250/info.php
Confirm the PHP Info page appears
Confirm PHP_ENV appears under Apache Environment
At the Web Server ...
Install PHP myAdmin
>yum install phpmyadmin
>cd /etc/httpd/conf.d
>ls | grep "php"
>vi phpMyAdmin.conf
edit the Directory XML tag to look as follows:
<Directory /usr/share/phpMyAdmin/>
# <IfModule mod_authz_core.c>
# # Apache 2.4
# <RequireAny>
# Require ip 127.0.0.1
# Require ip ::1
# </RequireAny>
# </IfModule>
# <IfModule !mod_authz_core.c>
# # Apache 2.2
# Order Deny,Allow
# Deny from All
# Allow from 127.0.0.1
# Allow from ::1
# </IfModule>
Require all granted
</Directory>
Save changes and exit vi
>service httpd restart
At the Client Desktop ...
Open a web browser
Browse to 192.168.0.250/phpMyAdmin
Log in to the site with the following
user name = [MySQL Root]
user password = [MySQL Root Password]
Confirm phpMyAdmin appears
Create a new database for the website
Select Databases
Set Database = [Database Name]
Select Create
Confirm [Database Name] appears in left column
At the Web Server ...
Install Samba
>yum install samba
>cd /etc/samba
>cp smb.conf smb.conf.org
>vi smb.conf
consolidate the file down to the following lines ...
[global]
workgroup = [Workgroup]
server string = Samba Server Version %v
netbios name = WebServer_Dev
log file = /var/log/samba/log.%m
max log size = 1000
security = user
passdb backend = tdbsam
[www]
path = /var/www/html
valid users = [UID]
read only = no
writable = yes
browsable = yes
create mask = 0777
...
Save changes and exit
>testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[www]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[global]
workgroup = [Workgroup]
netbios name = WEBSERVER_DEV
server string = Samba Server Version %v
log file = /var/log/samba/log.%m
max log size = 1000
idmap config * : backend = tdb
[www]
path = /var/www/html
valid users = [UID]
read only = No
create mask = 0777
>setsebool -P samba_domain_controller on
>setsebool -P samba_export_all_ro on
>setsebool -P samba_export_all_rw on
>systemctl enable smb.service
>service smb start
>pdbedit -a -u [UID]
[Password]
[Re-enter Password]
>firewall-cmd --add-service samba --permanent
>firewall-cmd --add-service samba
>service firewalld restart
At the Client Desktop ...
Start a terminal session
>smbtree
... view the SMB servers that are broadcasting ...
Note: your server may not appear in this list. Thus you may need to use the [IP Address] to connect to your server
>smbclient //[IP Address]/www
Enter your password
>dir
... info.php .. should appear
NOTE: if you can browse here and list the directory contents of the share. SMB should be working properly.
Start File Explorer
Browse to smb://[IP Address]/
Enter your password
Confirm "WWW" appears
Select "WWW"
Confirm "info.php" appears
Edit info.php
Save changes and exit
Start a terminal session
>su
enter root password
>cd /mnt
>mkdir WEBSERVER_DEV -p
>chmod o+wr WEBSERVER_DEV
>mount -t cifs //[IP Address]/www /mnt/WEBSERVER_DEV -o
user=[UID],password=[PSW],domain=[Workgroup],sec=ntlm,rw,
uid=[UID] -rw
>cd WEBSERVER_DEV
>ls -L
-rwxrw-rw-. 1 [UID] [UID] 19 Jun 14 20:57 info.php
Confirm "info.php" appears
Confirm user is your [UID]
Confirm user priviledges are "rwx rw- rw-
user Read Write Execute
group Read Write
Others Read Write
Note: the UID and PSW can be stored in a secure location and referenced in mount. uid=[UID] tells Linux which user owns the files created through this link. if uid=[UID] is omitted, then only the root will have ReadWrite access.
There is some debate as to when to initiate the mount command, thus check the web for ways to mount when Linux starts vs when the user logs in.
Start File Explorer
Browse to /mnt/WEBSERVER_DEV
Enter your password
Confirm "info.php" appears
Edit info.php
Save changes and exit
If you cannot edit or save changes of "info.php" check the permissions as well. If you don't have permission, then it is possible that the chgrp and chmod commands were not executed on /var/www/html.
To confirm execute the following commands ...
At the Web Server ...
>cd /var/www/html
>ls -l
drwxr-xr-x. 2 root root 4096 Jun 16 12:38 html
Note: see how the group is set to root, and the group rights are "-RX" this means that chrp and chmod were not executed.
>chgrp -R webdevs html
>chmod -R g+w html
>ls -l
drwxrwxr-x. 2 root webdevs 4096 Jun 16 12:38 html
Note: see how the group has changed to webdevs, and the group rights are wrx. Now try the client again and see if your permissions have changed and that the info.php file can be editted and saved.
At the Web Server ...
confirm the SMB session
>smbstatus
Samba version 4.0.6
PID Username Group Machine
-------------------------------------------------------------------
5827 [UID] [UID] 192.168.0.110 (ipv4:192.168.0.110:49618)
6348 [UID] [UID] 192.168.0.110 (ipv4:192.168.0.110:50435)
Service pid machine Connected at
-------------------------------------------------------
www 6348 192.168.0.110 Sat Jun 15 02:01:33 2013
www 5827 192.168.0.110 Fri Jun 14 20:39:55 2013
IPC$ 6348 192.168.0.110 Sat Jun 15 02:01:33 2013
No locked files
Lastly .. connect to the file server for archiving files
>mkdir /mnt/FileServer -p
>chmod o+wr FileServer
>mount -t cifs //[IP ADDRESS]/www /mnt/FILESERVER -o
user=[UID],password=[PSW],domain=[WORKGROUP],sec=ntlm,rw,
uid=[UID] -rw
>cd /mnt/FILESERVER
>ls -l
Use cp as needed to move files to and from the file server as needed
>cp /mnt/FILESERVER/www/versions/01 /var/www/html
Resources
Linux and Unix ifconfig command
Installing Apache2 With PHP5 And MySQL Support On Fedora 18 (LAMP)
Setting Apache Environment Variables
Samba Server Types and Security Modes
Samba HowTo: Mount a CIFS Network Share [Mapped Drive] in openSUSE
You need to be a registered user or login to post a comment
Login Immediately with your account on:
Comments:
5. Can't Create Directories / Folders (Superceed Previous) - Michael J. Fuhrman (2013-09-02 03:51)
Problems seen creating directories / folders .. try this ...... - 0 replies
Read the whole comment and replies
4. Can't Create Directories / Folders - Michael J. Fuhrman (2013-09-02 03:51)
Problems creating directories / folders .. try this ...... - 0 replies
Read the whole comment and replies
2. Notes on Samba - Oleg (2013-07-04 07:26)
Why Samba?... - 2 replies
Read the whole comment and replies
3. Update to PHP.ini Settings - Michael J. Fuhrman (2013-07-04 01:38)
PHP would like you to set your Date Time Local... - 0 replies
Read the whole comment and replies
1. File permissions - Oleg (2013-07-03 20:59)
File permissions issue... - 0 replies
Read the whole comment and replies