I’m learning PHP from a Pluralsight course. The final module is about web development and the author teaches how to set Linux (Ubuntu) for us to follow along, but I’m having a hard time trying to set it on Opensuse.
The author says to create a symbolic link using
ln -s /path/to/my/forlder/ /var/www/html/
but I cant find /var/www/html.
I follow these steps to configure my machine and everything is working.
So where shoud I put my project folders/files in order to work locally and follow along the course?
Install the LAMP pattern which will install Apache2, PHP5 and Mariadb(a fork of MySQL). You can install using YAST or run the following in an elevated console
zypper in patterns-openSUSE-lamp_server
The pattern should include installing the YAST http-server module which makes configuring your Apache web server easy. Open
YAST > http-server
1/5
Optionally set your webserver to start on boot
Enable the firewall ports for your webserver to be opened (ports 80, 443)
2/5
Enable PHP scripting.
3/5
Review the configuration, edit if you wish. Note the document root (/srv/www/htdocs) instead of the location /var/www/html on Ubuntu.
Save your configuration. You can always re-run this http-server module to change or review your settings.
Depending on your website code, you may also need to run “mysql_secure_installation” to configure your mysql/mariadb security configuration.
I assume, but as I do not follow your course I am not sure, that the equivalent on openSUSE is /srv/www/htdocs. But I do not think that making a symbolic link from your /path/to/my/forlder to it is a good idea. Here again assume things, like: /path/to/my/forlder is owned by a userid that is given to you for login (it may even be somewhere in your home directory) and that user will have no access to /srv/www/htdocs for the simple reason that it would be a great break of security when every user on a system could change the web pages of the HTTP server running on the system. >:)
@tsu2 I did what you posted except installing php5 since I already had installed php7. I have configure http-server via yast, but when I point to /srv/www/htdocs/phpfun/index.php it only displays an empty page but it displays .html pages without any problems.
@hcvv If isn’t a good practice doing the symlink, how should I proceed in this matter?
Can’t I just put the files in my home directory and work through there? Don’t I need to be logged as root to work with files in /srv/www/htdocs/?
I’m new to linux, and I know there are things like xammp that ease the process, but I prefer to do it manually and learn something along the way.
This has nothing to do with being new to linux. IMHO to become a good php developper you need to know what php needs, i.e. have a bit more than basic understanding of a webserver.
if php files are not displayed then maybe the php module is not activated in Apache.
You can see in Apache if the php module is activated via the following command
# a2enmod -l
authz_host actions alias authz_groupfile auth_basic authz_user authn_file autoindex cgi dir include log_config mime negotiation setenvif status userdir asis imagemap info **php5 **ssl authn_core authz_core reqtimeout version
The symlink will probably not bring you what you think.
But from the above other posts, several people are assuming you being in a different phase of the whole process of having a web-site with PHP.
We are of course not following that course and few of us will go into reading that course and deciding if it is a good one and if it fits into openSUSE.
And no, you should not be root to manage a website. Better create a separate user for it, that has the same primary group as the user that runs Apache: wwwrun:www I have one www:www, but the first www is of course arbitrary). That is what I do. But I doubt you are that far in the process. Thus when you only want to write (and test what you wrote) some PHP, you can do it anywhere (thus also in your home directory) and execute those file with php to see what comes out of them. No need to have a web site for that.
An example:
henk@boven:~/test/phptest> cat some-php.php
Here goes some HTML
<?php phpinfo()
?>
More HTML
henk@boven:~/test/phptest>
Assuming the doc root should be /srv/www/htdocs/ that should be where you put your index.php, not a subfolder. Or, what is the URL you’re testing in your browser?
I assumed that if you “activated php scripts” that your PHP module would be enabled. If not, then you can enable as @phil524 describes.
I have never set up a symlink for content files as you described, I’d have to do some testing to know for sure sym-linking doesn’t open up serious vulnerabilities in your system. I recommend instead copying files into the document root (and not a subdirectory as you’ve done).
I don’t know what your Pluralsight course says, but the first PHP page you should always create is a phpinfo.php page (There are numerous tutorials and blogs describing this).
Thank you all. Following the tips of all of you, I manage to solve the problem. This is the course I’m following and as you can see, I am a beginner learning PHP. That being said, I like to do things the proper way and in the process maybe learn something along the way.
My plan is to learn PHP to complement my knowledge of HTML/CSS and then dive into Wordpress or/and Laravel. And since I’m learning I would like to do it on localhost.
I know there are tools like XAMMP and I wonder if it isn’t the best solution to my case.
I’m doing all initial development on my laptop. IMHO openSUSE’s LAMP server has all you need. XAMMP or WAMP or whatever are definitely not going to give you more insight. And you need that. From first experience I remember spending lots of time in an attempt to get things working, where a misconfiguration of the apache webserver was the actual cause of failure. Investing some of your time is the best thing you can do IMHO. It will pay of over the years.
From your posts, what I can understand is, you need to save your php files in a local folder within your user’s home & still should be accessible from your browser.
You can save all your php files inside “public_html” folder within your user’s home.
For Example, I create a php file called “enjoy.php” and save inside my “public_html” folder of my home directory.
Lets say my linux login user id is “san001”
Then I must use “http://localhost/~san001/enjoy.php” to view in Web browser.
This works for CMS sites like wordpress & joomla as well.
Doesn’t seem to work.
On firefox when I type localhost/~biofobico/web/index.php I get a 403 Error and Access forbidden! message. I’m getting very frustrated with this. I just want to create some sites locally to learn php, install wordpress/laravel and play with them for learning purposes.
I set up a test configuring a symlinked directory to the Apatche website’s document root, and the specific things I was concerned about (directory traversal, remote access to the file system) are not issues (The content is accessible only from localhost and not a remote machine, directory traversal tests I ran were denied).
@Spinus
Whenever you want help with a problem, you have to post enough details so that anyone can replicate your problem.
So, for example…
You need to state whether you’re using the default document root (/srv/www/htdocs) or something else
You need to post exactly the directory you want to symlink to the website document root.
You need to state the command you invoked to symlink the directory to the document root.
For troubleshooting purposes, it might also be useful to post the results listing in detail your document root, for instance the following if you’re using the default location
For troubleshooting purposes, it might also be useful to post the results listing in detail your document root, for instance the following if you’re using the default location
biofobico@mothership:~> ls -l /srv/www/htdocs/
total 16
-rw-r--r-- 1 root root 302 Mar 13 2006 favicon.ico
drwxr-xr-x 1 wwwrun root 106 Jan 16 15:24 gif
-rw-r--r-- 1 root root 45 Jun 11 2007 index.html
-rw-r--r-- 1 wwwrun root 2356 Mai 12 2016 info2html.css
drwxr-xr-x 1 wwwrun root 2988 Jan 17 09:10 phpMyAdmin
-rw-r--r-- 1 root root 26 Out 9 22:36 robots.txt
drwxr-xr-x 1 wwwrun users 48 Jan 17 15:53 web
AFAICS you’re barking up the wrong tree… Install apache’s mod_userdir and use YaST to set up a proper webserver environment. I’ve done this literally dozens of times and it never failed to return a working basic webserver. From there on, you can make all kind of changes, but you’ll at least know what the working situation was.
Re: this Forum thread, because I had not heard of or had personally symlinked a directory to a website document root, my first course of action was to Google the practice (of course). I found not only articles and examples of this but also recommended alternatives, and I remember there were at least 2 alternatives mentioned that were based on Apache modules.
My feeling is that if this symlinking method isn’t fundamentally flawed, it is likely an acceptable procedure.