- Joomla 1.5
- Apache 2.2
- MySQL 5.1
- Ubuntu 8.04 Hardy Heron server edition
The instructions may apply for other versions too.
1. Prerequisitements
What you need to have in order to use this how to
- Basic UNIX file permissions knowledge
- Basic UNIX shell knowledge
- You have a Linux server (Ubuntu / Debian) for which you have root user access and you plan to use this server to host one or several Joomla! sites
- Apache and MySQL instaleld on your server
User setup
2. Set-up an UNIX user on a dedicated server for Joomla! hosting. The user can SSH in the box and write to his home folder, /tmp and /var/www site folder.
We create a user called “user” in this instructions. Replace it with the username you desire. We also use the example site name (www).yoursite.com.
sudo adduser user # Asks for the password and created /home/user
sudo mkdir /var/www/user sudo chmod -R user:user /var/www/user # Only user has writing access to this folder
3. Setup MySQL user account
Install MySQL as per Debian/Ubuntu instructions.
Login as MySQL admin user (may vary depending how your MySQL is configured). Note that first you will be asked for sudo password, then for MySQL administrative user password.
sudo mysql -u admin -p
CREATE DATABASE user DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON user.* TO 'user'@'localhost' identified by 'zxc123zxc';
4. Extract Joomla! installation files
Enter the folder which will contain web site PHP files.
sudo -i -u user # pose yourself as UNIX user who runs the site
cd /var/www/user
wget http://joomlacode.org/gf/download/frsrelease/12350/51111/Joomla_1.5.18-Stable-Full_Package.zip
unzip Joomla_1.5.18-Stable-Full_Package.zip
Exit posing yourself as user UNIX user.
exit
5. Set file permission
- Configuration files and upload directory must be writable by Apache user (www-data for Ubuntu/Debian, httpd for Fedora/Red Hat)
- Other .php files should be read-only
Note that during Joomla’s browser based installation Apache’s www-data must have write access to folder in order to create configuration.php file. We will later remove this access right.
We will set Joomla! files under UNIX group group www-data so that Apache can read them. Certain files are set to be writable. This must be done as root user.
sudo chown -R user:www-data /var/www/user # Make user group to www-data
sudo chmod g+wrx /var/www/user # Read only access to www-data user. Write access for installation, will be later removed.
Now ls -l command in /var/www/user should give you something like this for fil masks:
drwxr-xr-x 11 user www-data 4096 2010-05-28 10:22 plugins -rwxr--r-- 1 user www-data 304 2010-05-28 10:21 robots.txt drwxr-xr-x 6 user www-data 4096 2010-05-28 10:22 templates
6. Creating Apache configuration
sudo nano /etc/apache2/sites-enabled/yoursite.conf
ServerName yoursite.com ServerAlias www.yoursite.com ServerAdmin info@yourcompany.com LogFormat combined TransferLog /var/log/apache2/yoursite.log # Make sure this virtual host if capable of executing PHP5 Options +ExecCGI AddType application/x-httpd-php .php .php5 # Point to www folder where Joomla! is extracted DocumentRoot /var/www/yoursite # Do not give illusion of safety # as PHP safe_mode really is a crap # and only causes problems php_admin_flag safe_mode off # # This entry will redirect traffic www.yoursite.com -> yoursite.com # Assume mod_rewrite is installed and enabled on Apache # 301 is HTTP Permanent Redirect code RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.yoursite\.com [NC] RewriteRule (.*) http://yoursite.com$1 [L,R=301] </VirtualHost>
7. Faking the DNS entry
sudo gedit /etc/hosts
# Force this hostname to go to your server public IP address from your local computer
123.123.123 yoursite.com www.yoursite.com
8. Start Joomla! browser based installation
http://yoursite.com
- Fill in MySQL database values as created before.
- If you plan to use SSH for file transfer do not enable FTP layer (unsecure).
- Use a random password as Joomla! administrator user and store it somewhere in safe.
- When Joomla! browser based installation goes to the point it asks you to remove the installation directory follow the instructions below.
Secure the configuration
sudo chmod -R g-w /var/www/user # Remote write permission sudo rm -rf /var/www/user/installation # Remove installation directory # Add write permission to folders which contain writable files sudo chmod -R g+x /var/www/user/logs sudo chmod -R g+x /var/www/user/images sudo chmod -R g+x /var/www/user/tmp sudo chmod -R g+x /var/www/user/images
9. Setting up htaccess files
Joomla! comes with a sample htaccess file which has some security measurements by having RewriteRules to prevent malformed URL access.
To install this file do the following
sudo -i cd /var/www/user cp htaccess.txt .htaccess chmod user:www-data .htaccess # Set file permission to be readable by Apache and writable by the UNIX user
Then we create a .htaccess file which we will place in all folders with Joomla! write access to prevent execution of PHP files in these folders. First we create htaccess.limited file which we use as a template.
sudo -i cd /var/www/user nano htaccess.limited # Open text editor
Use the following htaccess.limited content
# secure directory by disabling script execution AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi Options -ExecCGI -Indexes
And put the master template htaccess.limited to proper places
cp htaccess.limited media/.htaccess chown -R user:www-data media/.htaccess cp htaccess.limited tmp/.htaccess chown -R user:www-data tmp/.htaccess cp htaccess.limited logs/.htaccess chown -R user:www-data logs/.htaccess cp htaccess.limited images/.htaccess chown -R user:www-data images/.htaccess
10. Start using the site
11. Setting outgoing email
11. Test outgoing email
12. Maintaining file permission
- UNIX user: user (your site username)
- UNIX group: www-data
sudo usermod -a -G www-data user # Add user to www-data group so that it can set group permissions
sudo -i -u user # Login as your UNIX user chgrp -R www-data templates libraries # Fix group ownership chmod -R g+rx libraries templates # Set read access for the group
Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+
Nice write up. How does this affect Joomla’s FTP layer? Can I install vsftpd and have it work correctly with Joomla? Does this even matter since the server isn’t shared? Care to elaborate on this?
Use SFTP / SCP / SSH to transfer and access files. It is just
sudo apt-get install openssh-server
FTP in insecure, more difficult to configure and otherwise pain in the ass. There is no reason why anyone should use FTP nowdays.
Also, SFTP clients are much better to manage file permissions and ownership issues than FTP clients.
Isn’t this a typo?:
sudo chmod -R user:user /var/www/user
Should be?:
sudo chown -R user:user /var/www/user
Yeah it is. Thanks for noticing.
Please get some one to fix the multiple errors in your
website. It got joomla! installed, but there are scores or
errors in the use of chmod/chown, file edits and explanation
I appreciate the ubuntu 2010 tutorial.
ed
Hi Ed,
Thank you for finding the tutorial useful. If you find errors in the post please comment them so we fix them. Unfortunately we are not making money out of writing tutorials. it is more like of “write this down that the world will know”, so we have little time to invest to maintain them.
If you are talented I suggest you take this post as a starting point and make a good tutorial at ubuntu-forums.com how to section.
Thanks
Hi Mikko!
Thanks for the excellent tutorial. I find it very simple to follow, as I am a complete newbie to Linux.
To the point. I’ve installed joomla, and created the apache yoursite.conf file (oh, btw you’be put the outside of the box with the example output) and falsified the nds entry on my laptop. But when point my web browser to my site the apache welcome screen appears and not jommla. Any suggestions?
Best regards
Urban
Apache is probably looking files from /var/www not, from your virtualhost.
Check virtualhost port and ip.
The writeup was very helpful, I’ve gotten most of the way there. Two questions on this block:
# Add write permission to folders which contain writable files
sudo chmod -R g+x /var/www/user/logs
sudo chmod -R g+x /var/www/user/images
sudo chmod -R g+x /var/www/user/tmp
sudo chmod -R g+x /var/www/user/images
1) Should that be chmod -R g+w?
2) You have /var/www/user/images listed twice. Should there be some other directory instead?
–Bryan
yeah, looks like it’s typo
should be sudo chmod -R g+rx
… and images listed twice must be an issue.
Joomla control panel info page itself has a sanity check which tells whether directory permissions are configured correctly for core Joomla (not necessary for add-ons)
Hmm, maybe sudo chmod g+rwx? The comment says ‘add write permission’.
I can see that you are putting a lots of efforts into your blog. Keep posting the good work.Some really helpful information in there. Bookmarked. Nice to see your site. Thanks! Regard Mobile Twitter Client
Pingback: Install Joomla! on Ubuntu server with basic security | TurboLinux Blog
Thanks for the guide. This is a bit protective guide. I figured out several hours why Joomla/TinyMCE editor would not open HTML link popup window.
Reason is that .htaccess file which prevents *.js executing /media directory where the TinyMCE html-link editor is. Maaaaan, I was hunting this problem for hours. End users surely want to edit the articles html links.
Anyway, clear error in this guide.
You have to be a genius using user as a user with user examples and config, great 🙂
Hey I have been creating my joomla site offline on xampp in windows. I am now about to tranfer the site to a linux server. I have never done that. I am worried about the data base. can I intall phpmyadmin on the server?
I continue to the very last step and I see the “congratulations ….” but even when I remove the installation folder I still cannot continue to the other screen where I can login to my joomla! site. I have even uploaded a ‘configuration.php’ document to the site root.
how i can post joomla website in linux?
please help me if it can possible