Install WordPress locally with xampp for Linux
Working on a website or theme is easier to do locally. Unfortunately it’s not that straightforward to get things running. A search on the internet gave a couple of solutions of which some didn’t work and others seemed to insecure for me. So here’s my problem and solution.
For the webserver I’m using xampp voor linux. Xampp is a complete package with an Apache server, PHP, MySQL and phpMyAdmin. What I like about xampp is that you just have to unpack the files in /opt and everything works instantly. However, to get WordPress working is a little bit more complicated.
Here’s the problem. The xampp root directory is /opt/xampp/htdocs/ but in order to easily work on the WordPress files and themes I’d like to install it in my own home directory. When I’m working on the source files I don’t like to mess around in /opt with root access. One solution is to move the Apache root directory, but it’s more convenient to put a symbolic link in the xampp root directory to the local WordPress install.
The next problem is to get the automatic installation of WordPress plugins and themes working. From within WordPress the server doesn’t have access to the local folder. A solution I found on the internet is to open all local files (with chmod 777), but somehow that doesn’t sound too secure for me. Also, it didn’t work (yes, I tried). My solution is to change the Apache username to my own username, so WordPress has the same access to the local files as myself.
So here’s how it works:
- install xampp with sudo tar xvfz xampp-linux-1.8.1.tar.gz -C /opt
- start xampp (sudo /opt/lampp/lampp start)
- create passwords for the default users (sudo /opt/lampp/lampp security)
- change Apache user ‘nobody’ in /opt/lampp/etc/httpd.conf by replacing it with your own username (in my case ‘simon’)
- just to make sure you can create a whoami.php file in htdocs with <?php echo(exec(“whoami”)); ?> to check whether Apache is using your username now
- give this new user access to the xampp files in /opt/lampp with sudo chown -R simon htdocs and in /opt/lampp/phpmyadmin with sudo chown simon config.inc.php (use your own username here)
- install (extract) WordPress locally, for example in ~/wordpress
- create a symbolic link in htdocs: sudo ln -s ~/wordpress wordpress
- log in as root on phpMyAdmin and create a database for WordPress, for example wp_dbase
- under ‘Databases’ – ‘add user’ you can add the default xampp user pma as user of this new database, so WordPress doesn’t have to have root access
- now do the usual WordPress install: in ~/wordpress rename the configuration file (mv wp-config-sample.php wp-config.php) and change the database parameters (database wp_dbase, user pma, and the password you chose for user pma)
- in your browser visit localhost/wordpress/wp-admin/install.php and if everything went ok you should have a local WordPress running with working installation of plugins and themes from the Dashboard
Hi Simon, Thank you very much for your post. It was really useful. But I am having some trouble with FTP credentials while installing plugins and themes.
I LOVE YOU MAN
You’ve just spared me of constant agony I’ve been enduring this past few days trying to configure darn local server.
THANK YOU.